Avoid too much reserved_size for erofs image

After the erofs image is built, it won't be modified again. The reserve
room is only used for the hash footer. There is no need to set an
excessive margin.

Bug: 199248596
Test: erofs image size is smaller than before
Signed-off-by: Huang Jianan <huangjianan@oppo.com>
Change-Id: If2535b9ad2c2d60bea74feeca576a168387ff341
This commit is contained in:
Huang Jianan 2021-09-08 18:28:32 +08:00 committed by Jianan Huang
parent 1ab1c2ff96
commit 6552727e03

View file

@ -231,6 +231,22 @@ def CheckHeadroom(ext4fs_output, prop_dict):
mount_point, total_blocks, used_blocks, headroom_blocks,
adjusted_blocks))
def CalculateSizeAndReserved(prop_dict, size):
fs_type = prop_dict.get("fs_type", "")
partition_headroom = int(prop_dict.get("partition_headroom", 0))
# If not specified, give us 16MB margin for GetDiskUsage error ...
reserved_size = int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16))
if fs_type == "erofs":
reserved_size = int(prop_dict.get("partition_reserved_size", 0))
if reserved_size == 0:
# give .3% margin or a minimum size for AVB footer
return max(size * 1003 // 1000, 256 * 1024)
if fs_type.startswith("ext4") and partition_headroom > reserved_size:
reserved_size = partition_headroom
return size + reserved_size
def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
"""Builds a pure image for the files under in_dir and writes it to out_file.
@ -468,12 +484,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
size = GetDiskUsage(in_dir)
logger.info(
"The tree size of %s is %d MB.", in_dir, size // BYTES_IN_MB)
# If not specified, give us 16MB margin for GetDiskUsage error ...
reserved_size = int(prop_dict.get("partition_reserved_size", BYTES_IN_MB * 16))
partition_headroom = int(prop_dict.get("partition_headroom", 0))
if fs_type.startswith("ext4") and partition_headroom > reserved_size:
reserved_size = partition_headroom
size += reserved_size
size = CalculateSizeAndReserved(prop_dict, size)
# Round this up to a multiple of 4K so that avbtool works
size = common.RoundUpTo4K(size)
if fs_type.startswith("ext"):