From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 01/10] btrfs: use precalculated sectorsize_bits from fs_info
Date: Mon, 2 Nov 2020 16:15:51 +0100 [thread overview]
Message-ID: <20201102151551.GE6756@twin.jikos.cz> (raw)
In-Reply-To: <5d586f76-7cad-b7be-60d3-44c8d3b67623@gmx.com>
On Mon, Nov 02, 2020 at 10:05:54PM +0800, Qu Wenruo wrote:
> On 2020/10/29 下午10:27, David Sterba wrote:
> > We do a lot of calculations where we divide or multiply by sectorsize.
> > We also know and make sure that sectorsize is a power of two, so this
> > means all divisions can be turned to shifts and avoid eg. expensive
> > u64/u32 divisions.
> >
> > The type is u32 as it's more register friendly on x86_64 compared to u8
> > and the resulting assembly is smaller (movzbl vs movl).
> >
> > There's also superblock s_blocksize_bits but it's usually one more
> > pointer dereference farther than fs_info.
> >
> > Signed-off-by: David Sterba <dsterba@suse.com>
> > ---
> > fs/btrfs/ctree.h | 1 +
> > fs/btrfs/disk-io.c | 2 ++
> > fs/btrfs/extent-tree.c | 2 +-
> > fs/btrfs/file-item.c | 11 ++++++-----
> > fs/btrfs/free-space-tree.c | 12 +++++++-----
> > fs/btrfs/ordered-data.c | 3 +--
> > fs/btrfs/scrub.c | 12 ++++++------
> > fs/btrfs/tree-checker.c | 3 ++-
> > 8 files changed, 26 insertions(+), 20 deletions(-)
> >
> > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > index 8a83bce3225c..87c40cc5c42e 100644
> > --- a/fs/btrfs/ctree.h
> > +++ b/fs/btrfs/ctree.h
> > @@ -931,6 +931,7 @@ struct btrfs_fs_info {
> > /* Cached block sizes */
> > u32 nodesize;
> > u32 sectorsize;
> > + u32 sectorsize_bits;
>
> For the bit shift, it can alwasy be contained in one u8.
> Since one u32 is only to be at most 32 bits, it can be easily contained
> in u8 whose max value is 255.
>
> This should allow us to pack several u8 together to reduce some memory
> usage.
As mentioned in the changelog, u32 generates slightly better assembly.
The size increase is minimal compared to overall fs_info size so I'd
become worried once we have a lot of u32 in place of u8 that would span
more cachelines than necessary. Reorganizing fs_info for better
cacheline access patterns would be interesting but at the moment we
leave it up to the CPU.
next prev parent reply other threads:[~2020-11-02 15:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 14:27 [PATCH 00/10] Sectorsize, csum_size lifted to fs_info David Sterba
2020-10-29 14:27 ` [PATCH 01/10] btrfs: use precalculated sectorsize_bits from fs_info David Sterba
2020-11-02 14:05 ` Qu Wenruo
2020-11-02 14:18 ` Qu Wenruo
2020-11-02 14:31 ` Johannes Thumshirn
2020-11-02 15:08 ` David Sterba
2020-11-02 15:12 ` Johannes Thumshirn
2020-11-02 15:15 ` David Sterba [this message]
2020-11-03 9:31 ` David Sterba
2020-10-29 14:27 ` [PATCH 02/10] btrfs: replace div_u64 by shift in free_space_bitmap_size David Sterba
2020-11-02 14:07 ` Qu Wenruo
2020-10-29 14:27 ` [PATCH 03/10] btrfs: replace s_blocksize_bits with fs_info::sectorsize_bits David Sterba
2020-11-02 14:23 ` Qu Wenruo
2020-11-02 15:18 ` David Sterba
2020-10-29 14:27 ` [PATCH 04/10] btrfs: store precalculated csum_size in fs_info David Sterba
2020-10-29 14:27 ` [PATCH 05/10] btrfs: precalculate checksums per leaf once David Sterba
2020-11-02 14:27 ` Qu Wenruo
2020-11-02 15:24 ` David Sterba
2020-11-02 16:00 ` David Sterba
2020-10-29 14:27 ` [PATCH 06/10] btrfs: use cached value of fs_info::csum_size everywhere David Sterba
2020-11-02 14:28 ` Qu Wenruo
2020-10-29 14:27 ` [PATCH 07/10] btrfs: switch cached fs_info::csum_size from u16 to u32 David Sterba
2020-10-29 14:27 ` [PATCH 08/10] btrfs: remove unnecessary local variables for checksum size David Sterba
2020-10-29 14:43 ` Johannes Thumshirn
2020-10-29 14:27 ` [PATCH 09/10] btrfs: check integrity: remove local copy of csum_size David Sterba
2020-10-29 14:44 ` Johannes Thumshirn
2020-10-29 14:27 ` [PATCH 10/10] btrfs: scrub: remove local copy of csum_size from context David Sterba
2020-10-29 14:45 ` Johannes Thumshirn
2020-10-29 14:54 ` David Sterba
2020-10-29 15:01 ` Johannes Thumshirn
2020-10-29 14:50 ` [PATCH 00/10] Sectorsize, csum_size lifted to fs_info Johannes Thumshirn
2020-10-29 16:25 ` David Sterba
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=20201102151551.GE6756@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox