@@ -2813,6 +2813,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
fs_info->sectorsize = 4096;
fs_info->sectorsize_bits = ilog2(4096);
fs_info->stripesize = 4096;
+ fs_info->folio_size = PAGE_SIZE;
+ fs_info->folio_shift = PAGE_SHIFT;
/* Default compress algorithm when user does -o compress */
fs_info->compress_type = BTRFS_COMPRESS_ZLIB;
@@ -3306,6 +3308,15 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size;
fs_info->stripesize = stripesize;
+ if (sectorsize > PAGE_SIZE) {
+ /* For future multi-page sectorsize support */
+ fs_info->folio_size = sectorsize;
+ fs_info->sectorsize_bits = fs_info->sectorsize_bits;
+ } else {
+ fs_info->folio_size = PAGE_SIZE;
+ fs_info->folio_shift = PAGE_SHIFT;
+ }
+
/*
* Handle the space caching options appropriately now that we have the
* super block loaded and validated.
@@ -750,6 +750,16 @@ struct btrfs_fs_info {
u32 csums_per_leaf;
u32 stripesize;
+ /*
+ * For future subpage and multipage sectorsize support.
+ *
+ * For subpage, all of our data folios would still be PAGE_SIZE.
+ * But for multipage, those data folios would be sector sized.
+ * This is the cached result to read/write path to utilize.
+ */
+ u32 folio_size;
+ u32 folio_shift;
+
/*
* Maximum size of an extent. BTRFS_MAX_EXTENT_SIZE on regular
* filesystem, on zoned it depends on the device constraints.
For the future multipage sectorsize support (sectorsize > PAGE_SIZE), we want to fully utilize folio interface, thus making every data sector to be represented by a folio. However this would lead to a small problem that multipage and subpage support would have every different folio size expectation. For subpage, since folio can not be smaller than a page, one folio would always be page sized. But for multiplage, each folio would be sector sized. For callsites directly handling pages/folios (aka, all read/write paths) we don't want to do such check every time we got a folio. So instead we cache the data folio size and its shift into btrfs_fs_info. This would make later folio conversion easier. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/disk-io.c | 11 +++++++++++ fs/btrfs/fs.h | 10 ++++++++++ 2 files changed, 21 insertions(+)