[PATCH 2/4] btrfs: cache max and min order inside btrfs_fs_info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Inside btrfs_fs_info we cache several bits shift like sectorsize_bits.

Apply this to max and min folio orders so that every time mapping order
needs to be applied we can skip the calculation.

Furthermore all those sectorsize/nodesize shifts, along with the new
min/max folio orders have a very limited value range by their natures.

E.g. blocksize bits can be at most ilog2(64K) which is 16, and for 4K
page size and 64K block size (bs > ps) the minimal folio order is only
4.
Neither those number can even exceed U8_MAX, thus there is no need to
use u32 for those bits.

Use u8 for those members to save memory.

Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
---
 fs/btrfs/btrfs_inode.h | 6 +++---
 fs/btrfs/disk-io.c     | 2 ++
 fs/btrfs/fs.h          | 8 +++++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index df3445448b7d..a9d6e1bfebae 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -527,14 +527,14 @@ static inline void btrfs_update_inode_mapping_flags(struct btrfs_inode *inode)
 
 static inline void btrfs_set_inode_mapping_order(struct btrfs_inode *inode)
 {
+	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 	/* Metadata inode should not reach here. */
 	ASSERT(is_data_inode(inode));
 
 	/* We only allow BITS_PER_LONGS blocks for each bitmap. */
 #ifdef CONFIG_BTRFS_EXPERIMENTAL
-	mapping_set_folio_order_range(inode->vfs_inode.i_mapping, 0,
-			ilog2(((BITS_PER_LONG << inode->root->fs_info->sectorsize_bits)
-				>> PAGE_SHIFT)));
+	mapping_set_folio_order_range(inode->vfs_inode.i_mapping, fs_info->block_min_order,
+				      fs_info->block_max_order);
 #endif
 }
 
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 7b06bbc40898..a2eba8bc4336 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3383,6 +3383,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 	fs_info->nodesize_bits = ilog2(nodesize);
 	fs_info->sectorsize = sectorsize;
 	fs_info->sectorsize_bits = ilog2(sectorsize);
+	fs_info->block_min_order = ilog2(round_up(sectorsize, PAGE_SIZE) >> PAGE_SHIFT);
+	fs_info->block_max_order = ilog2((BITS_PER_LONG << fs_info->sectorsize_bits) >> PAGE_SHIFT);
 	fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size;
 	fs_info->stripesize = stripesize;
 	fs_info->fs_devices->fs_info = fs_info;
diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
index 5f0b185a7f21..412d3eb30b73 100644
--- a/fs/btrfs/fs.h
+++ b/fs/btrfs/fs.h
@@ -820,11 +820,13 @@ struct btrfs_fs_info {
 	struct mutex reclaim_bgs_lock;
 
 	/* Cached block sizes */
-	u32 nodesize;
-	u32 nodesize_bits;
 	u32 sectorsize;
+	u32 nodesize;
 	/* ilog2 of sectorsize, use to avoid 64bit division */
-	u32 sectorsize_bits;
+	u8 sectorsize_bits;
+	u8 nodesize_bits;
+	u8 block_min_order;
+	u8 block_max_order;
 	u32 csum_size;
 	u32 csums_per_leaf;
 	u32 stripesize;
-- 
2.50.1





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux