linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: Yafang Shao <laoar.shao@gmail.com>,
	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 10:34:27 +1000	[thread overview]
Message-ID: <20200618003427.GZ2040@dread.disaster.area> (raw)
In-Reply-To: <20200616104806.GE9499@dhcp22.suse.cz>

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...

> > 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...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com


  parent reply	other threads:[~2020-06-19  6:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 11:56 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 [this message]
2020-06-18 11:04             ` Yafang Shao
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=20200618003427.GZ2040@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=akpm@linux-foundation.org \
    --cc=darrick.wong@oracle.com \
    --cc=hch@infradead.org \
    --cc=laoar.shao@gmail.com \
    --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