btrfs-progs/mkfs
Qu Wenruo 599a0abed5 btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier
Use an easier method to calculate the estimate device size for
mkfs.btrfs --rootdir.

The new method will over-estimate, but should ensure we won't encounter
ENOSPC.

It relies on the following data:
1) number of inodes -- for metadata chunk size
2) rounded up data size of each regular inode -- for data chunk size

Total meta chunk size = round_up(nr_inode * (PATH_MAX * 3 + sectorsize),
min_chunk_size) * profile_multiplier

PATH_MAX is the maximum size possible for INODE_REF/DIR_INDEX/DIR_ITEM.
Sectorsize is the maximum size possible for inline extent.
min_chunk_size is 8M for SINGLE, and 32M for DUP, get from
btrfs_alloc_chunk().
profile_multiplier is 1 for Single, 2 for DUP.

Total data chunk size is much easier.
Total data chunk size = round_up(total_data_usage, min_chunk_size) *
profile_multiplier

Total_data_usage is the sum of *rounded up* size of each regular inode
use.
min_chunk_size is 8M for SINGLE, 64M for DUP, get from btrfS_alloc_chunk().
Same profile_multiplier for meta.

This over-estimate calculate is, of course inacurrate, but since we will
later shrink the fs to its real usage, it doesn't matter much now.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update comments ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:15:11 +01:00
..
common.c btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on small file 2018-01-03 17:10:11 +01:00
common.h btrfs-progs: mkfs: Enhance minimal device size calculation to fix mkfs failure on small file 2018-01-03 17:10:11 +01:00
main.c btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier 2018-01-08 18:15:11 +01:00
rootdir.c btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier 2018-01-08 18:15:11 +01:00
rootdir.h btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier 2018-01-08 18:15:11 +01:00