From: Yiyang Chen <cyyzero16@gmail.com>
To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-trace-devel@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>
Subject: tracepoints expose s_dev of kernel-internal superblocks -- no generic resolution interface
Date: Mon, 1 Jun 2026 01:10:13 +0800 [thread overview]
Message-ID: <20260531171013.289131-1-cyyzero16@gmail.com> (raw)
Hi all,
While tracing page cache activity via mm_filemap_add_to_page_cache, I
noticed s_dev values that do not appear in /proc/*/mountinfo:
mm_filemap_add_to_page_cache: dev 0:18 ino dea89 pfn=0x13ba00 ofs=0 order=9
Using a kernel module to enumerate all active superblocks, I confirmed
this is the hugetlbfs internal mount created by hugetlbfs_init() ->
kern_mount(). The actual s_dev value is dynamically allocated via
get_anon_bdev() and varies across systems (0:18 on my test machine).
Because kern_mount() attaches the mount to MNT_NS_INTERNAL, it is
invisible to all mount namespaces.
Each internal filesystem requires its own trick to discover the
s_dev -> fs_type mapping:
- shmem: create a memfd, call fstatfs() -> TMPFS_MAGIC
- bdev: open a block device, call fstatfs()
- hugetlbfs: memfd_create(MFD_HUGETLB) creates a file
on the internal mount itself, so fstat() gives s_dev and
fstatfs() returns HUGETLBFS_MAGIC
None of these are a general, authoritative interface -- each requires
filesystem-specific knowledge of which object to create and which
syscall to call.
The question is: should there be a single stable interface that exposes
the s_dev -> fs_type mapping for all active superblocks, including
internal ones? Here are some options:
- Add fs_type to the affected tracepoints.
- Provide a generic interface (BPF iterator, /proc, /sys) that
exposes s_dev + fs_type for all active superblocks including
internal ones.
Reproduce steps:
s_dev is dynamically allocated via get_anon_bdev(), values vary.
--- test_hugetlb_sdev.c ---
#include <sys/mman.h>
#include <string.h>
int main(void) {
void *p = mmap(NULL, 2<<20, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0);
if (p == MAP_FAILED) return 1;
memset(p, 0, 2<<20);
munmap(p, 2<<20);
return 0;
}
gcc -o test_hugetlb_sdev test_hugetlb_sdev.c
# precondition:
cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages # must be > 0
--- trace script (run with sudo) ---
TP=/sys/kernel/tracing
DEVS=$(awk '{print $3}' /proc/self/mountinfo | sort -u)
echo 1 > $TP/events/filemap/mm_filemap_add_to_page_cache/enable
echo 1 > $TP/events/hugetlbfs/hugetlbfs_alloc_inode/enable
echo > $TP/trace
./test_hugetlb_sdev
sleep 1
echo "=== s_dev from tracepoint, NOT in mountinfo ==="
# filemap uses "dev X:Y", hugetlbfs uses "dev X,Y"
grep -v '^#' $TP/trace | grep -oP 'dev[= ]\K\d+[:,]\d+' | tr ',' ':' | sort -u \
| while read d; do echo "$DEVS" | grep -qx "$d" || echo " $d"; done
echo 0 > $TP/events/filemap/enable
echo 0 > $TP/events/hugetlbfs/enable
echo > $TP/trace
You will see hugetlbfs s_dev which is not present in any mountinfo.
Thanks.
reply other threads:[~2026-05-31 17:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260531171013.289131-1-cyyzero16@gmail.com \
--to=cyyzero16@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=willy@infradead.org \
/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