Skip to contentSkip to conversation

rootfs: rootflags take effect when mount rootfs

PATCH New Weilong Chen 1 participant 1 message Jun 30, 2021 VFS

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rootfs: rootflags take effect when mount rootfs

The kernel root filesystem may use the rootflags parameters when mount, especially for tmpfs, to setup a variety of features.

For example:
1. Add 'rootflags=huge=always' to boot args.
2. When the OS bootup:
rootfs on / type rootfs (..., huge=always)
Then we can get the hugepage performance improvement of tmpfs.

Usage:
Relevant documents (Documentation/admin-guide/kernel-parameters.txt) description:
rootflags= [KNL] Set root filesystem mount option string

---
 fs/namespace.c       | 5 +++--
 include/linux/init.h | 2 +-
 init/do_mounts.c     | 4 +++-
 3 files changed, 7 insertions(+), 4 deletions(-)
fs/namespace.c +3 -2
index c3f1a78ba369..318ad4fbc20b 100644
@@ -4184,6 +4184,7 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
 	return err;
 }
 
+static char * __initdata rootfs_flags;
 static void __init init_mount_tree(void)
 {
 	struct vfsmount *mnt;
@@ -4191,7 +4192,7 @@ static void __init init_mount_tree(void)
 	struct mnt_namespace *ns;
 	struct path root;
 
-	mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL);
+	mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", rootfs_flags);
 	if (IS_ERR(mnt))
 		panic("Can't create rootfs");
 
@@ -4245,7 +4246,7 @@ void __init mnt_init(void)
 	if (!fs_kobj)
 		printk(KERN_WARNING "%s: kobj create error\n", __func__);
 	shmem_init();
-	init_rootfs();
+	init_rootfs(&rootfs_flags);
 	init_mount_tree();
 }
 
include/linux/init.h +1 -1
index d82b4b2e1d25..d8d46d3c73fb 100644
@@ -148,7 +148,7 @@ extern unsigned int reset_devices;
 /* used by init/main.c */
 void setup_arch(char **);
 void prepare_namespace(void);
-void __init init_rootfs(void);
+void __init init_rootfs(char **rootfs_flags);
 extern struct file_system_type rootfs_fs_type;
 
 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
init/do_mounts.c +3 -1
index a78e44ee6adb..42019b5fbf45 100644
@@ -632,9 +632,11 @@ struct file_system_type rootfs_fs_type = {
 	.kill_sb	= kill_litter_super,
 };
 
-void __init init_rootfs(void)
+void __init init_rootfs(char **rootfs_flags)
 {
 	if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
 		(!root_fs_names || strstr(root_fs_names, "tmpfs")))
 		is_tmpfs = true;
+
+	*rootfs_flags = root_mount_data;
 }
Signature · 1 line
2.31.GIT