From: Kent Overstreet <kent.overstreet@linux.dev>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org, Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@kernel.org>,
"Darrick J . Wong" <djwong@kernel.org>
Subject: Re: [PATCH 2/3] mm: introduce PF_MEMALLOC_NORECLAIM, PF_MEMALLOC_NOWARN
Date: Wed, 7 Feb 2024 16:05:23 -0500 [thread overview]
Message-ID: <zup5yilebkgkrypis4g6zkbft7pywqi57k5aztoio2ufi5ujsd@mfnqu4rarort> (raw)
In-Reply-To: <f9ad4bc5-37ce-485b-94d8-afdfaca620c8@suse.cz>
On Wed, Feb 07, 2024 at 08:24:33AM +0100, Vlastimil Babka wrote:
> On 2/6/24 22:50, Kent Overstreet wrote:
> > Introduce PF_MEMALLOC_* equivalents of some GFP_ flags:
> >
> > PF_MEMALLOC_NORECLAIM -> GFP_NOWAIT
>
> In an ideal world, this would be nice, but we are in a world with implicit
> "too small to fail" guarantees that has so far been impossible to get away
> from [1] for small order GFP_KERNEL allocations, and this scoping would be
> only safe if no allocations underneath relied on this behavior. But how to
> ensure that's the case?
Fault injection. You can't know if code works if it never gets tested,
and if small allocations don't fail in practice, then you need fault
injection.
But there's a code pattern that absolutely requires GFP_NOWAIT. Say
you've got locks held and you want to allocate memory:
p = kmalloc(GFP_NOWAIT);
if (p)
goto success;
unlock();
p = kmalloc(GFP_KERNEL);
/* unwind and retry, or tryrelock, depending on what you're doing */
that is - try the allocation nonblocking, then unlock or unwind, then
try it GFP_KERNEL.
bcachefs uses this heavily because we've got bch2_trans_unlock() and
bch2_trans_relock(); relock succeeds iff nothing else took write locks
on the nodes he had locked before - so we can safely use GFP_KERNEL
without causing deadlocks, only the occasional transaction restart.
but: the first GFP_NOWAIT allocation, before using GFP_KERNEL, is
absolutely required - calling unlock() has to be a slowpath operation,
otherwise it will livelock when multiple threads are contending for the
same locks.
More broadly, there's a bunch of other GFP_NOWAIT uses in the kernel,
and we're _not_ going to kill them off, and we are trying to kill off
gfp_t for this kind of purpose - so we need this.
next prev parent reply other threads:[~2024-02-07 21:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 21:50 [PATCH 0/3] few mm helpers for bcachefs Kent Overstreet
2024-02-06 21:50 ` [PATCH 1/3] mm: introduce memalloc_flags_{save,restore} Kent Overstreet
2024-02-09 10:36 ` Vlastimil Babka
2024-02-06 21:50 ` [PATCH 2/3] mm: introduce PF_MEMALLOC_NORECLAIM, PF_MEMALLOC_NOWARN Kent Overstreet
2024-02-07 7:24 ` Vlastimil Babka
2024-02-07 7:44 ` Michal Hocko
2024-02-07 21:05 ` Kent Overstreet [this message]
2024-02-06 21:50 ` [PATCH 3/3] mempool: kvmalloc pool Kent Overstreet
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=zup5yilebkgkrypis4g6zkbft7pywqi57k5aztoio2ufi5ujsd@mfnqu4rarort \
--to=kent.overstreet@linux.dev \
--cc=djwong@kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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