Skip to content

fs: give the file system globals per-CPU storage for BMP - #22719

Open
zhaoxingyu12 wants to merge 5 commits into
apache:masterfrom
zhaoxingyu12:bmp
Open

zhaoxingyu12 wants to merge 5 commits into
apache:masterfrom
zhaoxingyu12:bmp

Conversation

@zhaoxingyu12

Copy link
Copy Markdown
Contributor

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

nsh> ls /
/:
 bin/
 data/
 dev/
 etc/
 proc/
 tmp/
nsh> ls /dev
/dev:
 console
 gpio0
 gpio1
 gpio2
 gpio3
 loop
 null
 oneshot
 ram0
 ram1
 ram2
 rtc0
 zero
nsh> ls /proc
/proc:
 0/
 1/
 2/
 4/
 7/
 cpuinfo
 fs/
 memdump
 meminfo
 mempool
 self/
 tcbinfo
 uptime
 version
nsh> cat /proc/meminfo
      total       used       free    maxused    maxfree  nused  nfree name
   67108856    1859224   65249632    1859920   65190032    106      3 Umem
nsh> mkdir /t1
nsh> mkdir /t1/t2
nsh> ls /t1
/t1:
 t2/
nsh> rmdir /t1/t2
nsh> rmdir /t1
nsh> ls /
/:
 bin/
 data/
 dev/
 etc/
 proc/
 tmp/
nsh> mount
  /bin type binfs
  /data type hostfs
  /etc type romfs
  /proc type procfs
  /tmp type vfat

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.

jasonbu and others added 5 commits December 2, 2026 15:19
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 zhaoxingyu12 changed the title Bmp fs: give the file system globals per-CPU storage for BMP Dec 2, 2026
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants