From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796418646; b=rf+XFy9O13AA4g6I9FseKKkqElvHWo5pKt/WpNIY6/EQB+Q/EubG/mD8TAyU9fn0T/BU zHyHaqADObYU7CfQdHw0hqBG0jX5b4sQbr/ZL7KgkW/B2G/CUBhLfJ0Fdr8I4ikp4TF0j Mne2wOM+cO3IL0i4VacURJo9aPIuz+rG1sjk2UFl8lryJwNRXY6H0Atgsh5OM4vou3LRO Cw3zEqU6+9HHfep4DEX5JFvN5TnpLgQ+Rw+q/+vAqFZukbAMgsMpKrx2CGDxh41ijNK+z w4zAEzxi3CAm/bp2RjxTnGBXxiMj2P17cuMSne/faC9Qgu7tzI28JY18ckhyiWz42pQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796418646; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=NkKMkIc2fWoW3pS2FmPAgQ0poMAohrp+CnpXzkYv7i0=; b=nRxDoRJjhtNNhNNaR3LOzSa8RmgwUkZJLaFhTpht4DFZ8eMLy5OTD2GnG7ZOHBrkDnDS ADWHLJZTI33GrisaaCMhg+obH3crmY3LEtf+KZArURCBD1NF/3YypD6ABWrMh2iYeo3dk wOS/ILzgPyrNgzaqxffxuN2L6tFfLONxFxIYRr7VDfvHL4CcjZPm/FW2OOHtxu0oHEMId y4rdI49SPMrsALTS7fNCR6vvEkOz8eckimzJ5n2BMNhgUVYeiWPxTWsTuTtI/y5c3vd66 smWoUBtpGqIeffMR/h3m96BvZsNtZ3ySrIWN8AWwkOKUUUjRjkXt8UNm0kTEhDJ5r2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=JGPW0jO4; arc=none smtp.remote-ip=91.218.175.46 Received: from mta0.migadu.com (out-46.mta0.migadu.com [91.218.175.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C6B6606A330 for ; Fri, 4 Dec 2026 21:10:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C6B6606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=JGPW0jO4 X-Envelope-To: linux-fsdevel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=DhRRFdiflMPrb/8WU/IKoo/0dzYMAoA5jw+r2yQ5JIk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796418643; v=1; x=1797023443; b=JGPW0jO4zIhYzV+Wuj+eQlTLT5/H6JPKswhZJ8yfk1KwITwAepbxEFF/zXqu5NJOn/j/LsiY Dm1CoXBSnU9fQ0FftOjUOg6bahluSDR1cjw+NEcrQ1kXfzXuCuqLXt/34k1NWN2hCKzluBZypm5 fAKUbwCfBFqxBnrhyi9oNa9g= X-Envelope-To: linux-fsdevel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 295d4b526ee4b2f7; Fri, 04 Dec 2026 21:10:41 +0000 X-Mizu-Trace-ID: 295d4b526ee4b2f7 X-Migadu-Flow: FLOW_OUT From: Shakeel Butt To: Christian Brauner Cc: Greg Kroah-Hartman , Tejun Heo , Andrew Morton , Ian Kent , Jori Koolstra , "T . J . Mercier" , Meta kernel team , 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 Message-ID: <20261204211034.3436390-1-shakeel.butt@linux.dev> X-Mailer: git-send-email 2.53.1 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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