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 1/3] mm: introduce memalloc_flags_{save,restore}
Date: Fri, 9 Feb 2024 11:36:00 +0100 [thread overview]
Message-ID: <dc8253c2-c94e-48a2-9e56-87a5e941ad18@suse.cz> (raw)
In-Reply-To: <20240206215016.961253-2-kent.overstreet@linux.dev>
On 2/6/24 22:50, Kent Overstreet wrote:
> Our proliferation of memalloc_*_{save,restore} APIs is getting a bit
> silly, this adds a generic version and converts the existing
> save/restore functions to wrappers.
>
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> 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
Acked-by: Vlastimil Babka <vbabka@suse.cz>
This will also make it possible to do combinations of flags in a single
call, in case some ad-hoc combinations are needed only in few places that
don't warrant a designated helper.
> ---
> include/linux/sched/mm.h | 43 ++++++++++++++++++++++++----------------
> 1 file changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index 9a19f1b42f64..f00d7ecc2adf 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -306,6 +306,24 @@ static inline void might_alloc(gfp_t gfp_mask)
> might_sleep_if(gfpflags_allow_blocking(gfp_mask));
> }
>
> +/**
> + * memalloc_flags_save - Add a PF_* flag to current->flags, save old value
> + *
> + * This allows PF_* flags to be conveniently added, irrespective of current
> + * value, and then the old version restored with memalloc_flags_restore().
> + */
> +static inline unsigned memalloc_flags_save(unsigned flags)
> +{
> + unsigned oldflags = ~current->flags & flags;
> + current->flags |= flags;
> + return oldflags;
> +}
> +
> +static inline void memalloc_flags_restore(unsigned flags)
> +{
> + current->flags &= ~flags;
> +}
> +
> /**
> * memalloc_noio_save - Marks implicit GFP_NOIO allocation scope.
> *
> @@ -319,9 +337,7 @@ static inline void might_alloc(gfp_t gfp_mask)
> */
> static inline unsigned int memalloc_noio_save(void)
> {
> - unsigned int flags = current->flags & PF_MEMALLOC_NOIO;
> - current->flags |= PF_MEMALLOC_NOIO;
> - return flags;
> + return memalloc_flags_save(PF_MEMALLOC_NOIO);
> }
>
> /**
> @@ -334,7 +350,7 @@ static inline unsigned int memalloc_noio_save(void)
> */
> static inline void memalloc_noio_restore(unsigned int flags)
> {
> - current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
> + memalloc_flags_restore(flags);
> }
>
> /**
> @@ -350,9 +366,7 @@ static inline void memalloc_noio_restore(unsigned int flags)
> */
> static inline unsigned int memalloc_nofs_save(void)
> {
> - unsigned int flags = current->flags & PF_MEMALLOC_NOFS;
> - current->flags |= PF_MEMALLOC_NOFS;
> - return flags;
> + return memalloc_flags_save(PF_MEMALLOC_NOFS);
> }
>
> /**
> @@ -365,32 +379,27 @@ static inline unsigned int memalloc_nofs_save(void)
> */
> static inline void memalloc_nofs_restore(unsigned int flags)
> {
> - current->flags = (current->flags & ~PF_MEMALLOC_NOFS) | flags;
> + memalloc_flags_restore(flags);
> }
>
> static inline unsigned int memalloc_noreclaim_save(void)
> {
> - unsigned int flags = current->flags & PF_MEMALLOC;
> - current->flags |= PF_MEMALLOC;
> - return flags;
> + return memalloc_flags_save(PF_MEMALLOC);
> }
>
> static inline void memalloc_noreclaim_restore(unsigned int flags)
> {
> - current->flags = (current->flags & ~PF_MEMALLOC) | flags;
> + memalloc_flags_restore(flags);
> }
>
> static inline unsigned int memalloc_pin_save(void)
> {
> - unsigned int flags = current->flags & PF_MEMALLOC_PIN;
> -
> - current->flags |= PF_MEMALLOC_PIN;
> - return flags;
> + return memalloc_flags_save(PF_MEMALLOC_PIN);
> }
>
> static inline void memalloc_pin_restore(unsigned int flags)
> {
> - current->flags = (current->flags & ~PF_MEMALLOC_PIN) | flags;
> + memalloc_flags_restore(flags);
> }
>
> #ifdef CONFIG_MEMCG
next prev parent reply other threads:[~2024-02-09 10:36 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 [this message]
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
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=dc8253c2-c94e-48a2-9e56-87a5e941ad18@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