[PATCH v2 07/19] btrfs: update num_extent_pages() to support subpage sized extent buffer

Qu Wenruo
2020-09-15T05:36:00Z

For subpage sized extent buffer, we have ensured no extent buffer will
cross page boundary, thus we would only need one page for any extent
buffer.

This patch will update the function num_extent_pages() to handle such
case.
Now num_extent_pages() would return 1 instead of for subpage sized
extent buffer.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/extent_io.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index d511890702cc..61556d6e9363 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -229,8 +229,15 @@ void wait_on_extent_buffer_writeback(struct extent_buffer *eb);

static inline int num_extent_pages(const struct extent_buffer *eb)
{
- return (round_up(eb->start + eb->len, PAGE_SIZE) >> PAGE_SHIFT) -
- (eb->start >> PAGE_SHIFT);
+ /*
+ * For sectorsize == PAGE_SIZE case, since eb is always aligned to
+ * sectorsize, it's just (eb->len / PAGE_SIZE) >> PAGE_SHIFT.
+ *
+ * For sectorsize < PAGE_SIZE case, we only want to support 64K
+ * PAGE_SIZE, and ensured all tree blocks won't cross page boundary.
+ * So in that case we always got 1 page.
+ */
+ return (round_up(eb->len, PAGE_SIZE) >> PAGE_SHIFT);
}

static inline int extent_buffer_uptodate(const struct extent_buffer *eb)
--
2.28.0