From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel@vger.kernel.org, Yu Kuai <yukuai1@huaweicloud.com>,
linux-block@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCHES][RFC] packing struct block_device flags
Date: Mon, 29 Apr 2024 08:31:07 +0100 [thread overview]
Message-ID: <20240429073107.GZ2118490@ZenIV> (raw)
In-Reply-To: <20240429052315.GB32688@lst.de>
On Mon, Apr 29, 2024 at 07:23:15AM +0200, Christoph Hellwig wrote:
> 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.
cmpxchg for setting/clearing a bit in u32 is hardly arcane,
especially since these bits are rarely modified. _Reading_
is done on hot paths, but that's cheap.
For more familiar form,
static inline void bdev_set_flag(struct block_device *bdev, int flag)
{
u32 *p = &bdev->__bd_flags;
u32 c, old;
c = *p;
while ((old = cmpxchg(p, c, c | (1 << (flag + 8)))) != c)
c = old;
}
to keep it closer to e.g. generic_atomic_or() and its ilk (asm-generic/atomic.h)
or any number of similar places.
FWIW, we could go for atomic_t there and use
atomic_read() & 0xff
for partno, with atomic_or()/atomic_and() for set/clear and
atomic_read() & constant for test. That might slightly optimize
set/clear on some architectures, but setting/clearing flags is
nowhere near hot enough for that to make a difference.
> 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.
The problem is not the total size, though - it's blowing the first
cacheline. With struct device shoved into that thing, a word or two
in total size is noise; keeping the fields read on the hot paths within
the first 64 bytes is not.
next prev parent reply other threads:[~2024-04-29 7:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-28 5:12 [PATCHES][RFC] packing struct block_device flags Al Viro
2024-04-28 5:14 ` [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Al Viro
2024-04-29 5:19 ` Christoph Hellwig
2024-04-28 5:15 ` [PATCH 2/8] wrapper for access to ->bd_partno Al Viro
2024-04-28 5:16 ` [PATCH 3/8] bdev: infrastructure for flags Al Viro
2024-04-28 5:17 ` [PATCH 4/8] bdev: move ->bd_read_only to ->__bd_flags Al Viro
2024-04-28 5:18 ` [PATCH 5/8] bdev: move ->bd_write_holder into ->__bd_flags Al Viro
2024-04-28 5:19 ` [PATCH 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Al Viro
2024-04-28 5:19 ` [PATCH 7/8] bdev: move ->bd_ro_warned " Al Viro
2024-04-28 5:21 ` [PATCH 8/8] bdev: move ->bd_make_it_fail " Al Viro
2024-04-29 5:23 ` [PATCHES][RFC] packing struct block_device flags Christoph Hellwig
2024-04-29 7:31 ` Al Viro [this message]
2024-04-29 17:02 ` Al Viro
2024-04-29 18:13 ` Al Viro
2024-04-29 18:30 ` Al Viro
2024-05-03 0:06 ` Al Viro
2024-05-03 0:07 ` [PATCH 1/8] Use bdev_is_paritition() instead of open-coding it Al Viro
2024-05-03 0:07 ` [PATCH 2/8] wrapper for access to ->bd_partno Al Viro
2024-05-03 0:08 ` [PATCH v2 3/8] bdev: infrastructure for flags Al Viro
2024-05-03 0:09 ` [PATCH v2 4/8] bdev: move ->bd_read_only to ->__bd_flags Al Viro
2024-05-03 0:09 ` [PATCH v2 5/8] bdev: move ->bd_write_holder into ->__bd_flags Al Viro
2024-05-03 0:10 ` [PATCH v2 6/8] bdev: move ->bd_has_subit_bio to ->__bd_flags Al Viro
2024-05-03 0:10 ` [PATCH v2 7/8] bdev: move ->bd_ro_warned " Al Viro
2024-05-03 0:11 ` [PATCH v2 8/8] bdev: move ->bd_make_it_fail " Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240429073107.GZ2118490@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=yukuai1@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.