]> www.infradead.org Git - users/jedix/linux-maple.git/commit
btrfs: scrub: reduce memory usage of struct scrub_sector_verification
authorQu Wenruo <wqu@suse.com>
Wed, 7 May 2025 04:25:42 +0000 (13:55 +0930)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:56 +0000 (14:30 +0200)
commit4ad57e1e224a349cede42e1fcb8abded0e4850ab
tree4605a9ca536d0c9742dd03a1dd000b0a492ccc81
parent4e2945f73b076bbd5c0bbb8f0da1e52180de9bda
btrfs: scrub: reduce memory usage of struct scrub_sector_verification

That structure records needed info for block verification (either data
checksum pointer, or expected tree block generation).

But there is also a boolean to tell if this block belongs to a metadata
or not, as the data checksum pointer and expected tree block generation
is already a union, we need a dedicated bit to tell if this block is a
metadata or not.

However such layout means we're wasting 63 bits for x86_64, which is a
huge memory waste.

Thanks to the recent bitmap aggregation, we can easily move this
single-bit-per-block member to a new sub-bitmap.
And since we already have six 16 bits long bitmaps, adding another
bitmap won't even increase any memory usage for x86_64, as we need two
64 bits long anyway.

This will reduce the following memory usages:

- sizeof(struct scrub_sector_verification)
  From 16 bytes to 8 bytes on x86_64.

- scrub_stripe::sectors
  From 16 * 16 to 16 * 8 bytes.

- Per-device scrub_ctx memory usage
  From 128 * (16 * 16) to 128 * (16 * 8), which saves 16KiB memory.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c