linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
	Dave Chinner <david@fromorbit.com>,
	Christoph Hellwig <hch@infradead.org>,
	Michal Hocko <mhocko@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Howells <dhowells@redhat.com>,
	jlayton@redhat.com, linux-fsdevel@vger.kernel.org,
	linux-cachefs@redhat.com, linux-xfs@vger.kernel.org,
	Linux MM <linux-mm@kvack.org>, Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH v10 2/4] xfs: use memalloc_nofs_{save,restore} in xfs transaction
Date: Tue, 8 Dec 2020 11:05:06 +0800	[thread overview]
Message-ID: <CALOAHbAe_BQzNEJNZCa-ixt4FUEoxHvxkj=jNCGiMF4LnzSwtw@mail.gmail.com> (raw)
In-Reply-To: <20201208024637.GG7338@casper.infradead.org>

On Tue, Dec 8, 2020 at 10:46 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Tue, Dec 08, 2020 at 10:15:41AM +0800, Yafang Shao wrote:
> > memalloc_nofs_{save,restore} API is introduced in
> > commit 7dea19f9ee63 ("mm: introduce memalloc_nofs_{save,restore} API"),
> > which gives a better abstraction of the usage around PF_MEMALLOC_NOFS. We'd
> > better use this API in XFS instead of using PF_MEMALLOC_NOFS directly as
> > well.
> >
> > To prepare for the followup patch, two new helpers are introduced in XFS
> > to wrap the memalloc_nofs_{save,restore} API, as follows,
> >
> > static inline void
> > xfs_trans_context_set(struct xfs_trans *tp)
> > {
> >       tp->t_pflags = memalloc_nofs_save();
> > }
> >
> > static inline void
> > xfs_trans_context_clear(struct xfs_trans *tp)
> > {
> >       memalloc_nofs_restore(tp->t_pflags);
> > }
>
> Don't repeat the contents of the patch in the changelog.
>

Sure.

> Also, this ordering of patches doesn't make sense.  If I saw this
> patch by itself instead of part of the series, there's no good reason
> to replace one xfs-specific wrapper (current_set_flags_nested) with
> another (xfs_trans_context_set).
>
> If the changelog here said something like ...
>
> Introduce a new API to mark the start and end of XFS transactions.
> For now, just save and restore the memalloc_nofs flags.
>
> ... then it might make more sense to do things in this order.
>

Thanks. I will update it in the next version.

