From nobody Sat Feb 7 14:39:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47A7EC77B7A for ; Tue, 30 May 2023 14:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjE3O6L (ORCPT ); Tue, 30 May 2023 10:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232969AbjE3O55 (ORCPT ); Tue, 30 May 2023 10:57:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30228A7 for ; Tue, 30 May 2023 07:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685458627; 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=N0hJfqn4EoxiBlmJOP3aHXOKCKD0R3BQJl7dwB2jg74=; b=EdHnI3jwQoOpnUVaihTNjUj165h94rj052qRldzCKoM7oe3lSBAZOnAO0BwW1pUSpcVx+h fHn1yiYWQqXgTeZSaznrj68u1aUqYXxrkasI6FFC6mcx1TxnBtC07lZdh881WfcCeENYk/ K0QIybQGHqdirTPQQqqnSFsOw/Hhwvk= 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-326-uE-WUPsyOkefq9LDnYZpnw-1; Tue, 30 May 2023 10:56:56 -0400 X-MC-Unique: uE-WUPsyOkefq9LDnYZpnw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74F20802E58; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F1B62166B25; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 49105401CE3ED; Tue, 30 May 2023 11:56:33 -0300 (-03) Message-ID: <20230530145335.677325196@redhat.com> User-Agent: quilt/0.67 Date: Tue, 30 May 2023 11:52:35 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Michal Hocko , Marcelo Tosatti Subject: [PATCH 1/4] vmstat: allow_direct_reclaim should use zone_page_state_snapshot References: <20230530145234.968927611@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A customer provided evidence indicating that a process was stalled in direct reclaim: - The process was trapped in throttle_direct_reclaim(). The function wait_event_killable() was called to wait condition =20 allow_direct_reclaim(pgdat) for current node to be true. =20 The allow_direct_reclaim(pgdat) examined the number of free pages =20 on the node by zone_page_state() which just returns value in =20 zone->vm_stat[NR_FREE_PAGES]. =20 =20 - On node #1, zone->vm_stat[NR_FREE_PAGES] was 0. =20 However, the freelist on this node was not empty. =20 =20 - This inconsistent of vmstat value was caused by percpu vmstat on =20 nohz_full cpus. Every increment/decrement of vmstat is performed =20 on percpu vmstat counter at first, then pooled diffs are cumulated =20 to the zone's vmstat counter in timely manner. However, on nohz_full =20 cpus (in case of this customer's system, 48 of 52 cpus) these pooled =20 diffs were not cumulated once the cpu had no event on it so that =20 the cpu started sleeping infinitely. =20 I checked percpu vmstat and found there were total 69 counts not =20 cumulated to the zone's vmstat counter yet. =20 =20 - In this situation, kswapd did not help the trapped process. =20 In pgdat_balanced(), zone_wakermark_ok_safe() examined the number =20 of free pages on the node by zone_page_state_snapshot() which =20 checks pending counts on percpu vmstat. =20 Therefore kswapd could know there were 69 free pages correctly. =20 Since zone->_watermark =3D {8, 20, 32}, kswapd did not work because =20 69 was greater than 32 as high watermark. =20 Change allow_direct_reclaim to use zone_page_state_snapshot, which allows a more precise version of the vmstat counters to be used. allow_direct_reclaim will only be called from try_to_free_pages, which is not a hot path. Testing: Due to difficulties accessing the system, it has not been possible for the reproducer to test the patch (however its clear from available data and analysis that it should fix it). Reviewed-by: Michal Hocko Reviewed-by: Aaron Tomlin Signed-off-by: Marcelo Tosatti --- Index: linux-vmstat-remote/mm/vmscan.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-vmstat-remote.orig/mm/vmscan.c +++ linux-vmstat-remote/mm/vmscan.c @@ -6887,7 +6887,7 @@ static bool allow_direct_reclaim(pg_data continue; =20 pfmemalloc_reserve +=3D min_wmark_pages(zone); - free_pages +=3D zone_page_state(zone, NR_FREE_PAGES); + free_pages +=3D zone_page_state_snapshot(zone, NR_FREE_PAGES); } =20 /* If there are no reserves (unexpected config) then do not throttle */ From nobody Sat Feb 7 14:39:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6762DC77B7A for ; Tue, 30 May 2023 14:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232605AbjE3O6C (ORCPT ); Tue, 30 May 2023 10:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232779AbjE3O5p (ORCPT ); Tue, 30 May 2023 10:57:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3087CD9 for ; Tue, 30 May 2023 07:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685458616; 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=B/GSKf6UEn0c42XXKcBB/6CIce6RG7UgO/Nmikr6pJA=; b=cl3550E5TrMIT55COM5pcyDmx+KyQ2elGFgZrZEL2btfAnKYoi5F/N+4fkJR/ukopAgeW/ 4i60yL1Q99gF8mS433IohaWbnZip6fQC+jZALgIL8UCD65CErnKZ2fQ2o9OV6YdkG2lKtP bkmyg01jsnjYoSpmrPc7Io+TlAQl+i0= 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-42-qhAbuYgmMEKTml1kAmu7gA-1; Tue, 30 May 2023 10:56:51 -0400 X-MC-Unique: qhAbuYgmMEKTml1kAmu7gA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28452185A792; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7445420A8; Tue, 30 May 2023 14:56:50 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 4E9DA401CFE3F; Tue, 30 May 2023 11:56:33 -0300 (-03) Message-ID: <20230530145335.828634764@redhat.com> User-Agent: quilt/0.67 Date: Tue, 30 May 2023 11:52:36 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Michal Hocko , Marcelo Tosatti Subject: [PATCH 2/4] vmstat: skip periodic vmstat update for nohz full CPUs References: <20230530145234.968927611@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The interruption caused by vmstat_update is undesirable=20 for certain aplications: oslat 1094.456862: sys_mlock(start: 7f7ed0000b60, len: 1000) oslat 1094.456971: workqueue_queue_work: ... function=3Dvmstat_update ... oslat 1094.456974: sched_switch: prev_comm=3Doslat ... =3D=3D> next_comm= =3Dkworker/5:1 ... kworker 1094.456978: sched_switch: prev_comm=3Dkworker/5:1 =3D=3D> next_com= m=3Doslat ... The example above shows an additional 7us for the oslat -> kworker -> oslat switches. In the case of a virtualized CPU, and the vmstat_update =20 interruption in the host (of a qemu-kvm vcpu), the latency penalty observed in the guest is higher than 50us, violating the acceptable latency threshold. Skip periodic updates for nohz full CPUs. Any callers who need precise values should use a snapshot of the per-CPU counters, or use the global counters with measures to=20 handle errors up to thresholds (see calculate_normal_threshold). Suggested by Michal Hocko. Signed-off-by: Marcelo Tosatti --- Index: linux-vmstat-remote/mm/vmstat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -28,6 +28,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -2022,6 +2023,16 @@ static void vmstat_shepherd(struct work_ for_each_online_cpu(cpu) { struct delayed_work *dw =3D &per_cpu(vmstat_work, cpu); =20 + /* + * Skip periodic updates for nohz full CPUs. + * Any callers who need precise values should use + * a snapshot of the per-CPU counters, or use the global + * counters with measures to handle errors up to + * thresholds (see calculate_normal_threshold). + */ + if (tick_nohz_full_cpu(cpu)) + continue; + if (!delayed_work_pending(dw) && need_update(cpu)) queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0); From nobody Sat Feb 7 14:39:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 556F0C77B7A for ; Tue, 30 May 2023 14:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232921AbjE3O5v (ORCPT ); Tue, 30 May 2023 10:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232820AbjE3O5n (ORCPT ); Tue, 30 May 2023 10:57:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4DBAB0 for ; Tue, 30 May 2023 07:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685458617; 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=zB34+gA9q6N2mJEfFmSt2POPWMX6epdGtnjhsa8vBnc=; b=iBCAgAnmzLl7pJbLrXIGp0tLeTly6KSI2RePd+9IiCIYcxesDLCKtzWPOwWleHe7Y+hjRX +uv2ng/UFTsZZHw/OXcaPa7iNRPFDovreXw9GbSHAr7Gxmtb0iWFS7vd7Q2OfiAEnYnr7p 9/TR1DCoYyKW+DhKlnRIDK4YlWCGcpw= 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-471-M5R71YDnOC6zHMxN_4ZF3Q-1; Tue, 30 May 2023 10:56:51 -0400 X-MC-Unique: M5R71YDnOC6zHMxN_4ZF3Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25935101AA68; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9F62C154D3; Tue, 30 May 2023 14:56:50 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 57A59401E150C; Tue, 30 May 2023 11:56:33 -0300 (-03) Message-ID: <20230530145335.930262644@redhat.com> User-Agent: quilt/0.67 Date: Tue, 30 May 2023 11:52:37 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Michal Hocko , Marcelo Tosatti Subject: [PATCH 3/4] workqueue: add schedule_on_each_cpumask helper References: <20230530145234.968927611@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a schedule_on_each_cpumask function, equivalent to schedule_on_each_cpu but accepting a cpumask to operate. Signed-off-by: Marcelo Tosatti --- Index: linux-vmstat-remote/kernel/workqueue.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-vmstat-remote.orig/kernel/workqueue.c +++ linux-vmstat-remote/kernel/workqueue.c @@ -3455,6 +3455,56 @@ int schedule_on_each_cpu(work_func_t fun return 0; } =20 + +/** + * schedule_on_each_cpumask - execute a function synchronously on each + * CPU in "cpumask", for those which are online. + * + * @func: the function to call + * @mask: the CPUs which to call function on + * + * schedule_on_each_cpu() executes @func on each specified CPU that is onl= ine, + * using the system workqueue and blocks until all such CPUs have complete= d. + * schedule_on_each_cpu() is very slow. + * + * Return: + * 0 on success, -errno on failure. + */ +int schedule_on_each_cpumask(work_func_t func, cpumask_t *cpumask) +{ + int cpu; + struct work_struct __percpu *works; + cpumask_var_t effmask; + + works =3D alloc_percpu(struct work_struct); + if (!works) + return -ENOMEM; + + if (!alloc_cpumask_var(&effmask, GFP_KERNEL)) { + free_percpu(works); + return -ENOMEM; + } + + cpumask_and(effmask, cpumask, cpu_online_mask); + + cpus_read_lock(); + + for_each_cpu(cpu, effmask) { + struct work_struct *work =3D per_cpu_ptr(works, cpu); + + INIT_WORK(work, func); + schedule_work_on(cpu, work); + } + + for_each_cpu(cpu, effmask) + flush_work(per_cpu_ptr(works, cpu)); + + cpus_read_unlock(); + free_percpu(works); + free_cpumask_var(effmask); + return 0; +} + /** * execute_in_process_context - reliably execute the routine with user con= text * @fn: the function to execute Index: linux-vmstat-remote/include/linux/workqueue.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-vmstat-remote.orig/include/linux/workqueue.h +++ linux-vmstat-remote/include/linux/workqueue.h @@ -450,6 +450,7 @@ extern void __flush_workqueue(struct wor extern void drain_workqueue(struct workqueue_struct *wq); =20 extern int schedule_on_each_cpu(work_func_t func); +extern int schedule_on_each_cpumask(work_func_t func, cpumask_t *cpumask); =20 int execute_in_process_context(work_func_t fn, struct execute_work *); From nobody Sat Feb 7 14:39:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BB8EC77B73 for ; Tue, 30 May 2023 14:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232956AbjE3O5y (ORCPT ); Tue, 30 May 2023 10:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232785AbjE3O5n (ORCPT ); Tue, 30 May 2023 10:57:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7DCA0 for ; Tue, 30 May 2023 07:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685458615; 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=Zp+6wKN5pw6h0b4P0Mp9cZhOYKe0APjLNDcaJDBGqc0=; b=KK44kWQtOd6KwlTRTlwFn57e9430/h84pRMj/h5h7i0+uMBUrpwtXlPyGAdQ4hm25IcuAv Un3PZnuk0CFwM9N9we09QX5zwLIeX7J9m7kwueECKzJti3fcQnYUxSaCHEBKSUP9tyRdi5 nIL+wIuvLNGKaySrXBa4qS5jzvxFqnE= 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-609-WcYEjc5XOeSOkwHfXbc04Q-1; Tue, 30 May 2023 10:56:53 -0400 X-MC-Unique: WcYEjc5XOeSOkwHfXbc04Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 241BB101A53B; Tue, 30 May 2023 14:56:51 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-2.gru2.redhat.com [10.97.112.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E742BC154D2; Tue, 30 May 2023 14:56:50 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 5C58B401E1522; Tue, 30 May 2023 11:56:33 -0300 (-03) Message-ID: <20230530145336.155097348@redhat.com> User-Agent: quilt/0.67 Date: Tue, 30 May 2023 11:52:38 -0300 From: Marcelo Tosatti To: Christoph Lameter Cc: Aaron Tomlin , Frederic Weisbecker , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Michal Hocko , Marcelo Tosatti Subject: [PATCH 4/4] mm/vmstat: do not refresh stats for nohz_full CPUs References: <20230530145234.968927611@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The interruption caused by queueing work on nohz_full CPUs=20 is undesirable for certain aplications. Fix by not refreshing per-CPU stats of nohz_full CPUs.=20 Signed-off-by: Marcelo Tosatti --- Index: linux-vmstat-remote/mm/vmstat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-vmstat-remote.orig/mm/vmstat.c +++ linux-vmstat-remote/mm/vmstat.c @@ -1877,12 +1877,31 @@ static void refresh_vm_stats(struct work refresh_cpu_vm_stats(true); } =20 +#ifdef CONFIG_NO_HZ_FULL +static inline const cpumask_t *tickless_cpumask(void) +{ + return tick_nohz_full_mask; +} +#else +static cpumask_t empty_cpumask; +static inline const cpumask_t *tickless_cpumask(void) +{ + return &empty_cpumask; +} +#endif + int vmstat_refresh(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { long val; int err; int i; + cpumask_var_t dstmask; + + if (!alloc_cpumask_var(&dstmask, GFP_KERNEL)) + return -ENOMEM; + + cpumask_andnot(dstmask, cpu_possible_mask, tickless_cpumask()); =20 /* * The regular update, every sysctl_stat_interval, may come later @@ -1896,7 +1915,9 @@ 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 =3D schedule_on_each_cpu(refresh_vm_stats); + err =3D schedule_on_each_cpumask(refresh_vm_stats, dstmask); + free_cpumask_var(dstmask); + if (err) return err; for (i =3D 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {