[lkml]   [2021]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH AUTOSEL 5.13 75/85] btrfs: make Private2 lifespan more consistent
On Sun, Jul 04, 2021 at 07:04:10PM -0400, Sasha Levin wrote:
> From: Qu Wenruo <>
> [ Upstream commit 87b4d86baae219a9a79f6b0a1434b2a42fd40d09 ]
> Currently we use page Private2 bit to indicate that we have ordered
> extent for the page range.
> But the lifespan of it is not consistent, during regular writeback path,
> there are two locations to clear the same PagePrivate2:
> T ----- Page marked Dirty
> |
> + ----- Page marked Private2, through btrfs_run_dealloc_range()
> |
> + ----- Page cleared Private2, through btrfs_writepage_cow_fixup()
> | in __extent_writepage_io()
> | ^^^ Private2 cleared for the first time
> |
> + ----- Page marked Writeback, through btrfs_set_range_writeback()
> | in __extent_writepage_io().
> |
> + ----- Page cleared Private2, through
> | btrfs_writepage_endio_finish_ordered()
> | ^^^ Private2 cleared for the second time.
> |
> + ----- Page cleared Writeback, through
> btrfs_writepage_endio_finish_ordered()
> Currently PagePrivate2 is mostly to prevent ordered extent accounting
> being executed for both endio and invalidatepage.
> Thus only the one who cleared page Private2 is responsible for ordered
> extent accounting.
> But the fact is, in btrfs_writepage_endio_finish_ordered(), page
> Private2 is cleared and ordered extent accounting is executed
> unconditionally.
> The race prevention only happens through btrfs_invalidatepage(), where
> we wait for the page writeback first, before checking the Private2 bit.
> This means, Private2 is also protected by Writeback bit, and there is no
> need for btrfs_writepage_cow_fixup() to clear Priavte2.
> This patch will change btrfs_writepage_cow_fixup() to just check
> PagePrivate2, not to clear it.
> The clearing will happen in either btrfs_invalidatepage() or
> btrfs_writepage_endio_finish_ordered().
> This makes the Private2 bit easier to understand, just meaning the page
> has unfinished ordered extent attached to it.
> And this patch is a hard requirement for the incoming refactoring for
> how we finished ordered IO for endio context, as the coming patch will
> check Private2 to determine if we need to do the ordered extent
> accounting. Thus this patch is definitely needed or we will hang due to
> unfinished ordered extent.
> Reviewed-by: Josef Bacik <>
> Signed-off-by: Qu Wenruo <>
> Signed-off-by: David Sterba <>
> Signed-off-by: Sasha Levin <>

Please drop this patch from all autosel stable backports. This is not a
standalone fix and the CC: stable@ is not there intentionally.

All patches that go through my tree are evaluated for stable backports
up to 4.4 so it's unlikely the machinery you're using can find something
I've overlooked.

The patches that autosel picks and do not get a complain^Wreply for me
are below the bar I'd consider it for stable but if after another review
the patch "does no harm", I let it pass because you're obviously
handling the backports. I would not tag it myself to avoid increasing
load of Greg with patches that don't matter much.

 \ /
  Last update: 2021-07-07 13:13    [W:1.236 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site