Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Christian Brauner <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ian Kent <raven@themaw.net>, Jori Koolstra <jkoolstra@xs4all.nl>,
	"T . J . Mercier" <tjmercier@google.com>,
	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: [PATCH 0/3] kernfs: list directories without kernfs_rwsem
Date: Fri,  4 Dec 2026 13:10:29 -0800	[thread overview]
Message-ID: <20261204211034.3436390-1-shakeel.butt@linux.dev> (raw)

kernfs_fop_readdir() takes kernfs_rwsem for reading for each entry, and
there is one kernfs_rwsem for the whole hierarchy.  So a listing of any
cgroup directory waits whenever a writer anywhere in cgroupfs holds the
lock or waits for it, for example a mkdir that is preempted with the
lock held.  Monitors such as oomd and below list cgroup directories all
the time.  In a week of data from our 6.16 fleet, on 92% of the hosts
where oomd or below got stuck in a kernfs read, it was in
kernfs_fop_readdir().

This series lets readdir run under RCU with a sequence count in each
directory.  Writers keep kernfs_rwsem, and a listing step falls back to
it only if the directory keeps changing under it.

It is one step toward kernfs readers that never wait for writers.
Andrew is working on another: keeping kernfs path walks in RCU walk,
with lockless permission checks.  The two do not depend on each other
and apply together.

Patch 1 fixes a type confusion in kernfs_drain() that patch 2's layout
change would otherwise turn into an oops on lockdep kernels.  Patch 2
adds the sequence count.  Patch 3 lists without the lock.

In a 16 CPU VM, with 8 tasks listing cgroup directories of 36 entries
(ranges over two or three runs):

                                           before         after
  with a SCHED_IDLE mkdir/rmdir loop sharing a CPU with a busy loop:
    slowest listing                    205-271 ms     0.19-0.86 ms
    listings per second                  48k-51k     1.26M-1.28M
  with 4 mkdir/rmdir loops:
    listings per second                  96k-98k     1.26M-1.27M
    mkdir+rmdir pairs per second         280-285       7.2k-7.4k

15 tasks listing one directory with no writers went from 157k-172k to
549k-690k listings per second.  Listing /sys/class/net in the root
namespace, which skips 1000 devices in other namespaces, went from
20k-21k to 29k-30k per second.

Tested with the kernfs and cgroup selftests, and with listings checked
for missing and repeated entries while cgroup files, cgroups and network
devices are added, removed, renamed and moved between network
namespaces, on lockdep, KASAN and KCSAN kernels, and on a kernel that
takes the fallback for every step.  Listings of a few sysfs and cgroupfs
directories are the same, in the same order, before and after.

The series is on vfs-7.5.kernfs.

Shakeel Butt (3):
  kernfs: don't look for open files of directories when draining
  kernfs: add a sequence count to directories
  kernfs: list directories without kernfs_rwsem

 fs/kernfs/dir.c             | 304 ++++++++++++++++++++++++------------
 fs/kernfs/file.c            |   7 +
 fs/kernfs/kernfs-internal.h |  27 ++++
 include/linux/kernfs.h      |   9 +-
 4 files changed, 242 insertions(+), 105 deletions(-)


base-commit: 8900b8b7e0d8b3b754f547ea31bed1a8f6e4814a
-- 
2.53.1-Meta


             reply	other threads:[~2026-12-04 21:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:10 Shakeel Butt [this message]
2026-12-04 21:10 ` [PATCH 1/3] kernfs: don't look for open files of directories when draining Shakeel Butt
2026-12-04 21:10 ` [PATCH 2/3] kernfs: add a sequence count to directories Shakeel Butt
2026-12-04 21:10 ` [PATCH 3/3] kernfs: list directories without kernfs_rwsem Shakeel Butt

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=20261204211034.3436390-1-shakeel.butt@linux.dev \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.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=raven@themaw.net \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.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