mbox series

[v2,0/2] btrfs: two small and safe fixes for large folios

Message ID cover.1743493507.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: two small and safe fixes for large folios | expand

Message

Qu Wenruo April 1, 2025, 7:50 a.m. UTC
[CHANGELOG]
v2:
- Fix a bug that page_pgoff() usage lacks left page shift

Two small and simple fixes.

The first one is that with large folios, we can have order 6 folios which
reached our current BITS_PER_LONG limit, triggering a previously
impossible ASSERT(), which is based on the fact that our largest page
size (64K) can not reach BITS_PER_LONG blocks per page.

An easily fix by extending the ASSERT() condition to cover
blocks_per_folio == BITS_PER_LONG cases.

The second one is a little more complex, that with large folios, if we
still go through the single page bio vec iteration, we can not call
page_offset(), as non-head pages of a large folio do not have their
page::index initialized properly.

Fix that by going a helper using page_pgoff() to calculate the file
offset, which handles both head and non-head pages of a large folio.

Qu Wenruo (2):
  btrfs: fix the ASSERT() inside GET_SUBPAGE_BITMAP()
  btrfs: fix the file offset calculation inside
    btrfs_decompress_buf2page()

 fs/btrfs/compression.c | 18 +++++++++++++++++-
 fs/btrfs/subpage.c     |  2 +-
 2 files changed, 18 insertions(+), 2 deletions(-)

Comments

Boris Burkov April 1, 2025, 4:20 p.m. UTC | #1
On Tue, Apr 01, 2025 at 06:20:27PM +1030, Qu Wenruo wrote:
> [CHANGELOG]
> v2:
> - Fix a bug that page_pgoff() usage lacks left page shift
> 
> Two small and simple fixes.
> 
> The first one is that with large folios, we can have order 6 folios which
> reached our current BITS_PER_LONG limit, triggering a previously
> impossible ASSERT(), which is based on the fact that our largest page
> size (64K) can not reach BITS_PER_LONG blocks per page.
> 
> An easily fix by extending the ASSERT() condition to cover
> blocks_per_folio == BITS_PER_LONG cases.
> 
> The second one is a little more complex, that with large folios, if we
> still go through the single page bio vec iteration, we can not call
> page_offset(), as non-head pages of a large folio do not have their
> page::index initialized properly.
> 
> Fix that by going a helper using page_pgoff() to calculate the file
> offset, which handles both head and non-head pages of a large folio.

LGTM, thanks.
Reviewed-by: Boris Burkov <boris@bur.io>

> 
> Qu Wenruo (2):
>   btrfs: fix the ASSERT() inside GET_SUBPAGE_BITMAP()
>   btrfs: fix the file offset calculation inside
>     btrfs_decompress_buf2page()
> 
>  fs/btrfs/compression.c | 18 +++++++++++++++++-
>  fs/btrfs/subpage.c     |  2 +-
>  2 files changed, 18 insertions(+), 2 deletions(-)
> 
> -- 
> 2.49.0
>
Sweet Tea Dorminy April 1, 2025, 6:29 p.m. UTC | #2
On 4/1/25 3:50 AM, Qu Wenruo wrote:
> [CHANGELOG]
> v2:
> - Fix a bug that page_pgoff() usage lacks left page shift
> 
> Two small and simple fixes.
> 
> The first one is that with large folios, we can have order 6 folios which
> reached our current BITS_PER_LONG limit, triggering a previously
> impossible ASSERT(), which is based on the fact that our largest page
> size (64K) can not reach BITS_PER_LONG blocks per page.
> 
> An easily fix by extending the ASSERT() condition to cover
> blocks_per_folio == BITS_PER_LONG cases.
> 
> The second one is a little more complex, that with large folios, if we
> still go through the single page bio vec iteration, we can not call
> page_offset(), as non-head pages of a large folio do not have their
> page::index initialized properly.
> 
> Fix that by going a helper using page_pgoff() to calculate the file
> offset, which handles both head and non-head pages of a large folio.
> 
> Qu Wenruo (2):
>    btrfs: fix the ASSERT() inside GET_SUBPAGE_BITMAP()
>    btrfs: fix the file offset calculation inside
>      btrfs_decompress_buf2page()
> 
>   fs/btrfs/compression.c | 18 +++++++++++++++++-
>   fs/btrfs/subpage.c     |  2 +-
>   2 files changed, 18 insertions(+), 2 deletions(-)
> 

Reviewed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>