From: Vlastimil Babka <vbabka@suse.cz>
To: Michal Hocko <mhocko@kernel.org>, Dennis Zhou <dennis@kernel.org>,
Tejun Heo <tj@kernel.org>, Filipe Manana <fdmanana@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH] mm, percpu: do not consider sleepable allocations atomic
Date: Tue, 11 Feb 2025 16:05:54 +0100 [thread overview]
Message-ID: <b990116d-d475-4c57-9c6c-fafb4ef5fbad@suse.cz> (raw)
In-Reply-To: <20250206122633.167896-1-mhocko@kernel.org>
On 2/6/25 13:26, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> 28307d938fb2 ("percpu: make pcpu_alloc() aware of current gfp context")
> has fixed a reclaim recursion for scoped GFP_NOFS context. It has done
> that by avoiding taking pcpu_alloc_mutex. This is a correct solution as
> the worker context with full GFP_KERNEL allocation/reclaim power and which
> is using the same lock cannot block the NOFS pcpu_alloc caller.
>
> On the other hand this is a very conservative approach that could lead
> to failures because pcpu_alloc lockless implementation is quite limited.
>
> We have a bug report about premature failures when scsi array of 193
> devices is scanned. Sometimes (not consistently) the scanning aborts
> because the iscsid daemon fails to create the queue for a random scsi
> device during the scan. iscsid itslef is running with PR_SET_IO_FLUSHER
> set so all allocations from this process context are GFP_NOIO. This in
> turn makes any pcpu_alloc lockless (without pcpu_alloc_mutex) which
> leads to pre-mature failures.
>
> It has turned out that iscsid has worked around this by dropping
> PR_SET_IO_FLUSHER (https://github.com/open-iscsi/open-iscsi/pull/382)
> when scanning host. But we can do better in this case on the kernel side
> and use pcpu_alloc_mutex for NOIO resp. NOFS constrained allocation
> scopes too. We just need the WQ worker to never trigger IO/FS reclaim.
> Achieve that by enforcing scoped GFP_NOIO for the whole execution of
> pcpu_balance_workfn (this will imply NOFS constrain as well). This will
> remove the dependency chain and preserve the full allocation power of
> the pcpu_alloc call.
>
> While at it make is_atomic really test for blockable allocations.
>
> Fixes: 28307d938fb2 ("percpu: make pcpu_alloc() aware of current gfp context
> Signed-off-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/percpu.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mm/percpu.c b/mm/percpu.c
> index d8dd31a2e407..192c2a8e901d 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -1758,7 +1758,7 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
> gfp = current_gfp_context(gfp);
> /* whitelisted flags that can be passed to the backing allocators */
> pcpu_gfp = gfp & (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
> - is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL;
> + is_atomic = !gfpflags_allow_blocking(gfp);
> do_warn = !(gfp & __GFP_NOWARN);
>
> /*
> @@ -2204,7 +2204,12 @@ static void pcpu_balance_workfn(struct work_struct *work)
> * to grow other chunks. This then gives pcpu_reclaim_populated() time
> * to move fully free chunks to the active list to be freed if
> * appropriate.
> + *
> + * Enforce GFP_NOIO allocations because we have pcpu_alloc users
> + * constrained to GFP_NOIO/NOFS contexts and they could form lock
> + * dependency through pcpu_alloc_mutex
> */
> + unsigned int flags = memalloc_noio_save();
> mutex_lock(&pcpu_alloc_mutex);
> spin_lock_irq(&pcpu_lock);
>
> @@ -2215,6 +2220,7 @@ static void pcpu_balance_workfn(struct work_struct *work)
>
> spin_unlock_irq(&pcpu_lock);
> mutex_unlock(&pcpu_alloc_mutex);
> + memalloc_noio_restore(flags);
> }
>
> /**
next prev parent reply other threads:[~2025-02-11 15:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 12:26 Michal Hocko
2025-02-11 15:05 ` Vlastimil Babka [this message]
2025-02-11 20:55 ` Tejun Heo
2025-02-12 16:57 ` Michal Hocko
2025-02-12 18:14 ` Tejun Heo
2025-02-12 20:53 ` Michal Hocko
2025-02-12 21:30 ` Tejun Heo
2025-02-12 21:39 ` Dennis Zhou
2025-02-14 15:52 ` Michal Hocko
2025-02-21 2:36 ` Dennis Zhou
2025-02-21 9:48 ` Vlastimil Babka
2025-03-05 15:10 ` Michal Hocko
2025-03-05 15:35 ` Vlastimil Babka
2025-02-14 15:43 ` Michal Hocko
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=b990116d-d475-4c57-9c6c-fafb4ef5fbad@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=dennis@kernel.org \
--cc=fdmanana@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=tj@kernel.org \
/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