> > These two new helpers are added into xfs_tans.h as they are used in xfs
> > transaction only.
> >
> > Cc: Darrick J. Wong <darrick.wong@oracle.com>
> > Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> > Cc: Christoph Hellwig <hch@lst.de>
> > Cc: Dave Chinner <david@fromorbit.com>
> > Cc: Michal Hocko <mhocko@kernel.org>
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  fs/xfs/xfs_aops.c  |  4 ++--
> >  fs/xfs/xfs_linux.h |  4 ----
> >  fs/xfs/xfs_trans.c | 13 +++++++------
> >  fs/xfs/xfs_trans.h | 12 ++++++++++++
> >  4 files changed, 21 insertions(+), 12 deletions(-)
> >
> > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> > index 4304c6416fbb..2371187b7615 100644
> > --- a/fs/xfs/xfs_aops.c
> > +++ b/fs/xfs/xfs_aops.c
> > @@ -62,7 +62,7 @@ xfs_setfilesize_trans_alloc(
> >        * We hand off the transaction to the completion thread now, so
> >        * clear the flag here.
> >        */
> > -     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_clear(tp);
> >       return 0;
> >  }
> >
> > @@ -125,7 +125,7 @@ xfs_setfilesize_ioend(
> >        * thus we need to mark ourselves as being in a transaction manually.
> >        * Similarly for freeze protection.
> >        */
> > -     current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_set(tp);
> >       __sb_writers_acquired(VFS_I(ip)->i_sb, SB_FREEZE_FS);
> >
> >       /* we abort the update if there was an IO error */
> > diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
> > index 5b7a1e201559..6ab0f8043c73 100644
> > --- a/fs/xfs/xfs_linux.h
> > +++ b/fs/xfs/xfs_linux.h
> > @@ -102,10 +102,6 @@ typedef __u32                    xfs_nlink_t;
> >  #define xfs_cowb_secs                xfs_params.cowb_timer.val
> >
> >  #define current_cpu()                (raw_smp_processor_id())
> > -#define current_set_flags_nested(sp, f)              \
> > -             (*(sp) = current->flags, current->flags |= (f))
> > -#define current_restore_flags_nested(sp, f)  \
> > -             (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
> >
> >  #define NBBY         8               /* number of bits per byte */
> >
> > diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
> > index c94e71f741b6..11d390f0d3f2 100644
> > --- a/fs/xfs/xfs_trans.c
> > +++ b/fs/xfs/xfs_trans.c
> > @@ -154,7 +154,7 @@ xfs_trans_reserve(
> >       bool                    rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
> >
> >       /* Mark this thread as being in a transaction */
> > -     current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_set(tp);
> >
> >       /*
> >        * Attempt to reserve the needed disk blocks by decrementing
> > @@ -164,7 +164,7 @@ xfs_trans_reserve(
> >       if (blocks > 0) {
> >               error = xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd);
> >               if (error != 0) {
> > -                     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +                     xfs_trans_context_clear(tp);
> >                       return -ENOSPC;
> >               }
> >               tp->t_blk_res += blocks;
> > @@ -241,7 +241,7 @@ xfs_trans_reserve(
> >               tp->t_blk_res = 0;
> >       }
> >
> > -     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_clear(tp);
> >
> >       return error;
> >  }
> > @@ -878,7 +878,7 @@ __xfs_trans_commit(
> >
> >       xfs_log_commit_cil(mp, tp, &commit_lsn, regrant);
> >
> > -     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_clear(tp);
> >       xfs_trans_free(tp);
> >
> >       /*
> > @@ -910,7 +910,8 @@ __xfs_trans_commit(
> >                       xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket);
> >               tp->t_ticket = NULL;
> >       }
> > -     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +
> > +     xfs_trans_context_clear(tp);
> >       xfs_trans_free_items(tp, !!error);
> >       xfs_trans_free(tp);
> >
> > @@ -971,7 +972,7 @@ xfs_trans_cancel(
> >       }
> >
> >       /* mark this thread as no longer being in a transaction */
> > -     current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS);
> > +     xfs_trans_context_clear(tp);
> >
> >       xfs_trans_free_items(tp, dirty);
> >       xfs_trans_free(tp);
> > diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
> > index 084658946cc8..44b11c64a15e 100644
> > --- a/fs/xfs/xfs_trans.h
> > +++ b/fs/xfs/xfs_trans.h
> > @@ -268,4 +268,16 @@ xfs_trans_item_relog(
> >       return lip->li_ops->iop_relog(lip, tp);
> >  }
> >
> > +static inline void
> > +xfs_trans_context_set(struct xfs_trans *tp)
> > +{
> > +     tp->t_pflags = memalloc_nofs_save();
> > +}
> > +
> > +static inline void
> > +xfs_trans_context_clear(struct xfs_trans *tp)
> > +{
> > +     memalloc_nofs_restore(tp->t_pflags);
> > +}
> > +
> >  #endif       /* __XFS_TRANS_H__ */
> > --
> > 2.18.4
> >
> >



-- 
Thanks
Yafang

  reply	other threads:[~2020-12-08  3:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  2:15 [PATCH v10 0/4] xfs: avoid transaction reservation recursion Yafang Shao
2020-12-08  2:15 ` [PATCH v10 1/4] mm: Add become_kswapd and restore_kswapd Yafang Shao
2020-12-08  2:15 ` [PATCH v10 2/4] xfs: use memalloc_nofs_{save,restore} in xfs transaction Yafang Shao
2020-12-08  2:46   ` Matthew Wilcox
2020-12-08  3:05     ` Yafang Shao [this message]
2020-12-08  2:15 ` [PATCH v10 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} Yafang Shao
2020-12-08  2:15 ` [PATCH v10 4/4] xfs: use current->journal_info to avoid transaction reservation recursion Yafang Shao
2020-12-08  2:41   ` Matthew Wilcox
2020-12-08  3:03     ` Yafang Shao
2020-12-08  4:20   ` Dave Chinner
2020-12-08  5:01     ` Yafang Shao

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='CALOAHbAe_BQzNEJNZCa-ixt4FUEoxHvxkj=jNCGiMF4LnzSwtw@mail.gmail.com' \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=jlayton@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).