From: Jeff Layton <jlayton@kernel.org>
To: dsterba@suse.cz
Cc: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com
Subject: Re: [PATCH v3 1/6] btrfs: use an on-stack path in btrfs_insert_orphan_item()
Date: Thu, 20 Aug 2026 08:49:52 -0400 [thread overview]
Message-ID: <e69401476a5241e73d3f81c5cf74229bfc31a044.camel@kernel.org> (raw)
In-Reply-To: <20260820120428.GA9053@suse.cz>
On Thu, 2026-08-20 at 14:04 +0200, David Sterba wrote:
> On Tue, Aug 11, 2026 at 02:14:54PM -0400, Jeff Layton wrote:
> > btrfs_insert_orphan_item() allocated a btrfs_path with btrfs_alloc_path()
> > which returns -ENOMEM on failure. It is called from btrfs_orphan_add(),
> > so a path allocation failure there turns a recoverable error into a
> > transaction abort.
> >
> > btrfs_path is only ~112 bytes, so allocate it on the stack instead.
>
> 112 is too much for on-stack, we've avoided that for btrfs_path in
> particular, except some justified cases. This means in general the
> beginning of call stack like ioctl, syscall handler and such. Otherwise
> we assume there are other layers in the IO stack, like block device
> drivers (DM), NFS, encoding layers or networking (iscsi), and obviously
> the lowest level device drivers.
>
> The trade off with possible allocation failure vs stack consumption
> needs to be argued in the changelog, "is just 112" is not sufficient.
>
> Getting back the consumed stack space is painful, we've been reducing
> unneeded or redundant parameters of functions for years. The gains are
> like -8 bytes here and -8 bytes there, allocation of +112 wipes that out.
>
> If the place of allocation is critical we can consider that but we have
> too many of them, anywhere during the transaction commit path or
> irreversible metadata changes. Possibly using __GFP_HIGH could work, but
> I haven't explored that.
>
> Qu added the patches to for-next but I had no chance to look closely at
> this patchset yet and am hesitant to leave it like that.
Fair critique. These days I think we're mostly ~16k stacks, but it can
certainly get deep given the right layering.
In this case, failing this allocation can lead to aborting the fs, so
it seemed justified. This is a GFP_NOFS allocation too, so it can
easily fail, even though it's small.
Qu suggested this approach in an earlier review pass, so I'd be
interested to hear his take on this too.
Thanks for taking a look!
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-08-20 12:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 18:14 [PATCH v3 0/6] btrfs: handle -ENOMEM errors in some synchronous dirops without aborting Jeff Layton
2026-08-11 18:14 ` [PATCH v3 1/6] btrfs: use an on-stack path in btrfs_insert_orphan_item() Jeff Layton
2026-08-20 12:04 ` David Sterba
2026-08-20 12:49 ` Jeff Layton [this message]
2026-08-11 18:14 ` [PATCH v3 2/6] btrfs: use an on-stack path in btrfs_del_orphan_item() Jeff Layton
2026-08-11 18:14 ` [PATCH v3 3/6] btrfs: split btrfs_insert_delayed_dir_index() into prealloc and commit phases Jeff Layton
2026-08-11 18:14 ` [PATCH v3 4/6] btrfs: pre-allocate delayed dir index before btree modification Jeff Layton
2026-08-11 18:14 ` [PATCH v3 5/6] btrfs: handle ENOMEM from btrfs_insert_dir_item() without aborting Jeff Layton
2026-08-11 18:14 ` [PATCH v3 6/6] btrfs: pre-allocate delayed dir index for non-overwrite rename Jeff Layton
2026-08-12 23:22 ` [PATCH v3 0/6] btrfs: handle -ENOMEM errors in some synchronous dirops without aborting Qu Wenruo
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=e69401476a5241e73d3f81c5cf74229bfc31a044.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 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.