From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 198063B27D3 for ; Fri, 29 May 2026 09:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780046732; cv=none; b=YwBgwpRCio0VDXYjt/hlbJ40Fyn3jp2nRE+0zioZP2CJKLpXlPExQ5hnEcSiKR/sFEy0nmn5r9b05u/4sT3vsaYNOnJtfSUtQc8J1CAPOe3Ltpum+yFyMsqZiJUTfSzZrAxYnlCuCMrrydTIisOJNCmm/k06gFE+C6qC2mzfTso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780046732; c=relaxed/simple; bh=VoUQ6N0n2dzBO3gcyIZHW67Vmg+QCKx3r614Jkyvtek=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d1lmTmSVQfkg0iXJhvVdf0hmvXsKa+2h9KoF84PBc69Q1B+mYGnNdUDHQECxPyDiFjdvE7VGZPlgKJUZJefQJTxV2epjrgaayyRQVkrKNDnfy4xHFj5IfyCLAKjtejU+LBCUV3avDT7IYgibgtVJUfb3j98c9lWTuHjPhjVU6YY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OtxIo8qF; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tsPPUVIV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OtxIo8qF; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=tsPPUVIV; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OtxIo8qF"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tsPPUVIV"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OtxIo8qF"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="tsPPUVIV" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 17F1F671CD; Fri, 29 May 2026 09:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780046727; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Oz9cjV4jibtvDaGmO2uMuiN0egNoZXNvT5/OvM8OCCY=; b=OtxIo8qFScTD6SXe5IFVEWaSDTgTswmy4v1qbhEY4Malp/xa4b9EaLiJ/xC+22456aXlbA 4warMxV3UyfRQInGilwDdKFUSsKJOroZhsLvE5h4HpN5yvcLgZz0K2Bf1M+MXyYqclQqe3 DOe6bxSe/snUBH7Nyw+fU7QqKcYMqAA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780046727; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Oz9cjV4jibtvDaGmO2uMuiN0egNoZXNvT5/OvM8OCCY=; b=tsPPUVIVUtExKCHnRSzKDNbtIg5YFTFmJG4UN/cDIZlEijygpiAh7oinWll2oIdfvHbKvh aA6Ebglt7CQa1VBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780046727; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Oz9cjV4jibtvDaGmO2uMuiN0egNoZXNvT5/OvM8OCCY=; b=OtxIo8qFScTD6SXe5IFVEWaSDTgTswmy4v1qbhEY4Malp/xa4b9EaLiJ/xC+22456aXlbA 4warMxV3UyfRQInGilwDdKFUSsKJOroZhsLvE5h4HpN5yvcLgZz0K2Bf1M+MXyYqclQqe3 DOe6bxSe/snUBH7Nyw+fU7QqKcYMqAA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780046727; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Oz9cjV4jibtvDaGmO2uMuiN0egNoZXNvT5/OvM8OCCY=; b=tsPPUVIVUtExKCHnRSzKDNbtIg5YFTFmJG4UN/cDIZlEijygpiAh7oinWll2oIdfvHbKvh aA6Ebglt7CQa1VBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 495D8779A7; Fri, 29 May 2026 09:25:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id JOuRDoZbGWrnTwAAD6G6ig (envelope-from ); Fri, 29 May 2026 09:25:26 +0000 Date: Fri, 29 May 2026 10:25:24 +0100 From: Pedro Falcato To: Kaitao Cheng Cc: dennis@kernel.org, tj@kernel.org, cl@gentwo.org, akpm@linux-foundation.org, mhocko@suse.com, vbabka@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, muchun.song@linux.dev, Kaitao Cheng Subject: Re: [PATCH 1/2] mm/percpu: Preserve NOFS/NOIO scope during chunk create and populate Message-ID: References: <20260528132917.81123-1-kaitao.cheng@linux.dev> <20260528132917.81123-2-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260528132917.81123-2-kaitao.cheng@linux.dev> X-Spam-Level: X-Spam-Score: -4.30 X-Spam-Flag: NO X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,pedro-suse.lan:mid,kylinos.cn:email] On Thu, May 28, 2026 at 09:29:16PM +0800, Kaitao Cheng wrote: > From: Kaitao Cheng > > pcpu_alloc_noprof() derives pcpu_gfp from the caller supplied GFP mask and > passes it to the backing percpu allocators. This preserves GFP_NOFS and > GFP_NOIO for pcpu_alloc_pages() and for the initial pcpu_chunk allocation. > > However, the chunk creation and population slow paths also call helpers > which do not take a GFP mask and perform internal allocations with > GFP_KERNEL. For example, pcpu_create_chunk() calls pcpu_get_vm_areas(), > and population can allocate temporary metadata or page tables while mapping > backing pages. As a result, a caller which explicitly uses GFP_NOFS or > GFP_NOIO can still enter FS or IO reclaim while creating or populating a > percpu chunk. > > This is problematic for callers which use GFP_NOFS or GFP_NOIO because > they are already holding filesystem or IO-path locks. If free chunks are > exhausted, the percpu allocation can take pcpu_alloc_mutex and then enter > unconstrained reclaim from these internal allocations, defeating the > caller's allocation context and potentially recreating reclaim lock > dependencies. > > Wrap chunk creation and population in a scoped NOIO or NOFS context when > pcpu_gfp has the corresponding constraints. Leave ordinary GFP_KERNEL > allocations unchanged so they retain full reclaim capability. > > Fixes: 9a5b183941b5 ("mm, percpu: do not consider sleepable allocations atomic") I assume you _did not_ observe this in production? As in no reclaim path should be insane^W daring enough to do pcpu allocations? > Signed-off-by: Kaitao Cheng > --- > mm/percpu.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 71a85d7245c7..1bb38467390b 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1778,6 +1778,23 @@ static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t s > } > #endif > > +static unsigned int pcpu_memalloc_scope_save(gfp_t gfp) > +{ > + if (!(gfp & __GFP_IO)) > + return memalloc_noio_save(); > + if (!(gfp & __GFP_FS)) > + return memalloc_nofs_save(); > + return 0; > +} > + > +static void pcpu_memalloc_scope_restore(gfp_t gfp, unsigned int flags) > +{ > + if (!(gfp & __GFP_IO)) > + memalloc_noio_restore(flags); > + else if (!(gfp & __GFP_FS)) > + memalloc_nofs_restore(flags); > +} I disagree with this. We already have gfp flags, they're already passed to pcpu_create_chunk() and pcpu_populate_chunk(). It's their job to respect the gfp flags and Do The Right Thing(tm). Can you fix the problematic places? It seems like it's mostly the vmalloc backend that's problematic. > + > /** > * pcpu_alloc - the percpu allocator > * @size: size of area to allocate in bytes > @@ -1901,7 +1918,12 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, > > /* No space left. Create a new chunk. */ > if (list_empty(&pcpu_chunk_lists[pcpu_free_slot])) { > + unsigned int pcpu_scope; > + > + pcpu_scope = pcpu_memalloc_scope_save(pcpu_gfp); > chunk = pcpu_create_chunk(pcpu_gfp); > + pcpu_memalloc_scope_restore(pcpu_gfp, pcpu_scope); > + > if (!chunk) { > err = "failed to allocate new chunk"; > goto fail; > @@ -1931,9 +1953,13 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, > page_end = PFN_UP(off + size); > > for_each_clear_bitrange_from(rs, re, chunk->populated, page_end) { > + unsigned int pcpu_scope; > + > WARN_ON(chunk->immutable); > > + pcpu_scope = pcpu_memalloc_scope_save(pcpu_gfp); > ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp); > + pcpu_memalloc_scope_restore(pcpu_gfp, pcpu_scope); > > spin_lock_irqsave(&pcpu_lock, flags); > if (ret) { > -- > 2.50.1 (Apple Git-155) > -- Pedro