mbox series

[0/2] btrfs: reduce the width of devices counter

Message ID cover.1695089790.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: reduce the width of devices counter | expand

Message

Qu Wenruo Sept. 19, 2023, 2:21 a.m. UTC
Currently btrfs_super_block::num_devices is u64, thus all of our
internal devices counters are also u64.

But the truth is, it's really impractical to have that many devices, one
of two dozens of devices may be the upper limit in the real world.

In fact we already have a sanity check for
btrfs_super_block::num_devices, if the value is beyond 1<<31, we would
consider it insane and reject the superblock.

Now let's go a step further, by reducing the limit to U16_MAX (65536),
and with that change, we can also reduce the width from 64 to 16 for all
our internal devices counters.
(superblock num_devices still stay u64 though).

Such reduce would slightly reduce the memory usage per-btrfs.

Also with the new device number limit, the 2nd patch would do extra
device number check to avoid overflow u16.

Qu Wenruo (2):
  btrfs: reject a superblock with over 65536 devices
  btrfs: reduce the width of device counters

 fs/btrfs/dev-replace.c |  9 +++++++++
 fs/btrfs/disk-io.c     |  3 ++-
 fs/btrfs/volumes.c     | 11 ++++++++++-
 fs/btrfs/volumes.h     | 12 ++++++------
 4 files changed, 27 insertions(+), 8 deletions(-)