public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Daniel Vacek <neelx@suse.com>,
	dsterba@suse.cz, Filipe Manana <fdmanana@kernel.org>,
	Qu Wenruo <wqu@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v3 1/4] btrfs: make sure all ordered extents beyond EOF is properly truncated
Date: Mon, 24 Nov 2025 23:25:06 +0100	[thread overview]
Message-ID: <20251124222506.GS13846@twin.jikos.cz> (raw)
In-Reply-To: <58e0b0e5-c72c-43de-a1ec-b9d85a71bbdf@gmx.com>

On Sat, Nov 22, 2025 at 07:16:06AM +1030, Qu Wenruo wrote:
> 在 2025/11/22 06:55, Daniel Vacek 写道:
> > On Fri, 21 Nov 2025 at 20:28, Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
> >> 在 2025/11/22 02:08, David Sterba 写道:
> >>> On Fri, Nov 21, 2025 at 11:55:58AM +0000, Filipe Manana wrote:
> >>>>> +               /*
> >>>>> +                * We have just run delalloc before getting here, so there must
> >>>>> +                * be an ordered extent.
> >>>>> +                */
> >>>>> +               ASSERT(ordered != NULL);
> >>>>> +               scoped_guard(spinlock, &inode->ordered_tree_lock) {
> >>>>> +                       set_bit(BTRFS_ORDERED_TRUNCATED, &ordered->flags);
> >>>>> +                       ordered->truncated_len = min(ordered->truncated_len,
> >>>>> +                                                    cur - ordered->file_offset);
> >>>>> +               }
> >>>>
> >>>> I thought we had not made a decision yet to not use this new fancy locking yet.
> >>>> In this case where it's a very short critical section, it doesn't
> >>>> bring any advantage over using explicit spin_lock/unlock, and adds one
> >>>> extra level of indentation.
> >>>
> >>> Agreed, this looks like an anti-pattern of the scoped locking.
> >>>
> >>
> >> I think one is free to use whatever style as long as there is no mixed
> >> style in the same function.
> > 
> > I've got a hard objection here. If there is(?) any granularity using
> > guards vs. explicit locking then, IMO, it should be per given lock.
> > 
> > Ie, given `ordered_tree_lock` - either it should always use the RAII
> > style *OR* it should always use the explicit style. But it should
> > never mix one style in one function and the other style in another
> > function. That would only make it really messy looking for
> > interactions and race bugs / missing/misplaced locking - simply
> > general debugging.
> 
> Then check fs/*.c.
> 
> There are guard(rcu) and rcu_read_lock() usage mixed in different files.
> 
> E.g. in fs/namespace.c it's using guard(rcu) and scoped_guard(rcu), 
> meanwhile still having regular rcu_read_lock().
> 
> There are more counter-examples than you know.
> We're not the first subsystem to face the new RAII styles, and I hope we 
> will not be the last either.

We take inspiration from other subsystems but that some coding style is
done in another subsystem does not mean we have to do that too. If
fs/*.c people decide to use it everywhere then so be it.

I was hesitant to introduce the auto cleaning for btrfs_path or kfree
but so far I found it working. The locking guards are quite different to
that and I don't seem to get any liking in it

> [...]
> >>
> >> I'm not saying we should change to the new RAII style immediately with a
> >> huge patch nor everyone should accept it immediately, but to gradually
> >> use the new style in new codes, with the usual proper review/testing
> >> procedures to keep the correctness.
> > 
> > I would understand if you introduced a _new_ lock and started using it
> > with the RAII style - setting the example. But if you're grabbing a
> > lock which is always acquired using the explicit style, just stick to
> > it and keep the style consistent throughout all the callsites, the
> > whole code base. This makes it _easier_ to crosscheck, IMO.
> 
> Then check kernfs_root::kernfs_rwsem, it also has mixed RAII and old styles.
> 
> We should all remember there are always subsystems before us facing this 
> challenge, and if they are fine embrace the new style gradually, I see 
> no reason why we can not.
> 
> We're just a regular subsystem in the kernel, not some god-chosen 
> special one, we do not live in a bubble.

Honestly, this is a weird argument to make. There are local coding
styles that are their own bubbles, look at net/* with their own special
commenting style and mandatory reverse xmass tree sort of variables (I
think that one has been adopted by other subsystems too). Contributing to
those subsystems means following their style. If you want an example
of a filesystem with unique code formatting style then go no further
than XFS.

I think we've been doing fine in btrfs with the style consistency and
incremental updates of old code when possible. This means we have fewer
choices for personal "creative expression" how the code is written but
in the long run it makes the code look better.

The problem with the guards is that there's no one good way for their
general use, i.e. the problem of mixing with explicit lock/unlock,
trylock, unlock/lock order, etc. Allowing both styles will lead to
inconsistent style based on personal preferences again.

As said on slack, we'll get to a conclusion.

  reply	other threads:[~2025-11-24 22:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20  9:16 [PATCH v3 0/4] btrfs: reduce btrfs_get_extent() calls for buffered write path Qu Wenruo
2025-11-20  9:16 ` [PATCH v3 1/4] btrfs: make sure all ordered extents beyond EOF is properly truncated Qu Wenruo
2025-11-21 11:55   ` Filipe Manana
2025-11-21 15:38     ` David Sterba
2025-11-21 19:26       ` Qu Wenruo
2025-11-21 20:25         ` Daniel Vacek
2025-11-21 20:46           ` Qu Wenruo
2025-11-24 22:25             ` David Sterba [this message]
2025-11-24 23:16               ` Qu Wenruo
2025-11-22  1:14     ` Qu Wenruo
2025-11-24 12:22       ` Filipe Manana
2025-11-24 21:00         ` Qu Wenruo
2025-11-20  9:16 ` [PATCH v3 2/4] btrfs: integrate the error handling of submit_one_sector() Qu Wenruo
2025-11-20  9:16 ` [PATCH v3 3/4] btrfs: replace for_each_set_bit() with for_each_set_bitmap() Qu Wenruo
2025-11-20  9:16 ` [PATCH v3 4/4] btrfs: reduce extent map lookup during writes Qu Wenruo
2025-11-21  1:02 ` [PATCH v3 0/4] btrfs: reduce btrfs_get_extent() calls for buffered write path Boris Burkov

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=20251124222506.GS13846@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=neelx@suse.com \
    --cc=quwenruo.btrfs@gmx.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