Skip to content

Commit

Permalink
btrfs: make free space cache size consistent across different PAGE_SIZE
Browse files Browse the repository at this point in the history
Currently free space cache inode size is determined by two factors:

- block group size
- PAGE_SIZE

This means, for the same sized block groups, with different PAGE_SIZE,
it will result in different inode sizes.

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 what the PAGE_SIZE is.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Qu Wenruo authored and David Sterba committed Jun 21, 2021
1 parent 8df507c commit 0044ae1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions fs/btrfs/block-group.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,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;

Expand Down Expand Up @@ -2617,20 +2617,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
Expand Down

0 comments on commit 0044ae1

Please sign in to comment.