Linux filesystem development
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Christian Brauner <brauner@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jori Koolstra <jkoolstra@xs4all.nl>,
	Meta kernel team <kernel-team@meta.com>,
	cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernfs: allocate in open before taking the active reference
Date: Thu, 19 Nov 2026 21:11:52 -1000	[thread overview]
Message-ID: <e64643aed76382fd9adc3b616cb76948@kernel.org> (raw)
In-Reply-To: <20261119191923.2223993-1-shakeel.butt@linux.dev>

On Thu, Nov 19, 2026 at 11:19:22AM -0800, Shakeel Butt wrote:
> kernfs_fop_open() allocates the open file, its seq_file and the open
> node while holding the file's active reference.  The seq_file is
> charged to the opener's memory cgroup, so in a cgroup at its limit the
> allocation reclaims.  Removing the file waits for active references.
> cgroup rmdir does that with cgroup_mutex held, so every cgroup
> operation on the host waits for that reclaim.  Deleting a netdev waits
> the same way with rtnl_lock held.
>
> Allocate them before taking the active reference.  kn->flags already
> says whether the file has ->seq_show, which is all seq_open() needs.
> If the file is removed in the meantime, open fails with -ENODEV as
> before.  Only the prealloc buffer, whose size comes from the ops, and
> ->open() still allocate under the active reference.
>
> In a VM, eight tasks in a 256 MB memory cgroup at its limit, with swap
> writes taking 500 ms, open and read small files of a cgroup that
> another task removes and recreates every 20 ms (60 s, worst of four
> runs):
>
>                                            before    after
>   reclaim with an active reference held     5.0 s        0
>   rmdir waiting for it, cgroup_mutex held  377 ms   6.3 ms
>   mkdir/rmdir of other cgroups             382 ms   125 ms
>
> The rest of the mkdir/rmdir time is waiting for kernfs_rwsem.  Opening
> and closing cgroup files in a loop is as fast as before.
>
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

--
tejun

      reply	other threads:[~2026-11-20  7:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:19 [PATCH] kernfs: allocate in open before taking the active reference Shakeel Butt
2026-11-20  7:11 ` Tejun Heo [this message]

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=e64643aed76382fd9adc3b616cb76948@kernel.org \
    --to=tj@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkoolstra@xs4all.nl \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shakeel.butt@linux.dev \
    /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