From: Vlastimil Babka <vbabka@suse.cz>
To: Kent Overstreet <kent.overstreet@linux.dev>, linux-mm@kvack.org
Cc: 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 08:24:33 +0100 [thread overview]
Message-ID: <f9ad4bc5-37ce-485b-94d8-afdfaca620c8@suse.cz> (raw)
In-Reply-To: <20240206215016.961253-3-kent.overstreet@linux.dev>
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?
[1] https://lwn.net/Articles/723317/
> PF_MEMALLOC_NOWARN -> __GFP_NOWARN
>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Darrick J. Wong <djwong@kernel.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> ---
> include/linux/sched.h | 4 ++--
> include/linux/sched/mm.h | 17 +++++++++++++----
> 2 files changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 292c31697248..ca08d92b20ac 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1755,8 +1755,8 @@ extern struct pid *cad_pid;
> * I am cleaning dirty pages from some other bdi. */
> #define PF_KTHREAD 0x00200000 /* I am a kernel thread */
> #define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */
> -#define PF__HOLE__00800000 0x00800000
> -#define PF__HOLE__01000000 0x01000000
> +#define PF_MEMALLOC_NORECLAIM 0x00800000 /* All allocation requests will inherit __GFP_NOWARN */
> +#define PF_MEMALLOC_NOWARN 0x01000000 /* All allocation requests will inherit __GFP_NOWARN */
> #define PF__HOLE__02000000 0x02000000
> #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */
> #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index f00d7ecc2adf..c29059a76052 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -236,16 +236,25 @@ static inline gfp_t current_gfp_context(gfp_t flags)
> {
> unsigned int pflags = READ_ONCE(current->flags);
>
> - if (unlikely(pflags & (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS | PF_MEMALLOC_PIN))) {
> + if (unlikely(pflags & (PF_MEMALLOC_NOIO |
> + PF_MEMALLOC_NOFS |
> + PF_MEMALLOC_NORECLAIM |
> + PF_MEMALLOC_NOWARN |
> + PF_MEMALLOC_PIN))) {
> /*
> - * NOIO implies both NOIO and NOFS and it is a weaker context
> - * so always make sure it makes precedence
> + * Stronger flags before weaker flags:
> + * NORECLAIM implies NOIO, which in turn implies NOFS
> */
> - if (pflags & PF_MEMALLOC_NOIO)
> + if (pflags & PF_MEMALLOC_NORECLAIM)
> + flags &= ~__GFP_DIRECT_RECLAIM;
> + else if (pflags & PF_MEMALLOC_NOIO)
> flags &= ~(__GFP_IO | __GFP_FS);
> else if (pflags & PF_MEMALLOC_NOFS)
> flags &= ~__GFP_FS;
>
> + if (pflags & PF_MEMALLOC_NOWARN)
> + flags |= __GFP_NOWARN;
> +
> if (pflags & PF_MEMALLOC_PIN)
> flags &= ~__GFP_MOVABLE;
> }
next prev parent reply other threads:[~2024-02-07 7:24 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 [this message]
2024-02-07 7:44 ` Michal Hocko
2024-02-07 21:05 ` Kent Overstreet
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=f9ad4bc5-37ce-485b-94d8-afdfaca620c8@suse.cz \
--to=vbabka@suse.cz \
--cc=djwong@kernel.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--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