mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Daniel Vacek <neelx@suse.com>, Qu Wenruo <wqu@suse.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>, Nick Terrell <terrelln@fb.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: zstd: add `zstd-fast` alias mount option for fast modes
Date: Tue, 1 Apr 2025 07:44:01 +1030	[thread overview]
Message-ID: <b1437d32-8c85-4e5d-9c68-76938dcf6573@gmx.com> (raw)
In-Reply-To: <CAPjX3Fdru3v6vezwzgSgkBcQ28uYvjsEquWHBHPFGNFOE8arjQ@mail.gmail.com>



在 2025/3/31 20:36, Daniel Vacek 写道:
[...]
>>>                        btrfs_set_opt(ctx->mount_opt, COMPRESS);
>>>                        btrfs_clear_opt(ctx->mount_opt, NODATACOW);
>>>                        btrfs_clear_opt(ctx->mount_opt, NODATASUM);
>>> +             } else if (strncmp(param->string, "zstd-fast", 9) == 0) {
>>> +                     ctx->compress_type = BTRFS_COMPRESS_ZSTD;
>>> +                     ctx->compress_level =
>>> +                             -btrfs_compress_str2level(BTRFS_COMPRESS_ZSTD,
>>> +                                                       param->string + 9
>>
>> Can we just use some temporary variable to save the return value of
>> btrfs_compress_str2level()?
>
> I don't see any added value. Isn't `ctx->compress_level` temporary
> enough at this point? Note that the FS is not mounted yet so there's
> no other consumer of `ctx`.
>
> Or did you mean just for readability?

Doing all the same checks and flipping the sign of ctx->compress_level
is already cursed to me.

Isn't something like this easier to understand?

	level = btrfs_compress_str2level();
	if (level > 0)
		ctx->compress_level = -level;
	else
		ctx->compress_level = level;

>
>> );
>>> +                     if (ctx->compress_level > 0)
>>> +                             ctx->compress_level = -ctx->compress_level;
>>
>> This also means, if we pass something like "compress=zstd-fast:-9", it
>> will still set the level to the correct -9.
>>
>> Not some weird double negative, which is good.
>>
>> But I'm also wondering, should we even allow minus value for "zstd-fast".
>
> It was meant as a safety in a sense that `s/zstd:-/zstd-fast:-/` still
> works the same. Hence it defines that "fast level -3 <===> fast level
> 3" (which is still level -3 in internal zstd representation).
> So if you mounted `compress=zstd-fast:-9` it's understood you actually
> meant `compress=zstd-fast:9` in the same way as if you did
> `compress=zstd:-9`.
>
> I thought this was solid. Or would you rather bail out with -EINVAL?

I prefer to bail out with -EINVAL, but it's only my personal choice.

You'd better wait for feedbacks from other people.

Thanks,
Qu>
>>> +                     btrfs_set_opt(ctx->mount_opt, COMPRESS);
>>> +                     btrfs_clear_opt(ctx->mount_opt, NODATACOW);
>>> +                     btrfs_clear_opt(ctx->mount_opt, NODATASUM);
>>>                } else if (strncmp(param->string, "zstd", 4) == 0) {
>>>                        ctx->compress_type = BTRFS_COMPRESS_ZSTD;
>>>                        ctx->compress_level =
>>
>> Another thing is, if we want to prefer using zstd-fast:9 other than
>> zstd:-9, should we also change our compress handling in
>> btrfs_show_options() to show zstd-fast:9 instead?
>
> At this point it's not about preference but about compatibility. I
> actually tested changing this but as a side-effect it also had an
> influence on `btrfs.compression` xattr (our `compression` property)
> which is rather an incompatible on-disk format change. Hence I falled
> back keeping it simple. Showing `zstd:-9` is still a valid output.
>
> --nX
>
>> Thanks,
>> Qu
>


  reply	other threads:[~2025-03-31 21:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31  8:23 Daniel Vacek
2025-03-31  8:49 ` Qu Wenruo
2025-03-31 10:06   ` Daniel Vacek
2025-03-31 21:14     ` Qu Wenruo [this message]
2025-03-31 22:57       ` David Sterba
2025-04-02  8:37         ` Daniel Vacek
2025-04-02  9:08           ` Qu Wenruo
2025-04-02 10:29             ` Daniel Vacek
2025-04-02 14:31         ` Daniel Vacek
2025-04-14  6:53           ` Daniel Vacek
2025-04-15  3:50             ` Qu Wenruo
2025-04-15 14:58               ` Nick Terrell
2025-04-15 16:56               ` 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=b1437d32-8c85-4e5d-9c68-76938dcf6573@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neelx@suse.com \
    --cc=terrelln@fb.com \
    --cc=wqu@suse.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

all inboxes | Powered by JetHome®