linux-bcachefs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Joshua Ashton <joshua@froggi.es>
Cc: linux-bcachefs@vger.kernel.org
Subject: Re: [PATCH 2/4] bcachefs: Optimize bch2_dirent_name_bytes
Date: Sat, 12 Aug 2023 12:23:30 -0400	[thread overview]
Message-ID: <20230812162330.6i6jybtasalh3asw@moria.home.lan> (raw)
In-Reply-To: <20230812145017.259609-2-joshua@froggi.es>

On Sat, Aug 12, 2023 at 03:47:46PM +0100, Joshua Ashton wrote:
> Avoids doing a full strnlen for getting the length of the name of a
> dirent entry.
> 
> Given the fact that the name of dirents is stored at the end of the
> bkey's value, and we know the length of that in u64s, we can find the
> last u64 and figure out how many NUL bytes are at the end of the string.
> 
> On little endian systems this ends up being the leading zeros of the
> last u64, whereas on big endian systems this ends up being the trailing
> zeros of the last u64.
> We can take that value in bits and divide it by 8 to get the number of
> NUL bytes at the end.
> 
> There is no endian-fixup or other compatibility here as this is string
> data interpreted as a u64.

This needs a bit more analysis:

If we ever screwed up and created dirents where there was a nul before
the last u64, this is going to change how those dirents are interpreted
- we'll now be returning longer dirents, but with an embedded nul.

Fortunately, bch2_dirent_invalid() checks for this, so we're good there.

But, your change does break the check in bch2_dirent_invalid(); we still
do need to check somehow that there aren't any embedded nuls. Can you
fix that too?

  reply	other threads:[~2023-08-12 16:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-12 14:47 [PATCH 1/4] bcachefs: Add btree_trans* to inode_set_fn Joshua Ashton
2023-08-12 14:47 ` [PATCH 2/4] bcachefs: Optimize bch2_dirent_name_bytes Joshua Ashton
2023-08-12 16:23   ` Kent Overstreet [this message]
2023-08-12 17:09     ` Joshua Ashton
2023-08-12 14:47 ` [PATCH 3/4] bcachefs: Introduce bch2_dirent_get_name Joshua Ashton
2023-08-12 14:47 ` [PATCH 4/4] bcachefs: Implement casefolding Joshua Ashton
2023-08-12 22:44   ` Kent Overstreet
2023-08-12 16:17 ` [PATCH 1/4] bcachefs: Add btree_trans* to inode_set_fn Kent Overstreet

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=20230812162330.6i6jybtasalh3asw@moria.home.lan \
    --to=kent.overstreet@linux.dev \
    --cc=joshua@froggi.es \
    --cc=linux-bcachefs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).