linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Zhongkun He <hezhongkun.hzk@bytedance.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	mhocko@suse.com,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH] mm: rename the oldflags and parameter in memalloc_flags_*()
Date: Thu, 19 Jun 2025 00:16:45 -0400	[thread overview]
Message-ID: <ig5wtmtownn5sebhqeugleb7ns5nf6wgmrbbzgev7henhujhsm@chsmrubxszrq> (raw)
In-Reply-To: <CACSyD1P5ksZHHRZwCr48gDVv9Wt9hXfX9PcXqrd5MpDRJkdzHA@mail.gmail.com>

On Thu, Jun 19, 2025 at 11:17:58AM +0800, Zhongkun He wrote:
> On Thu, Jun 19, 2025 at 8:07 AM Kent Overstreet
> <kent.overstreet@linux.dev> wrote:
> >
> > On Wed, Jun 18, 2025 at 04:43:34PM -0700, Andrew Morton wrote:
> > > On Wed, 18 Jun 2025 15:03:28 +0800 Zhongkun He <hezhongkun.hzk@bytedance.com> wrote:
> > >
> > > > The variable name oldflags can indeed be misleading, because
> > > > it does not store the complete original value of flags.
> > > > Instead, it records which flags from the given set are not
> > > > currently set. So rename it.
> > > >
> > >
> > > Your email client is mangling the patches in strange ways.  Please send
> > > yourself a patch, figure out why it didn't apply?
> > >
> > > > --- a/include/linux/sched/mm.h
> > > > +++ b/include/linux/sched/mm.h
> > > > @@ -322,21 +322,21 @@ static inline void might_alloc(gfp_t gfp_mask)
> > > >  }
> > > >
> > > >  /**
> > > > - * memalloc_flags_save - Add a PF_* flag to current->flags, save old value
> > > > + * memalloc_flags_save - Add a PF_* flag to current->flags, return saved flags mask
> > > >   *
> > > >   * 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)
> > > > +static inline unsigned int memalloc_flags_save(unsigned int flags_mask)
> > > >  {
> > > > -   unsigned oldflags = ~current->flags & flags;
> > > > -   current->flags |= flags;
> > > > -   return oldflags;
> > > > +   unsigned int saved_flags_mask = ~current->flags & flags_mask;
> > > > +
> > > > +   current->flags |= flags_mask;
> > > > +   return saved_flags_mask;
> > > >  }
> > > >
> > > > -static inline void memalloc_flags_restore(unsigned flags)
> > > > +static inline void memalloc_flags_restore(unsigned int flags_mask)
> > > >  {
> > > > -   current->flags &= ~flags;
> > > > +   current->flags &= ~flags_mask;
> > > >  }
> > >
> > > I guess so.  Maybe.  A bit.  Kent, what do you think?
> >
> > Eesh, seems like pointless verbosity to me. Maybe don't change it if it
> > doesn't need to be changed?
> 
> Hi Kent, thanks for your feedback.
> How about this version,  only change the 'old' to 'saved'.
> The function does not return the old current->flags value. Instead,
> it returns the subset of flags that were not previously set in current->flags,
> so they can later be cleared by memalloc_flags_restore(). The name savedflags
> makes this behavior clearer and avoids confusion.

Why change it at all? The returned flags parameter is opaque state that
should only be used by memalloc_flags_restore(), it's not something the
caller should be looking at.

> 
>  /**
> - * memalloc_flags_save - Add a PF_* flag to current->flags, save old value
> + * memalloc_flags_save - Add a PF_* flag to current->flags, return saved flags
>   *
>   * 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;
> +       unsigned savedflags = ~current->flags & flags;
>         current->flags |= flags;
> -       return oldflags;
> +       return savedflags;
>  }
> 
> Thanks,
> Zhongkun


  reply	other threads:[~2025-06-19  4:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  7:03 Zhongkun He
2025-06-18 23:43 ` Andrew Morton
2025-06-19  0:07   ` Kent Overstreet
2025-06-19  3:17     ` [External] " Zhongkun He
2025-06-19  4:16       ` Kent Overstreet [this message]
2025-06-19  4:36         ` Zhongkun He
2025-06-19  2:50   ` Zhongkun He

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=ig5wtmtownn5sebhqeugleb7ns5nf6wgmrbbzgev7henhujhsm@chsmrubxszrq \
    --to=kent.overstreet@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=hezhongkun.hzk@bytedance.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    /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