From patchwork Wed Dec 21 16:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 13078955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5B6FC4167B for ; Wed, 21 Dec 2022 17:10:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E44FF8E0008; Wed, 21 Dec 2022 12:10:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1A8D8E0005; Wed, 21 Dec 2022 12:10:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B82FF8E0008; Wed, 21 Dec 2022 12:10:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9173F8E0005 for ; Wed, 21 Dec 2022 12:10:53 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6D1F8A09F5 for ; Wed, 21 Dec 2022 17:10:53 +0000 (UTC) X-FDA: 80266953186.11.A4ADBD7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id D4B72C001E for ; Wed, 21 Dec 2022 17:10:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UR+48wp1; spf=pass (imf22.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671642651; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=TlUBF+2Ovi4fw5cA3chagzYiWYAEFxQHjy6HVV9843g=; b=YEU8/kRhZWleie303ve/1GqgNZhcLI436/jOIcxWbGXuX/q+ZAMF6JdycrFepnBkLKZtfM hnUQpk1xAuXJg/eew87AIxjF4jRufdVOeJcP+2R+86s0nUa9v/IwOKxW/avo7PWauaJbl4 tSMFmOQbBhXNJLggB+BduaL/wQ6zHxo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UR+48wp1; spf=pass (imf22.hostedemail.com: domain of mtosatti@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mtosatti@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671642651; a=rsa-sha256; cv=none; b=0FSqDSdjGABoWwFE3PY4WiWeQ1wnJyCaqCwRlVYn3L44IP0iJZnK9UJUYAMGakaLUOQC03 fvuWshF9x+xvfGsSzeILarfI5H2blPxDzZXLvK+pvht+dDgiSRXnlqfD+b3TJG+xVkS3XZ TvMqZom8mdcZL1fFogvZe8fyg5yCc+c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671642651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=TlUBF+2Ovi4fw5cA3chagzYiWYAEFxQHjy6HVV9843g=; b=UR+48wp16vL8S8kqlGgp9m++9gZrvRQ1BhYrCrBKsxY/kzA3hbA7z0Fco2l/yKM5SZJt3H p2Q24dSm/URqofnGckNPmJ2p1isZ30Oxt/u+K4h75tv4IZMfCd1cnT+BRNV83EvLEIQD9P kyX1RXgrF+uPXed75atrhzhsfgwa4WM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-4PpJoZByPimihLmmqWBpNQ-1; Wed, 21 Dec 2022 12:10:46 -0500 X-MC-Unique: 4PpJoZByPimihLmmqWBpNQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20631882827; Wed, 21 Dec 2022 17:10:46 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-4.gru2.redhat.com [10.97.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA5E92026D4B; Wed, 21 Dec 2022 17:10:44 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id B17E640408D5F; Wed, 21 Dec 2022 14:09:34 -0300 (-03) Message-ID: <20221221170436.449941687@redhat.com> User-Agent: quilt/0.66 Date: Wed, 21 Dec 2022 13:58:07 -0300 From: Marcelo Tosatti To: atomlin@atomlin.com, frederic@kernel.org Cc: cl@linux.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, pauld@redhat.com, neelx@redhat.com, oleksandr@natalenko.name, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Marcelo Tosatti Subject: [PATCH v11 6/6] mm/vmstat: avoid queueing work item if cpu stats are clean References: <20221221165801.362118576@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D4B72C001E X-Stat-Signature: t1bmyjqihc31metqueo3ui94153wqxi7 X-Rspam-User: X-HE-Tag: 1671642651-866796 X-HE-Meta: U2FsdGVkX1+Q3Fca4LD2+1iFeuDJcel8OWdFi6ICGN1MPKMjQkhcTGGKFNoiJcjSYGWsywyBxTG/oHbnG6EY4G0xKXJQBSSpbyc21XOSA6f+94cEFmCnHqqEErNmoBjlGDn+zFYoXSpYxSlaEVGp1buidG531yzbaBbrd/b0z/9bKIaSR3kAf6afVNRU9z5kMwBMTbcwBEnNNZy0IBiW0jK6SVr8OfaBRAzLPxzGUc01SIZoLYJhtkRkW3fSTg5iiCLnOt/2uVrPKVtXfk0O+Wf8IdjiIDaHXUAY96BKduiIta4t0qLAYKjE9FSa+ZcU8Wp+einmS8K7dOcIlbLksjlrJ3L4NU72yQMWoCDWQ5XogGqMAB2i0pm35Ca9wx9PMMc2ZDia7k55Ad3dZch1FOHKTrqG5qYR0A8YjmEkZZlxGYg10zSOQqFZblVOX8BhTDxT1OCol7/dTPxIQX3MJOYmsEv0oE/jLtgJ0cNgZgBFj0wKR4ZfejgipMJsxisiWxLCjEto7RcIw1ixALOSiLtr6y4BnBJ3rxV5LN1GNMW2LIOuXlkq9f/jl2SWTgLw5Vn/6fOThsS4vyrOcCSPBH+oWbi8tMVndb/6aBUI7Kox8ASLrTnoftBZXV4ZwQ+dvoPH//Xr9hByCjaNnPHUr5ngx7five7J8LHl90XVaC+jcZVvxkrJaWxMU2hs0H0mL+A1HkTjsjovDYPvPFHm5BCB5PPOhpo9g4xNkGlnWBOXZ3Xhqbe+nKxD0j8Jv3xbjBI0ROkU7w1IGdaxoZoAKo6z/dx1lf2mKL7vdP0TMgBfSYU05OJ1cOWyKjktjjsUzRYrwPCXrCRWSnNmvhjqBbPkqEoRM64i4uBL/LBQhRn3LmzYwUhMYeBhZpQob7Q1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It is not necessary to queue work item to run refresh_vm_stats on a remote CPU if that CPU has no dirty stats and no per-CPU allocations for remote nodes. This fixes sosreport hang (which uses vmstat_refresh) with spinning SCHED_FIFO process. Signed-off-by: Marcelo Tosatti Index: linux-2.6/mm/vmstat.c =================================================================== --- linux-2.6.orig/mm/vmstat.c +++ linux-2.6/mm/vmstat.c @@ -1917,6 +1917,31 @@ static const struct seq_operations vmsta #ifdef CONFIG_SMP #ifdef CONFIG_PROC_FS +static bool need_drain_remote_zones(int cpu) +{ +#ifdef CONFIG_NUMA + struct zone *zone; + + for_each_populated_zone(zone) { + struct per_cpu_pages *pcp; + + pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); + if (!pcp->count) + continue; + + if (!pcp->expire) + continue; + + if (zone_to_nid(zone) == cpu_to_node(cpu)) + continue; + + return true; + } +#endif + + return false; +} + static void refresh_vm_stats(struct work_struct *work) { refresh_cpu_vm_stats(true); @@ -1926,8 +1951,12 @@ int vmstat_refresh(struct ctl_table *tab void *buffer, size_t *lenp, loff_t *ppos) { long val; - int err; - int i; + int i, cpu; + struct work_struct __percpu *works; + + works = alloc_percpu(struct work_struct); + if (!works) + return -ENOMEM; /* * The regular update, every sysctl_stat_interval, may come later @@ -1941,9 +1970,21 @@ int vmstat_refresh(struct ctl_table *tab * transiently negative values, report an error here if any of * the stats is negative, so we know to go looking for imbalance. */ - err = schedule_on_each_cpu(refresh_vm_stats); - if (err) - return err; + cpus_read_lock(); + for_each_online_cpu(cpu) { + struct work_struct *work = per_cpu_ptr(works, cpu); + struct vmstat_dirty *vms = per_cpu_ptr(&vmstat_dirty_pcpu, cpu); + + INIT_WORK(work, refresh_vm_stats); + + if (vms->dirty || need_drain_remote_zones(cpu)) + schedule_work_on(cpu, work); + } + for_each_online_cpu(cpu) + flush_work(per_cpu_ptr(works, cpu)); + cpus_read_unlock(); + free_percpu(works); + for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { /* * Skip checking stats known to go negative occasionally.