linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Dave Chinner <david@fromorbit.com>
Cc: Michal Hocko <mhocko@kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	"Darrick J. Wong" <darrick.wong@oracle.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Linux MM <linux-mm@kvack.org>
Subject: Re: [PATCH v3] xfs: avoid deadlock when trigger memory reclaim in ->writepages
Date: Thu, 18 Jun 2020 19:04:49 +0800	[thread overview]
Message-ID: <CALOAHbAtmSzyj-r3ghX311+BLmHHT-Bb0WRmzmAFRV6SuvevGw@mail.gmail.com> (raw)
In-Reply-To: <20200618003427.GZ2040@dread.disaster.area>

On Thu, Jun 18, 2020 at 8:34 AM Dave Chinner <david@fromorbit.com> wrote:
>
> On Tue, Jun 16, 2020 at 12:48:06PM +0200, Michal Hocko wrote:
> > On Tue 16-06-20 17:39:33, Yafang Shao wrote:
> > > The history is complicated, but it doesn't matter.
> > > Let's  turn back to the upstream kernel now. As I explained in the commit log,
> > > xfs_vm_writepages
> > >   -> iomap_writepages.
> > >      -> write_cache_pages
> > >         -> lock_page <<<< This page is locked.
> > >         -> writepages ( which is  iomap_do_writepage)
> > >            -> xfs_map_blocks
> > >               -> xfs_convert_blocks
> > >                  -> xfs_bmapi_convert_delalloc
> > >                     -> xfs_trans_alloc
> > >                          -> kmem_zone_zalloc //It should alloc page
> > > with GFP_NOFS
> > >
> > > If GFP_NOFS isn't set in xfs_trans_alloc(), the kmem_zone_zalloc() may
> > > trigger the memory reclaim then it may wait on the page locked in
> > > write_cache_pages() ...
> >
> > This cannot happen because the memory reclaim backs off on locked pages.
>
> ->writepages can hold a bio with multiple PageWriteback pages
> already attached to it. Direct GFP_KERNEL page reclaim can wait on
> them - if that happens the the bio will never be issued and so
> reclaim will deadlock waiting for the writeback state to clear...
>

Thanks for the explanation.

> > > That means the ->writepages should be set with GFP_NOFS to avoid this
> > > recursive filesystem reclaim.
>
> Indeed. We already have parts of the IO submission path under
> PF_MEMALLOC_NOFS so we can do transaction allocation, etc. See
> xfs_prepare_ioend(), which is called from iomap via:
>
> iomap_submit_ioend()
>   ->prepare_ioend()
>     xfs_prepare_ioend()
>
> we can get there from:
>
> iomap_writepage()
>   iomap_do_writepage()
>     iomap_writepage_map()
>       iomap_submit_ioend()
>   iomap_submit_ioend()
>
> and:
>
> iomap_writepages()
>   write_cache_pages()
>     iomap_do_writepage()
>       iomap_writepage_map()
>         iomap_submit_ioend()
>   iomap_submit_ioend()
>
> Which says that we really should be putting both iomap_writepage()
> and iomap_writepages() under PF_MEMALLOC_NOFS context so that
> filesystem callouts don't have to repeatedly enter and exit
> PF_MEMALLOC_NOFS context to avoid memory reclaim recursion...
>

Looks reasonable.
I will update this patch to put both iomap_writepage() and
iomap_writepages() under PF_MEMALLOC_NOFS context and try to remove
the usage of PF_MEMALLOC_NOFS from the filesystem callouts.


-- 
Thanks
Yafang

  reply	other threads:[~2020-06-18 11:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 11:56 [PATCH v3] xfs: avoid deadlock when trigger memory reclaim in ->writepages Yafang Shao
2020-06-15 14:25 ` Holger Hoffstätte
2020-06-15 14:51   ` Yafang Shao
2020-06-15 14:53   ` Michal Hocko
2020-06-15 15:07     ` Matthew Wilcox
2020-06-15 23:23       ` Dave Chinner
2020-06-15 15:08     ` Yafang Shao
2020-06-15 23:06     ` Dave Chinner
2020-06-16  7:56       ` Michal Hocko
2020-06-16 10:17       ` Yafang Shao
2020-06-16  8:16 ` Michal Hocko
2020-06-16  9:05   ` Yafang Shao
2020-06-16  9:27     ` Michal Hocko
2020-06-16  9:39       ` Yafang Shao
2020-06-16 10:48         ` Michal Hocko
2020-06-16 11:42           ` Yafang Shao
2020-06-18  0:34           ` Dave Chinner
2020-06-18 11:04             ` Yafang Shao [this message]
2020-06-22  1:23 ` [xfs] 59d77e81c5: WARNING:at_fs/iomap/buffered-io.c:#iomap_do_writepage kernel test robot
2020-06-22 12:20   ` 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=CALOAHbAtmSzyj-r3ghX311+BLmHHT-Bb0WRmzmAFRV6SuvevGw@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=mhocko@kernel.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).