Currently free space cache inode size is determined by two factors:
- block group size
- PAGE_SIZE

This means, for the same sized block group, with different PAGE_SIZE, it
will result different inode size.

This will not be a good thing for subpage support, so change the
requirement for PAGE_SIZE to sectorsize.

Now for the same 4K sectorsize btrfs, it should result the same inode
size no matter whatever the PAGE_SIZE is.

Signed-off-by: Qu Wenruo <w...@suse.com>
---
 fs/btrfs/block-group.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 293f3169be80..a0591eca270b 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2414,7 +2414,7 @@ static int cache_save_setup(struct btrfs_block_group 
*block_group,
        struct extent_changeset *data_reserved = NULL;
        u64 alloc_hint = 0;
        int dcs = BTRFS_DC_ERROR;
-       u64 num_pages = 0;
+       u64 cache_size = 0;
        int retries = 0;
        int ret = 0;
 
@@ -2526,20 +2526,20 @@ static int cache_save_setup(struct btrfs_block_group 
*block_group,
         * taking up quite a bit since it's not folded into the other space
         * cache.
         */
-       num_pages = div_u64(block_group->length, SZ_256M);
-       if (!num_pages)
-               num_pages = 1;
+       cache_size = div_u64(block_group->length, SZ_256M);
+       if (!cache_size)
+               cache_size = 1;
 
-       num_pages *= 16;
-       num_pages *= PAGE_SIZE;
+       cache_size *= 16;
+       cache_size *= fs_info->sectorsize;
 
        ret = btrfs_check_data_free_space(BTRFS_I(inode), &data_reserved, 0,
-                                         num_pages);
+                                         cache_size);
        if (ret)
                goto out_put;
 
-       ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages,
-                                             num_pages, num_pages,
+       ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, cache_size,
+                                             cache_size, cache_size,
                                              &alloc_hint);
        /*
         * Our cache requires contiguous chunks so that we don't modify a bunch
-- 
2.31.1

Reply via email to