Re: [PATCHES][RFC] packing struct block_device flags

Christoph Hellwig
2024-04-29T05:23:19Z

On Sun, Apr 28, 2024 at 06:12:32AM +0100, Al Viro wrote:
> We have several bool members in struct block_device.
> It would be nice to pack that stuff, preferably without
> blowing the cacheline boundaries.
>
> That had been suggested a while ago, and initial
> implementation by Yu Kuai <yukuai1@huaweicloud.com> ran into
> objections re atomicity, along with the obvious suggestion to
> use unsigned long and test_bit/set_bit/clear_bit for access.
> Unfortunately, that *does* blow the cacheline boundaries.
>
> However, it's not hard to do that without bitops;
> we have an 8-bit assign-once partition number nearby, and
> folding it into a 32-bit member leaves us up to 24 bits for
> flags. Using cmpxchg for setting/clearing flags is not
> hard, and 32bit cmpxchg is supported everywhere.

To me this looks pretty complicated and arcane. How about we just
reclaim a little space in the block device and just keep bd_partno
and add an unsigned long base flags?

E.g. bd_meta_info is only used in slow path early boot and sysfs code
and just set for a few partitions.

Just turn it into a hash/xrray/whatever indexed by bd_dev and we've
already reclaimed enough space.