All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] Use tmpfs rather tham ramfs for rootfs when available
@ 2011-12-05 17:02 Andrew Walrond
  0 siblings, 0 replies; only message in thread
From: Andrew Walrond @ 2011-12-05 17:02 UTC (permalink / raw)
  To: linux-kernel

Make rootfs an instance of tmpfs instead of ramfs when tmpfs is available.

Documentation/filesystems/ramfs-rootfs-initramfs.txt says:
"Rootfs is a special instance of ramfs (or tmpfs, if that's enabled)"
but it has always been a lie, until now.

This patch is based upon one proposed by Bodo Eggert in 2008.
---
 fs/ramfs/inode.c |    6 ++++++
 mm/shmem.c       |   31 +++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 462ceb3..e8a5c7f 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -260,11 +260,13 @@ struct dentry *ramfs_mount(struct file_system_type *fs_type,
 	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
+#if !(defined CONFIG_SHMEM && defined CONFIG_TMPFS)
 static struct dentry *rootfs_mount(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data)
 {
 	return mount_nodev(fs_type, flags|MS_NOUSER, data, ramfs_fill_super);
 }
+#endif
 
 static void ramfs_kill_sb(struct super_block *sb)
 {
@@ -277,11 +279,13 @@ static struct file_system_type ramfs_fs_type = {
 	.mount		= ramfs_mount,
 	.kill_sb	= ramfs_kill_sb,
 };
+#if !(defined CONFIG_SHMEM && defined CONFIG_TMPFS)
 static struct file_system_type rootfs_fs_type = {
 	.name		= "rootfs",
 	.mount		= rootfs_mount,
 	.kill_sb	= kill_litter_super,
 };
+#endif
 
 static int __init init_ramfs_fs(void)
 {
@@ -289,6 +293,7 @@ static int __init init_ramfs_fs(void)
 }
 module_init(init_ramfs_fs)
 
+#if !(defined CONFIG_SHMEM && defined CONFIG_TMPFS)
 int __init init_rootfs(void)
 {
 	int err;
@@ -303,3 +308,4 @@ int __init init_rootfs(void)
 
 	return err;
 }
+#endif
diff --git a/mm/shmem.c b/mm/shmem.c
index d672250..9b7af22 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2220,7 +2220,7 @@ failed:
 	return err;
 }
 
-static struct kmem_cache *shmem_inode_cachep;
+static struct kmem_cache *shmem_inode_cachep = NULL;
 
 static struct inode *shmem_alloc_inode(struct super_block *sb)
 {
@@ -2253,9 +2253,11 @@ static void shmem_init_inode(void *foo)
 
 static int shmem_init_inodecache(void)
 {
-	shmem_inode_cachep = kmem_cache_create("shmem_inode_cache",
-				sizeof(struct shmem_inode_info),
-				0, SLAB_PANIC, shmem_init_inode);
+	if (!shmem_inode_cachep)
+		shmem_inode_cachep =
+			kmem_cache_create("shmem_inode_cache",
+					  sizeof(struct shmem_inode_info),
+					  0, SLAB_PANIC, shmem_init_inode);
 	return 0;
 }
 
@@ -2407,6 +2409,27 @@ out4:
 	return error;
 }
 
+#ifdef CONFIG_TMPFS
+static struct dentry *rootfs_mount(struct file_system_type *fs_type,
+				   int flags, const char *dev_name, void *data)
+{
+	return mount_nodev(fs_type, flags|MS_NOUSER, data, shmem_fill_super);
+}
+
+static struct file_system_type rootfs_fs_type = {
+	.name		= "rootfs",
+	.mount	        = rootfs_mount,
+	.kill_sb	= kill_litter_super,
+};
+
+int __init init_rootfs(void)
+{
+	if (shmem_init_inodecache())
+		panic("Rootfs - Can't initialize shm inode cache");
+	return register_filesystem(&rootfs_fs_type);
+}
+#endif
+
 #else /* !CONFIG_SHMEM */
 
 /*
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-12-05 17:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-05 17:02 [RFC][PATCH] Use tmpfs rather tham ramfs for rootfs when available Andrew Walrond

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.