Repository navigation
fs: give the file system globals per-CPU storage for BMP - #22719
Open
zhaoxingyu12 wants to merge 5 commits into
Open
zhaoxingyu12 wants to merge 5 commits into
zhaoxingyu12 wants to merge 5 commits into
Conversation
Under CONFIG_BMP each CPU runs its own kernel image with its own file system namespace. One shared instance of the VFS state is wrong there: two images would hand out inode numbers from the same counter, share one root inode and serialise on one inode tree lock. Convert the core globals to the per-CPU BMP accessors: g_root_inode, g_root_inode_storage root of the pseudo file system g_ino inode number allocator g_inode_lock inode tree lock g_dir_inode stand-in inode of a directory fd g_fs_reboot_nb reboot notifier block g_procfs_meminfo procfs meminfo entry list g_file_lock_table, g_protect_lock file lock hash table DEFINE_PER_CPU_BMP() and this_cpu_var_bmp() expand to the plain variable when CONFIG_BMP is off, so nothing changes for any other build. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
epoll, eventfd, signalfd, timerfd and inotify each keep one static struct inode that stands in for every descriptor of that type, and inotify also keeps one global instance list. Under CONFIG_BMP the kernel images of different CPUs must not share them, or both images would update one reference count and one inotify device list. Convert them to the per-CPU BMP accessors: g_epoll_inode, g_eventfd_inode, g_signalfd_inode, g_timerfd_inode, g_inotify_inode and g_inotify. No change when CONFIG_BMP is off. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
g_sock_inode is the single static inode that every socket descriptor points at. Under CONFIG_BMP the kernel images of different CPUs would share it and its reference count. Convert it to the per-CPU BMP accessors. No change when CONFIG_BMP is off. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
With CONFIG_FS_PROCFS_REGISTER the procfs entry table lives in the heap: procfs_initialize() allocates g_procfs_entries from the fixed base entries, and procfs_register() reallocates it and bumps g_procfs_entrycount. Under CONFIG_BMP the kernel images of different CPUs registered into that one table, and the boot asserted. Convert both to the per-CPU BMP accessors. No change when CONFIG_BMP is off. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
unique_devname() builds the /dev/tmp* name of a temporary block or MTD proxy device from g_devno, under g_devno_lock. Under CONFIG_BMP the kernel images of different CPUs shared the counter, so two images could pick the same name for two different proxy devices. Convert both to the per-CPU BMP accessors. No change when CONFIG_BMP is off. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
zhaoxingyu12
requested review from
jerpelea,
pkarashchenko,
xiaoxiang781216 and
yamt
as code owners
December 2, 2026 08:46
|
GUIDINGLI
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
Under CONFIG_BMP each CPU runs its own kernel image with its own file system namespace, but the fs/ globals were still single shared instances. Two images would hand out inode numbers from the same counter, share one root inode, serialise on one inode tree lock, register into one procfs entry table and pick proxy device names from one counter.
This series converts the fs/ globals to the per-CPU BMP accessors, in five steps:
fs: the core VFS state — g_root_inode, g_root_inode_storage, g_ino, g_inode_lock, g_dir_inode, g_fs_reboot_nb, g_procfs_meminfo, g_file_lock_table, g_protect_lock
fs/vfs: the stand-in inodes of the anonymous objects — g_epoll_inode, g_eventfd_inode, g_signalfd_inode, g_timerfd_inode, g_inotify_inode, g_inotify
fs/socket: g_sock_inode
fs/procfs: the run-time entry table — g_procfs_entries, g_procfs_entrycount
fs/driver: the proxy device number allocator — g_devno, g_devno_lock
DEFINE_PER_CPU_BMP(), DEFINE_PER_CPU_BSS_BMP() and this_cpu_var_bmp() come from
percpu.h
and expand to the plain variable when CONFIG_BMP is off. The same mechanism is already used in 83 files outside fs/ (42 in drivers/, 30 in sched/, 4 in net/, 2 in mm/), so fs/ was the remaining gap.
Impact
CONFIG_BMP=y: the listed globals get one instance per CPU, in the .percpu_data / .percpu_bss sections.
CONFIG_BMP=n, which is every existing configuration: no functional change and no size change. rv-virt:nsh is byte-identical before and after (see Testing).
No change to any public API, Kconfig option or documentation.
fs.py
and mm.py read g_root_inode and g_procfs_meminfo. With CONFIG_BMP=y these become per-CPU section symbols, the same as the already-converted sched/ and mm/ globals, so the scripts have the same limitation there as they do today for those subsystems. They are unaffected with CONFIG_BMP=n.
Testing
OSTest, sim:nsh
ostest_main: Exiting with status 0
1140 lines of log, no failed assertion. Groups run: barrier, cancel, flockfile, libc, mutex, nxevent, pthread_rwlock, pthread_rwlock_cancel, pthread_sigqueue, robust, semaphore, setjmp, setvbuf, sigprocmask, spinlock, task_restart, waitpid, wdog, wqueue.