From: Balbir Singh <balbirs@nvidia.com>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: "David Hildenbrand" <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"David Rientjes" <rientjes@google.com>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jann Horn" <jannh@google.com>,
"Pedro Falcato" <pfalcato@suse.de>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Jan Kara" <jack@suse.cz>, "Nhat Pham" <nphamcs@gmail.com>,
"Johannes Weiner" <hannes@cmpxchg.org>, "Zi Yan" <ziy@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>,
"Byungchul Park" <byungchul@sk.com>,
"Gregory Price" <gourry@gourry.net>,
"Ying Huang" <ying.huang@linux.alibaba.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Usama Arif" <usama.arif@linux.dev>,
"Kairui Song" <kasong@tencent.com>,
"Jérôme Glisse" <jglisse@redhat.com>,
"Kiryl Shutsemau" <kas@kernel.org>,
"Yu-cheng Yu" <yu-cheng.yu@intel.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Dennis Zhou" <dennis@kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Christoph Lameter" <cl@gentwo.org>,
"Peng Fan" <peng.fan@nxp.com>, "Josef Bacik" <jbacik@fb.com>,
"Chris Mason" <mason@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
"Borislav Petkov (AMD)" <bp@alien8.de>,
"Mark Brown" <broonie@kernel.org>,
"Dennis Zhou (Facebook)" <dennisszhou@gmail.com>,
"Rick Edgecombe" <rick.p.edgecombe@intel.com>
Subject: Re: [PATCH v2 13/13] percpu: queue the balance work on an unbound workqueue
Date: Sun, 15 Nov 2026 10:07:15 +1100 [thread overview]
Message-ID: <avjn4xuxUmtTfMWu@parvat> (raw)
In-Reply-To: <20261113-mason-migrate-et-al-fixes-v2-13-50a2ed382b61@kernel.org>
On Fri, Nov 13, 2026 at 09:45:31PM +0000, Lorenzo Stoakes (ARM) wrote:
> From: Chris Mason <mason@kernel.org>
>
> A burst of small atomic per-CPU allocations can fail with -ENOMEM while the
> machine has free memory and idle CPUs, as atomic per-CPU allocations are
> only served from pages that are already populated, and those can be used up
> before a worker gets to populate more.
>
> Consider:
>
> caller on CPU 1 kworker bound to CPU 1
> =============== ======================
> allocates 8 bytes, which leaves
> one empty page and 4088 bytes
> schedule_work() woken, waits for CPU 1
> allocates 8 bytes, 1023 times
> next allocation: "no space left"
> gives up CPU 1 populates pages
>
> The allocator keeps a few empty populated pages in reserve, and the work
> item pcpu_balance_work refills them.
>
> pcpu_alloc_noprof() queues the work item using schedule_work(), so only a
> worker bound to the CPU of the caller can run the work item.
>
> The issue is that the caller keeps that CPU - a task keeps it for the rest
> of its time slice, and a softirq keeps it until the softirq ends.
>
> In that time the caller can use up the reserve, resulting in an atomic
> per-CPU allocation failing.
>
> Fix the issue by queueing the work item on an unbound workqueue so that
> another CPU can populate pages while the caller keeps allocating.
>
> Gregory Price hammered atomic per-CPU allocations from one CPU with
> preemption disabled for about a second, with and without this series:
>
> Before After
> Successful allocs 1,188 131,072
> Failed allocs 4,097 0
> Balance worker runs 0 169
> Successful retries 0 4,096
>
> Fixes: 1a4d76076cda ("percpu: implement asynchronous chunk population")
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ ljs: tweaked commit message, comment ]
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> mm/percpu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/percpu.c b/mm/percpu.c
> index f87813e6ad73..39cba1710383 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -200,8 +200,9 @@ static bool pcpu_atomic_alloc_failed;
>
> static void pcpu_schedule_balance_work(void)
> {
> + /* Unbound, so another CPU can populate pgs if caller keeps this one. */
> if (pcpu_async_enabled)
> - schedule_work(&pcpu_balance_work);
> + queue_work(system_dfl_wq, &pcpu_balance_work);
> }
>
Can this run havoc on otherwise idle systems? Why not choose a workqueue
with WQ_POWER_EFFICIENT, which becomes unbound when nohz_full is
enabled? I guess it still leaves open the case when nohz_full is not
enabled and we get a burst of atomic allocations?
Balbir
prev parent reply other threads:[~2026-11-14 23:07 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 21:45 [PATCH v2 00/13] mm: batch of (urgentish?) fixes in oomk, cachestat, dev-migrate, percpu Lorenzo Stoakes (ARM)
2026-11-13 21:45 ` [PATCH v2 01/13] mm/mmap: free gathered pages before MMF_OOM_SKIP Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 02/13] mm: cachestat: count each page only once Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 03/13] mm: cachestat: restart the walk after each entry Lorenzo Stoakes (ARM)
2026-11-14 18:08 ` Nhat Pham
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 04/13] mm/migrate_device: allocate THP deferred split heads Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 05/13] mm/migrate_device: don't collect a range twice Lorenzo Stoakes (ARM)
2026-11-14 5:09 ` Balbir Singh
2026-11-14 6:45 ` Mika Penttilä
2026-11-14 18:34 ` Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 06/13] mm/migrate_device: don't let go of the fault page Lorenzo Stoakes (ARM)
2026-11-13 22:31 ` Balbir Singh
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 07/13] mm/migrate_device: look up fault folio after a split Lorenzo Stoakes (ARM)
2026-11-13 22:20 ` Balbir Singh
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 08/13] mm/migrate_device: fix ksmd oops on a migrated KSM page Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 09/13] mm/migrate_device: fix use-after-free of the anon rmap Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 10/13] mm/migrate_device: refuse to migrate shadow stacks Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 11/13] percpu: fix contig hints that are too low Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 12/13] percpu: search the whole reserved chunk Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-13 21:45 ` [PATCH v2 13/13] percpu: queue the balance work on an unbound workqueue Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-14 23:07 ` Balbir Singh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avjn4xuxUmtTfMWu@parvat \
--to=balbirs@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=byungchul@sk.com \
--cc=cl@gentwo.org \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=dennis@kernel.org \
--cc=dennisszhou@gmail.com \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jbacik@fb.com \
--cc=jglisse@redhat.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kas@kernel.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mason@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=nphamcs@gmail.com \
--cc=peng.fan@nxp.com \
--cc=pfalcato@suse.de \
--cc=rick.p.edgecombe@intel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--cc=yu-cheng.yu@intel.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox