All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND] The initmpfs patches.
@ 2013-07-10  2:06 Rob Landley
  2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
  0 siblings, 1 reply; 18+ messages in thread
From: Rob Landley @ 2013-07-10  2:06 UTC (permalink / raw)
  To: akpm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

Attached, so you don't have to fish them out of:

   http://lkml.indiana.edu/hypermail/linux/kernel/1306.3/04204.html

Do they look worth applying, or should I wash it through linux-next for  
a bit? (Which I'm not sure how to do if I don't host a git tree on a  
server, or I'd have done it already.)

There was a previous post with a patch demonstrating the basic concept  
a while ago (https://lwn.net/Articles/545740/). This is the cleaned up,  
broken up, tested in as many ways as I could think of, does not have  
section mismatches, allows you to disable it at runtime, passes  
checkpatch.pl version. Still applies to a git pull from 3 minutes ago  
(two patches have offsets, but no fuzz).

Thanks,

Rob

[-- Attachment #2: 00.patch --]
[-- Type: text/x-patch, Size: 1241 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 0/5] initmpfs: use tmpfs instead of ramfs for rootfs
To: linux-kernel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jim Cromie <jim.cromie@gmail.com>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Stephen Warren <swarren@nvidia.com>

Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
Specify rootfstype=ramfs to get the old initramfs behavior.

The previous initramfs code provided a fairly crappy root filesystem:
didn't let you --bind mount directories out of it, reported zero
size/usage so it didn't show up in "df" and couldn't run things like
rpm that query available space before proceeding, would fill up all
available memory and panic the system if you wrote too much to it...

Using tmpfs instead provides a much better root filesystem.

[-- Attachment #3: 01.patch --]
[-- Type: text/x-patch, Size: 1166 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 1/5] initmpfs: replace MS_NOUSER in initramfs
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>

From: Rob Landley <rob@landley.net>

Mounting MS_NOUSER prevents --bind mounts from rootfs. Prevent new rootfs
mounts with a different mechanism that doesn't affect bind mounts.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/ramfs/inode.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c24f1e1..14b9c35 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -247,7 +247,14 @@ struct dentry *ramfs_mount(struct file_system_type *fs_type,
 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);
+	static int once;
+
+	if (once)
+		return ERR_PTR(-ENODEV);
+	else
+		once++;
+
+	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
 static void ramfs_kill_sb(struct super_block *sb)

[-- Attachment #4: 02.patch --]
[-- Type: text/x-patch, Size: 1859 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 2/5] initmpfs: Move bdi setup from init_rootfs to init_ramfs
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>

From: Rob Landley <rob@landley.net>

Even though ramfs hasn't got a backing device, commit e0bf68ddec4f added one
anyway, and put the initialization in init_rootfs() since that's the first
user, leaving it out of init_ramfs() to avoid duplication.

But initmpfs uses init_tmpfs() instead, so move the init into the filesystem's
init function, add a "once" guard to prevent duplicate initialization, and
call the filesystem init from rootfs init.

This goes part of the way to allowing ramfs to be built as a module.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/ramfs/inode.c |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

--- initold/fs/ramfs/inode.c	2013-06-28 15:12:03.205879730 -0500
+++ initold2/fs/ramfs/inode.c	2013-06-28 15:12:12.425880115 -0500
@@ -277,21 +277,36 @@
 
 static int __init init_ramfs_fs(void)
 {
-	return register_filesystem(&ramfs_fs_type);
+	static int once;
+	int err;
+
+	if (once)
+		return 0;
+	else
+		once++;
+
+	err = bdi_init(&ramfs_backing_dev_info);
+	if (err)
+		return err;
+
+	err = register_filesystem(&ramfs_fs_type);
+	if (err)
+		bdi_destroy(&ramfs_backing_dev_info);
+
+	return err;
 }
 module_init(init_ramfs_fs)
 
 int __init init_rootfs(void)
 {
-	int err;
+	int err = register_filesystem(&rootfs_fs_type);
 
-	err = bdi_init(&ramfs_backing_dev_info);
 	if (err)
 		return err;
 
-	err = register_filesystem(&rootfs_fs_type);
+	err = init_ramfs_fs();
 	if (err)
-		bdi_destroy(&ramfs_backing_dev_info);
+		unregister_filesystem(&rootfs_fs_type);
 
 	return err;
 }

[-- Attachment #5: 03.patch --]
[-- Type: text/x-patch, Size: 4898 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 3/5] initmpfs: Move rootfs code from fs/ramfs/ to init/
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Jeff Layton <jlayton@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Jim Cromie <jim.cromie@gmail.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>

From: Rob Landley <rob@landley.net>

When the rootfs code was a wrapper around ramfs, having them in the same
file made sense. Now that it can wrap another filesystem type, move it
in with the init code instead.

This also allows a subsequent patch to access rootfstype= command line arg.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/namespace.c        |    2 +-
 fs/ramfs/inode.c      |   34 +---------------------------------
 include/linux/init.h  |    1 +
 include/linux/ramfs.h |    2 +-
 init/do_mounts.c      |   34 ++++++++++++++++++++++++++++++++++
 5 files changed, 38 insertions(+), 35 deletions(-)

--- initold/fs/namespace.c	2013-06-28 15:09:19.389872904 -0500
+++ initold2/fs/namespace.c	2013-06-28 15:16:05.261889820 -0500
@@ -17,7 +17,7 @@
 #include <linux/security.h>
 #include <linux/idr.h>
 #include <linux/acct.h>		/* acct_auto_close_mnt */
-#include <linux/ramfs.h>	/* init_rootfs */
+#include <linux/init.h>		/* init_rootfs */
 #include <linux/fs_struct.h>	/* get_fs_root et.al. */
 #include <linux/fsnotify.h>	/* fsnotify_vfsmount_delete */
 #include <linux/uaccess.h>
--- initold/fs/ramfs/inode.c	2013-06-28 15:15:37.549888666 -0500
+++ initold2/fs/ramfs/inode.c	2013-06-28 15:16:05.273889820 -0500
@@ -244,19 +244,6 @@
 	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
-static struct dentry *rootfs_mount(struct file_system_type *fs_type,
-	int flags, const char *dev_name, void *data)
-{
-	static int once;
-
-	if (once)
-		return ERR_PTR(-ENODEV);
-	else
-		once++;
-
-	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
-}
-
 static void ramfs_kill_sb(struct super_block *sb)
 {
 	kfree(sb->s_fs_info);
@@ -269,13 +256,8 @@
 	.kill_sb	= ramfs_kill_sb,
 	.fs_flags	= FS_USERNS_MOUNT,
 };
-static struct file_system_type rootfs_fs_type = {
-	.name		= "rootfs",
-	.mount		= rootfs_mount,
-	.kill_sb	= kill_litter_super,
-};
 
-static int __init init_ramfs_fs(void)
+int __init init_ramfs_fs(void)
 {
 	static int once;
 	int err;
@@ -296,17 +276,3 @@
 	return err;
 }
 module_init(init_ramfs_fs)
-
-int __init init_rootfs(void)
-{
-	int err = register_filesystem(&rootfs_fs_type);
-
-	if (err)
-		return err;
-
-	err = init_ramfs_fs();
-	if (err)
-		unregister_filesystem(&rootfs_fs_type);
-
-	return err;
-}
--- initold/include/linux/init.h	2013-06-28 15:09:19.517872909 -0500
+++ initold2/include/linux/init.h	2013-06-28 15:16:05.321889821 -0500
@@ -154,6 +154,7 @@
 void setup_arch(char **);
 void prepare_namespace(void);
 void __init load_default_modules(void);
+int __init init_rootfs(void);
 
 extern void (*late_time_init)(void);
 
--- initold/include/linux/ramfs.h	2013-06-28 15:09:19.537872910 -0500
+++ initold2/include/linux/ramfs.h	2013-06-28 15:16:05.513889832 -0500
@@ -25,7 +25,7 @@
 
 extern const struct file_operations ramfs_file_operations;
 extern const struct vm_operations_struct generic_file_vm_ops;
-extern int __init init_rootfs(void);
+extern int __init init_ramfs_fs(void);
 
 int ramfs_fill_super(struct super_block *sb, void *data, int silent);
 
--- initold/init/do_mounts.c	2013-06-28 15:09:19.585872913 -0500
+++ initold2/init/do_mounts.c	2013-06-28 15:16:05.561889831 -0500
@@ -26,6 +26,7 @@
 #include <linux/async.h>
 #include <linux/fs_struct.h>
 #include <linux/slab.h>
+#include <linux/ramfs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -588,3 +589,36 @@
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
 	sys_chroot(".");
 }
+
+static struct dentry *rootfs_mount(struct file_system_type *fs_type,
+	int flags, const char *dev_name, void *data)
+{
+	static int once;
+
+	if (once)
+		return ERR_PTR(-ENODEV);
+	else
+		once++;
+
+	return mount_nodev(fs_type, flags, data, ramfs_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)
+{
+	int err = register_filesystem(&rootfs_fs_type);
+
+	if (err)
+		return err;
+
+	err = init_ramfs_fs();
+	if (err)
+		unregister_filesystem(&rootfs_fs_type);
+
+	return err;
+}
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c24f1e1..3b9f114 100644

[-- Attachment #6: 04.patch --]
[-- Type: text/x-patch, Size: 2111 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 4/5] initmpfs: Make rootfs use tmpfs when CONFIG_TMPFS enabled.
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>

From: Rob Landley <rob@landley.net>

Conditionally call the appropriate fs_init function and fill_super functions.
Add a use once guard to shmem_init() to simply succeed on a second call.

(Note that IS_ENABLED() is a compile time constant so dead code elimination
removes unused function calls when CONFIG_TMPFS is disabled.)

Signed-off-by: Rob Landley <rob@landley.net>
---

 init/do_mounts.c |   10 ++++++++--
 mm/shmem.c       |    4 ++++
 2 files changed, 12 insertions(+), 2 deletions(-)

--- initold/init/do_mounts.c	2013-06-27 00:02:26.283442977 -0500
+++ initwork/init/do_mounts.c	2013-06-27 00:45:21.599550312 -0500
@@ -27,6 +27,7 @@
 #include <linux/fs_struct.h>
 #include <linux/slab.h>
 #include <linux/ramfs.h>
+#include <linux/shmem_fs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -600,7 +599,8 @@
 	else
 		once++;
 
-	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
+	return mount_nodev(fs_type, flags, data,
+		IS_ENABLED(CONFIG_TMPFS) ? shmem_fill_super : ramfs_fill_super);
 }
 
 static struct file_system_type rootfs_fs_type = {
@@ -616,7 +616,11 @@
 	if (err)
 		return err;
 
-	err = init_ramfs_fs();
+	if (IS_ENABLED(CONFIG_TMPFS))
+		err = shmem_init();
+	else
+		err = init_ramfs_fs();
+
 	if (err)
 		unregister_filesystem(&rootfs_fs_type);
 
--- initold/mm/shmem.c	2013-06-25 13:09:22.215743137 -0500
+++ initwork/mm/shmem.c	2013-06-27 00:16:58.195479317 -0500
@@ -2787,6 +2787,10 @@
 {
 	int error;
 
+	/* If rootfs called this, don't re-init */
+	if (shmem_inode_cachep)
+		return 0;
+
 	error = bdi_init(&shmem_backing_dev_info);
 	if (error)
 		goto out4;

[-- Attachment #7: 05.patch --]
[-- Type: text/x-patch, Size: 1776 bytes --]

From: Rob Landley <rob@landley.net>
Subject: [PATCH 5/5] initmpfs: Use initramfs if rootfstype= or root= specified.
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>

From: Rob Landley <rob@landley.net>

Command line option rootfstype=ramfs to obtain old initramfs behavior,
and use ramfs instead of tmpfs for stub when root= defined (for cosmetic
reasons).

Signed-off-by: Rob Landley <rob@landley.net>
---

 init/do_mounts.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- initold/init/do_mounts.c	2013-06-29 13:27:00.485256840 -0500
+++ initwork/init/do_mounts.c	2013-06-29 13:34:17.925275072 -0500
@@ -591,18 +591,22 @@
 	sys_chroot(".");
 }
 
+static bool is_tmpfs;
 static struct dentry *rootfs_mount(struct file_system_type *fs_type,
 	int flags, const char *dev_name, void *data)
 {
 	static int once;
+	void *fill = ramfs_fill_super;
 
 	if (once)
 		return ERR_PTR(-ENODEV);
 	else
 		once++;
 
-	return mount_nodev(fs_type, flags, data,
-		IS_ENABLED(CONFIG_TMPFS) ? shmem_fill_super : ramfs_fill_super);
+	if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
+		fill = shmem_fill_super;
+
+	return mount_nodev(fs_type, flags, data, fill);
 }
 
 static struct file_system_type rootfs_fs_type = {
@@ -618,9 +622,12 @@
 	if (err)
 		return err;
 
-	if (IS_ENABLED(CONFIG_TMPFS))
+	if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
+		(!root_fs_names || strstr(root_fs_names, "tmpfs")))
+	{
 		err = shmem_init();
-	else
+		is_tmpfs = true;
+	} else
 		err = init_ramfs_fs();
 
 	if (err)

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [RESEND] The initmpfs patches.
@ 2013-07-16 15:31   ` Rob Landley
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Morton @ 2013-07-15 21:01 UTC (permalink / raw)
  To: Rob Landley; +Cc: linux-kernel

On Tue, 09 Jul 2013 21:06:39 -0500 Rob Landley <rob@landley.net> wrote:

> Attached, so you don't have to fish them out of:
> 
>    http://lkml.indiana.edu/hypermail/linux/kernel/1306.3/04204.html

Too hard.  Especially when I want to reply to a patch.  Please resend
as a patch series in the time-honoured fashion?

> --- a/fs/ramfs/inode.c
> +++ b/fs/ramfs/inode.c
> @@ -247,7 +247,14 @@ struct dentry *ramfs_mount(struct file_system_type *fs_type,
>  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);
> +	static int once;
> +
> +	if (once)
> +		return ERR_PTR(-ENODEV);
> +	else
> +		once++;
> +
> +	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
>  }

The patches do this in a couple of places.  The treatment of `once' is
obviously racy.  Probably it is unlikely to matter in these contexts,
but it does set a poor example.  And it's so trivially fixed with, for
example, test_and_set_bit() that I do think it's worth that change.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [RESEND] The initmpfs patches.
  2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
  (?)
@ 2013-07-16  4:07   ` Rob Landley
  2013-07-16  7:12     ` Ramkumar Ramachandra
  -1 siblings, 1 reply; 18+ messages in thread
From: Rob Landley @ 2013-07-16  4:07 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On 07/15/2013 04:01:35 PM, Andrew Morton wrote:
> On Tue, 09 Jul 2013 21:06:39 -0500 Rob Landley <rob@landley.net>  
> wrote:
> 
> > Attached, so you don't have to fish them out of:
> >
> >    http://lkml.indiana.edu/hypermail/linux/kernel/1306.3/04204.html
> 
> Too hard.  Especially when I want to reply to a patch.  Please resend
> as a patch series in the time-honoured fashion?

Ok.

(Balsa is such an incompetent email client I wrote a python script to  
do this via raw smtp, and I'm always convinced it's going to screw up  
the send. But I think I've got it debugged now...)

> > --- a/fs/ramfs/inode.c
> > +++ b/fs/ramfs/inode.c
> > @@ -247,7 +247,14 @@ struct dentry *ramfs_mount(struct  
> file_system_type *fs_type,
> >  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);
> > +	static int once;
> > +
> > +	if (once)
> > +		return ERR_PTR(-ENODEV);
> > +	else
> > +		once++;
> > +
> > +	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
> >  }
> 
> The patches do this in a couple of places.  The treatment of `once' is
> obviously racy.  Probably it is unlikely to matter in these contexts,
> but it does set a poor example.  And it's so trivially fixed with, for
> example, test_and_set_bit() that I do think it's worth that change.

Fixing in new series. Retesting will probably delay the resend until  
morning.

Thanks,

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [RESEND] The initmpfs patches.
  2013-07-16  4:07   ` [RESEND] The initmpfs patches Rob Landley
@ 2013-07-16  7:12     ` Ramkumar Ramachandra
  2013-07-16 23:43       ` Rob Landley
  0 siblings, 1 reply; 18+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-16  7:12 UTC (permalink / raw)
  To: Rob Landley; +Cc: Andrew Morton, linux-kernel

Rob Landley wrote:
> (Balsa is such an incompetent email client I wrote a python script to do
> this via raw smtp, and I'm always convinced it's going to screw up the send.
> But I think I've got it debugged now...)

Use the tried-and-tested git-send-email.perl, perhaps?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-16 15:31   ` Rob Landley
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-16 15:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alexander Viro

Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
Specify rootfstype=ramfs to get the old initramfs behavior.

The previous initramfs code provided a fairly crappy root filesystem:
didn't let you --bind mount directories out of it, reported zero
size/usage so it didn't show up in "df" and couldn't run things like
rpm that query available space before proceeding, would fill up all
available memory and panic the system if you wrote too much to it...

Using tmpfs instead provides a much better root filesystem.

Changes from last time: use test_and_set_bit() for "once" logic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/
  2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
  (?)
  (?)
@ 2013-07-16 15:31   ` Rob Landley
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-16 15:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-fsdevel, Jeff Layton, Jens Axboe, Stephen Warren,
	Rusty Russell, Jim Cromie, Sam Ravnborg, Greg Kroah-Hartman,
	Andrew Morton, Eric W. Biederman, Alexander Viro

From: Rob Landley <rob@landley.net>

When the rootfs code was a wrapper around ramfs, having them in the same
file made sense. Now that it can wrap another filesystem type, move it
in with the init code instead.

This also allows a subsequent patch to access rootfstype= command line arg.

Signed-off-by: Rob Landley <rob@landley.net>
---

 fs/namespace.c        |    2 +-
 fs/ramfs/inode.c      |   32 +-------------------------------
 include/linux/init.h  |    1 +
 include/linux/ramfs.h |    2 +-
 init/do_mounts.c      |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 36 insertions(+), 33 deletions(-)

--- initold/fs/namespace.c	2013-06-28 15:09:19.389872904 -0500
+++ initold2/fs/namespace.c	2013-06-28 15:16:05.261889820 -0500
@@ -17,7 +17,7 @@
 #include <linux/security.h>
 #include <linux/idr.h>
 #include <linux/acct.h>		/* acct_auto_close_mnt */
-#include <linux/ramfs.h>	/* init_rootfs */
+#include <linux/init.h>		/* init_rootfs */
 #include <linux/fs_struct.h>	/* get_fs_root et.al. */
 #include <linux/fsnotify.h>	/* fsnotify_vfsmount_delete */
 #include <linux/uaccess.h>
--- initold/fs/ramfs/inode.c	2013-06-28 15:15:37.549888666 -0500
+++ initold2/fs/ramfs/inode.c	2013-06-28 15:16:05.273889820 -0500
@@ -244,17 +244,6 @@
 	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
 }
 
-static struct dentry *rootfs_mount(struct file_system_type *fs_type,
-	int flags, const char *dev_name, void *data)
-{
-	static unsigned long once;
-
-	if (test_and_set_bit(1, &once))
-		return ERR_PTR(-ENODEV);
-
-	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
-}
-
 static void ramfs_kill_sb(struct super_block *sb)
 {
 	kfree(sb->s_fs_info);
@@ -267,13 +256,8 @@
 	.kill_sb	= ramfs_kill_sb,
 	.fs_flags	= FS_USERNS_MOUNT,
 };
-static struct file_system_type rootfs_fs_type = {
-	.name		= "rootfs",
-	.mount		= rootfs_mount,
-	.kill_sb	= kill_litter_super,
-};
 
-static int __init init_ramfs_fs(void)
+int __init init_ramfs_fs(void)
 {
 	static unsigned long once;
 	int err;
@@ -292,17 +276,3 @@
 	return err;
 }
 module_init(init_ramfs_fs)
-
-int __init init_rootfs(void)
-{
-	int err = register_filesystem(&rootfs_fs_type);
-
-	if (err)
-		return err;
-
-	err = init_ramfs_fs();
-	if (err)
-		unregister_filesystem(&rootfs_fs_type);
-
-	return err;
-}
--- initold/include/linux/init.h	2013-06-28 15:09:19.517872909 -0500
+++ initold2/include/linux/init.h	2013-06-28 15:16:05.321889821 -0500
@@ -153,6 +153,7 @@
 void setup_arch(char **);
 void prepare_namespace(void);
 void __init load_default_modules(void);
+int __init init_rootfs(void);
 
 extern void (*late_time_init)(void);
 
--- initold/include/linux/ramfs.h	2013-06-28 15:09:19.537872910 -0500
+++ initold2/include/linux/ramfs.h	2013-06-28 15:16:05.513889832 -0500
@@ -25,7 +25,7 @@
 
 extern const struct file_operations ramfs_file_operations;
 extern const struct vm_operations_struct generic_file_vm_ops;
-extern int __init init_rootfs(void);
+extern int __init init_ramfs_fs(void);
 
 int ramfs_fill_super(struct super_block *sb, void *data, int silent);
 
--- initold/init/do_mounts.c	2013-06-28 15:09:19.585872913 -0500
+++ initold2/init/do_mounts.c	2013-06-28 15:16:05.561889831 -0500
@@ -26,6 +26,7 @@
 #include <linux/async.h>
 #include <linux/fs_struct.h>
 #include <linux/slab.h>
+#include <linux/ramfs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -588,3 +589,34 @@
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
 	sys_chroot(".");
 }
+
+static struct dentry *rootfs_mount(struct file_system_type *fs_type,
+	int flags, const char *dev_name, void *data)
+{
+	static unsigned long once;
+
+	if (test_and_set_bit(1, &once))
+		return ERR_PTR(-ENODEV);
+
+	return mount_nodev(fs_type, flags, data, ramfs_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)
+{
+	int err = register_filesystem(&rootfs_fs_type);
+
+	if (err)
+		return err;
+
+	err = init_ramfs_fs();
+	if (err)
+		unregister_filesystem(&rootfs_fs_type);
+
+	return err;
+}
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index c24f1e1..3b9f114 100644

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled.
  2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
                     ` (2 preceding siblings ...)
  (?)
@ 2013-07-16 15:31   ` Rob Landley
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-16 15:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, Al Viro, Greg Kroah-Hartman, Jens Axboe,
	Stephen Warren, Andrew Morton, Hugh Dickins

From: Rob Landley <rob@landley.net>

Conditionally call the appropriate fs_init function and fill_super functions.
Add a use once guard to shmem_init() to simply succeed on a second call.

(Note that IS_ENABLED() is a compile time constant so dead code elimination
removes unused function calls when CONFIG_TMPFS is disabled.)

Signed-off-by: Rob Landley <rob@landley.net>
---

 init/do_mounts.c |   10 ++++++++--
 mm/shmem.c       |    4 ++++
 2 files changed, 12 insertions(+), 2 deletions(-)

--- initold/init/do_mounts.c	2013-06-27 00:02:26.283442977 -0500
+++ initwork/init/do_mounts.c	2013-06-27 00:45:21.599550312 -0500
@@ -27,6 +27,7 @@
 #include <linux/fs_struct.h>
 #include <linux/slab.h>
 #include <linux/ramfs.h>
+#include <linux/shmem_fs.h>
 
 #include <linux/nfs_fs.h>
 #include <linux/nfs_fs_sb.h>
@@ -598,7 +597,8 @@
 	if (test_and_set_bit(1, &once))
 		return ERR_PTR(-ENODEV);
 
-	return mount_nodev(fs_type, flags, data, ramfs_fill_super);
+	return mount_nodev(fs_type, flags, data,
+		IS_ENABLED(CONFIG_TMPFS) ? shmem_fill_super : ramfs_fill_super);
 }
 
 static struct file_system_type rootfs_fs_type = {
@@ -614,7 +614,11 @@
 	if (err)
 		return err;
 
-	err = init_ramfs_fs();
+	if (IS_ENABLED(CONFIG_TMPFS))
+		err = shmem_init();
+	else
+		err = init_ramfs_fs();
+
 	if (err)
 		unregister_filesystem(&rootfs_fs_type);
 
--- initold/mm/shmem.c	2013-06-25 13:09:22.215743137 -0500
+++ initwork/mm/shmem.c	2013-06-27 00:16:58.195479317 -0500
@@ -2816,6 +2816,10 @@
 {
 	int error;
 
+	/* If rootfs called this, don't re-init */
+	if (shmem_inode_cachep)
+		return 0;
+
 	error = bdi_init(&shmem_backing_dev_info);
 	if (error)
 		goto out4;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [RESEND] The initmpfs patches.
  2013-07-16  7:12     ` Ramkumar Ramachandra
@ 2013-07-16 23:43       ` Rob Landley
  2013-07-17  7:02         ` Ramkumar Ramachandra
  0 siblings, 1 reply; 18+ messages in thread
From: Rob Landley @ 2013-07-16 23:43 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Andrew Morton, linux-kernel

On 07/16/2013 02:12:19 AM, Ramkumar Ramachandra wrote:
> Rob Landley wrote:
> > (Balsa is such an incompetent email client I wrote a python script  
> to do
> > this via raw smtp, and I'm always convinced it's going to screw up  
> the send.
> > But I think I've got it debugged now...)
> 
> Use the tried-and-tested git-send-email.perl, perhaps?

Is this script of yours any use for patches that aren't, and never  
were, in git? (Given that it's not in the kernel tree, I'm guessing  
"no".)

That said... in my resend this morning I substituted the message-id of  
the first message instead of the reply-to, didn't I? (Trying to make it  
a reply to Andrew's most recent message. Confused the list archive, it  
seems.)

I'll resend again...

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [RESEND] The initmpfs patches.
  2013-07-16 23:43       ` Rob Landley
@ 2013-07-17  7:02         ` Ramkumar Ramachandra
  0 siblings, 0 replies; 18+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-17  7:02 UTC (permalink / raw)
  To: Rob Landley; +Cc: Andrew Morton, linux-kernel

Rob Landley wrote:
> Is this script of yours any use for patches that aren't, and never were, in
> git? (Given that it's not in the kernel tree, I'm guessing "no".)

It's part of git.git.  And yes, it works with plain mbox files
(especially those generated by `git format-patch`).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
  2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
@ 2013-07-17 23:06     ` Andrew Morton
  -1 siblings, 0 replies; 18+ messages in thread
From: Andrew Morton @ 2013-07-17 23:06 UTC (permalink / raw)
  To: Rob Landley
  Cc: linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:

> Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> Specify rootfstype=ramfs to get the old initramfs behavior.
> 
> The previous initramfs code provided a fairly crappy root filesystem:
> didn't let you --bind mount directories out of it, reported zero
> size/usage so it didn't show up in "df" and couldn't run things like
> rpm that query available space before proceeding, would fill up all
> available memory and panic the system if you wrote too much to it...

The df problem and the mount --bind thing are ramfs issues, are they
not?  Can we fix them?  If so, that's a less intrusive change, and we
also get a fixed ramfs.

> Using tmpfs instead provides a much better root filesystem.
> 
> Changes from last time: use test_and_set_bit() for "once" logic.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-17 23:06     ` Andrew Morton
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew Morton @ 2013-07-17 23:06 UTC (permalink / raw)
  To: Rob Landley
  Cc: linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:

> Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> Specify rootfstype=ramfs to get the old initramfs behavior.
> 
> The previous initramfs code provided a fairly crappy root filesystem:
> didn't let you --bind mount directories out of it, reported zero
> size/usage so it didn't show up in "df" and couldn't run things like
> rpm that query available space before proceeding, would fill up all
> available memory and panic the system if you wrote too much to it...

The df problem and the mount --bind thing are ramfs issues, are they
not?  Can we fix them?  If so, that's a less intrusive change, and we
also get a fixed ramfs.

> Using tmpfs instead provides a much better root filesystem.
> 
> Changes from last time: use test_and_set_bit() for "once" logic.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
  2013-07-17 23:06     ` Andrew Morton
@ 2013-07-18  0:15       ` Hugh Dickins
  -1 siblings, 0 replies; 18+ messages in thread
From: Hugh Dickins @ 2013-07-18  0:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rob Landley, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On Wed, 17 Jul 2013, Andrew Morton wrote:
> On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:
> 
> > Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> > Specify rootfstype=ramfs to get the old initramfs behavior.
> > 
> > The previous initramfs code provided a fairly crappy root filesystem:
> > didn't let you --bind mount directories out of it, reported zero
> > size/usage so it didn't show up in "df" and couldn't run things like
> > rpm that query available space before proceeding, would fill up all
> > available memory and panic the system if you wrote too much to it...
> 
> The df problem and the mount --bind thing are ramfs issues, are they
> not?  Can we fix them?  If so, that's a less intrusive change, and we
> also get a fixed ramfs.

I'll leave others to comment on "mount --bind", but with regard to "df":
yes, we could enhance ramfs with accounting such as tmpfs has, to allow
it to support non-0 "df".  We could have done so years ago; but have
always preferred to leave ramfs as minimal, than import tmpfs features
into it one by one.

I prefer Rob's approach of making tmpfs usable for rootfs.

Hugh

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-18  0:15       ` Hugh Dickins
  0 siblings, 0 replies; 18+ messages in thread
From: Hugh Dickins @ 2013-07-18  0:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rob Landley, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On Wed, 17 Jul 2013, Andrew Morton wrote:
> On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:
> 
> > Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> > Specify rootfstype=ramfs to get the old initramfs behavior.
> > 
> > The previous initramfs code provided a fairly crappy root filesystem:
> > didn't let you --bind mount directories out of it, reported zero
> > size/usage so it didn't show up in "df" and couldn't run things like
> > rpm that query available space before proceeding, would fill up all
> > available memory and panic the system if you wrote too much to it...
> 
> The df problem and the mount --bind thing are ramfs issues, are they
> not?  Can we fix them?  If so, that's a less intrusive change, and we
> also get a fixed ramfs.

I'll leave others to comment on "mount --bind", but with regard to "df":
yes, we could enhance ramfs with accounting such as tmpfs has, to allow
it to support non-0 "df".  We could have done so years ago; but have
always preferred to leave ramfs as minimal, than import tmpfs features
into it one by one.

I prefer Rob's approach of making tmpfs usable for rootfs.

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
  2013-07-18  0:15       ` Hugh Dickins
  (?)
@ 2013-07-18 23:17         ` Rob Landley
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-18 23:17 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

Andrew: I'll save you the time of reading this message.

   tl;dr: "I agree with what Hugh said".

You're welcome. :)

On 07/17/2013 07:15:29 PM, Hugh Dickins wrote:
> On Wed, 17 Jul 2013, Andrew Morton wrote:
> > On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley  
> <rob@landley.net> wrote:
> >
> > > Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> > > Specify rootfstype=ramfs to get the old initramfs behavior.
> > >
> > > The previous initramfs code provided a fairly crappy root  
> filesystem:
> > > didn't let you --bind mount directories out of it, reported zero
> > > size/usage so it didn't show up in "df" and couldn't run things  
> like
> > > rpm that query available space before proceeding, would fill up  
> all
> > > available memory and panic the system if you wrote too much to  
> it...
> >
> > The df problem and the mount --bind thing are ramfs issues, are they
> > not?  Can we fix them?  If so, that's a less intrusive change, and  
> we
> > also get a fixed ramfs.
> 
> I'll leave others to comment on "mount --bind",

It's unrelated to tmpfs but _is_ related to exposing a non-broken rootfs
to the user.

> but with regard to "df":
> yes, we could enhance ramfs with accounting such as tmpfs has, to  
> allow
> it to support non-0 "df".  We could have done so years ago; but have
> always preferred to leave ramfs as minimal, than import tmpfs features
> into it one by one.

Ramfs reporting 0 size is not a new issue, here it is 13 years ago:

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0098.html

And people proposed adding resource limits to ramfs at the time (yes,
13 years ago):

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0713.html

And Linus complained about complicating ramfs which he thought was a  
good
educational example and could be turned into a reusable code library.
(Somewhere around  
http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0257.html
or http://lkml.indiana.edu/hypermail/linux/kernel/0101.0/1167.html or...
I'd have to dig for that one. I remember reading it but my google roll
missed.)

Way back when Linus also mentioned embedded users benefitting from
rootfs, ala:

http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0307.html

Which is why I documented rootfs to be ramfs "or tmpfs, if that's
enabled" back in 2005:

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt#n57

And when I found out it still wasn't the case a year later I went
"um, hey!" on the list, but ironically I got pushback from the same
guy who objected to my perl removal patches as an "academic"
exercise because it's not how _he_ uses linux...

http://lkml.indiana.edu/hypermail/linux/kernel/0607.3/2480.html
https://lkml.org/lkml/2013/3/20/321

(And you wonder why embedded guys don't speak up more? I'm an
outright "bullhorn and plackard" guy in this community. Random
example: a guy named Rich Felker has been hanging out on the
busybox and uclibc lists and IRC channels for years, and recently
wrote musl-libc.org from "git init" to "builds linux from scratch"
in 2 years. He's on the posix committe list and posts there
multiple times per week. Number of times he's posted to
linux-kernel: zero. I'm sure Sarah Sharp just facepalmed...)

I was recently reminded of initmpfs because I'm finishing up a
contract at Cray and they wanted to do this on their supercomputers
and I went "oh, that's easy", and then had to make it work.
(Embedded and supercomputing have always been closer to each other
than either is to the desktop...) This is very much Not My Area
but I've been waiting a _decade_ for other people to do this and
nada. Really, you could see this as just "fixing my documentation"
from way back when, by changing the code to match the docs. :)

> I prefer Rob's approach of making tmpfs usable for rootfs.

Me too. The resource accounting logic in tmpfs is hundreds of lines,
with shmem_default_max_blocks and shmem_default_max_inodes to specify
default size limits, mount-time option parsing to specify different
values for those limits, plus remount logic (what if you specify a
smaller size after the fact?), plus displaying the settings per-mount
in /proc/mounts... see mm/shmem.c lines 2414 through 2581 for the
largest chunk of it.

That's why we got tmpfs/shmfs as a separate filesystem in the first
place: it's a design decision. Ramfs is intentionally minimalist.

Ramfs can't say how big it is because it doesn't _know_ how big it is.
If you write unlimited data to ramfs, the OOM killer zaps everything but
init and then the system hangs in a page eviction loop. (The OOM killer
can't free pinned page cache with nowhere to evict it to.)

My patch series switching over tmpfs is much smaller than the tmpfs
size accounting code, and we get the swap backing store for free. Plus
hooking up years-old existing tested code (instead of putting new  
untested
logic in the boot path), without duplicating functionality.

I.E. "what Hugh said."

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-18 23:17         ` Rob Landley
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-18 23:17 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

Andrew: I'll save you the time of reading this message.

   tl;dr: "I agree with what Hugh said".

You're welcome. :)

On 07/17/2013 07:15:29 PM, Hugh Dickins wrote:
> On Wed, 17 Jul 2013, Andrew Morton wrote:
> > On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley  
> <rob@landley.net> wrote:
> >
> > > Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> > > Specify rootfstype=ramfs to get the old initramfs behavior.
> > >
> > > The previous initramfs code provided a fairly crappy root  
> filesystem:
> > > didn't let you --bind mount directories out of it, reported zero
> > > size/usage so it didn't show up in "df" and couldn't run things  
> like
> > > rpm that query available space before proceeding, would fill up  
> all
> > > available memory and panic the system if you wrote too much to  
> it...
> >
> > The df problem and the mount --bind thing are ramfs issues, are they
> > not?  Can we fix them?  If so, that's a less intrusive change, and  
> we
> > also get a fixed ramfs.
> 
> I'll leave others to comment on "mount --bind",

It's unrelated to tmpfs but _is_ related to exposing a non-broken rootfs
to the user.

> but with regard to "df":
> yes, we could enhance ramfs with accounting such as tmpfs has, to  
> allow
> it to support non-0 "df".  We could have done so years ago; but have
> always preferred to leave ramfs as minimal, than import tmpfs features
> into it one by one.

Ramfs reporting 0 size is not a new issue, here it is 13 years ago:

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0098.html

And people proposed adding resource limits to ramfs at the time (yes,
13 years ago):

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0713.html

And Linus complained about complicating ramfs which he thought was a  
good
educational example and could be turned into a reusable code library.
(Somewhere around  
http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0257.html
or http://lkml.indiana.edu/hypermail/linux/kernel/0101.0/1167.html or...
I'd have to dig for that one. I remember reading it but my google roll
missed.)

Way back when Linus also mentioned embedded users benefitting from
rootfs, ala:

http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0307.html

Which is why I documented rootfs to be ramfs "or tmpfs, if that's
enabled" back in 2005:

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt#n57

And when I found out it still wasn't the case a year later I went
"um, hey!" on the list, but ironically I got pushback from the same
guy who objected to my perl removal patches as an "academic"
exercise because it's not how _he_ uses linux...

http://lkml.indiana.edu/hypermail/linux/kernel/0607.3/2480.html
https://lkml.org/lkml/2013/3/20/321

(And you wonder why embedded guys don't speak up more? I'm an
outright "bullhorn and plackard" guy in this community. Random
example: a guy named Rich Felker has been hanging out on the
busybox and uclibc lists and IRC channels for years, and recently
wrote musl-libc.org from "git init" to "builds linux from scratch"
in 2 years. He's on the posix committe list and posts there
multiple times per week. Number of times he's posted to
linux-kernel: zero. I'm sure Sarah Sharp just facepalmed...)

I was recently reminded of initmpfs because I'm finishing up a
contract at Cray and they wanted to do this on their supercomputers
and I went "oh, that's easy", and then had to make it work.
(Embedded and supercomputing have always been closer to each other
than either is to the desktop...) This is very much Not My Area
but I've been waiting a _decade_ for other people to do this and
nada. Really, you could see this as just "fixing my documentation"
from way back when, by changing the code to match the docs. :)

> I prefer Rob's approach of making tmpfs usable for rootfs.

Me too. The resource accounting logic in tmpfs is hundreds of lines,
with shmem_default_max_blocks and shmem_default_max_inodes to specify
default size limits, mount-time option parsing to specify different
values for those limits, plus remount logic (what if you specify a
smaller size after the fact?), plus displaying the settings per-mount
in /proc/mounts... see mm/shmem.c lines 2414 through 2581 for the
largest chunk of it.

That's why we got tmpfs/shmfs as a separate filesystem in the first
place: it's a design decision. Ramfs is intentionally minimalist.

Ramfs can't say how big it is because it doesn't _know_ how big it is.
If you write unlimited data to ramfs, the OOM killer zaps everything but
init and then the system hangs in a page eviction loop. (The OOM killer
can't free pinned page cache with nowhere to evict it to.)

My patch series switching over tmpfs is much smaller than the tmpfs
size accounting code, and we get the swap backing store for free. Plus
hooking up years-old existing tested code (instead of putting new  
untested
logic in the boot path), without duplicating functionality.

I.E. "what Hugh said."

Rob
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-18 23:17         ` Rob Landley
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Landley @ 2013-07-18 23:17 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Jeff Layton, Jens Axboe, Jim Cromie,
	linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

Andrew: I'll save you the time of reading this message.

   tl;dr: "I agree with what Hugh said".

You're welcome. :)

On 07/17/2013 07:15:29 PM, Hugh Dickins wrote:
> On Wed, 17 Jul 2013, Andrew Morton wrote:
> > On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley  
> <rob@landley.net> wrote:
> >
> > > Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
> > > Specify rootfstype=ramfs to get the old initramfs behavior.
> > >
> > > The previous initramfs code provided a fairly crappy root  
> filesystem:
> > > didn't let you --bind mount directories out of it, reported zero
> > > size/usage so it didn't show up in "df" and couldn't run things  
> like
> > > rpm that query available space before proceeding, would fill up  
> all
> > > available memory and panic the system if you wrote too much to  
> it...
> >
> > The df problem and the mount --bind thing are ramfs issues, are they
> > not?  Can we fix them?  If so, that's a less intrusive change, and  
> we
> > also get a fixed ramfs.
> 
> I'll leave others to comment on "mount --bind",

It's unrelated to tmpfs but _is_ related to exposing a non-broken rootfs
to the user.

> but with regard to "df":
> yes, we could enhance ramfs with accounting such as tmpfs has, to  
> allow
> it to support non-0 "df".  We could have done so years ago; but have
> always preferred to leave ramfs as minimal, than import tmpfs features
> into it one by one.

Ramfs reporting 0 size is not a new issue, here it is 13 years ago:

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0098.html

And people proposed adding resource limits to ramfs at the time (yes,
13 years ago):

http://lkml.indiana.edu/hypermail/linux/kernel/0011.2/0713.html

And Linus complained about complicating ramfs which he thought was a  
good
educational example and could be turned into a reusable code library.
(Somewhere around  
http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0257.html
or http://lkml.indiana.edu/hypermail/linux/kernel/0101.0/1167.html or...
I'd have to dig for that one. I remember reading it but my google roll
missed.)

Way back when Linus also mentioned embedded users benefitting from
rootfs, ala:

http://lkml.indiana.edu/hypermail/linux/kernel/0112.3/0307.html

Which is why I documented rootfs to be ramfs "or tmpfs, if that's
enabled" back in 2005:

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.txt#n57

And when I found out it still wasn't the case a year later I went
"um, hey!" on the list, but ironically I got pushback from the same
guy who objected to my perl removal patches as an "academic"
exercise because it's not how _he_ uses linux...

http://lkml.indiana.edu/hypermail/linux/kernel/0607.3/2480.html
https://lkml.org/lkml/2013/3/20/321

(And you wonder why embedded guys don't speak up more? I'm an
outright "bullhorn and plackard" guy in this community. Random
example: a guy named Rich Felker has been hanging out on the
busybox and uclibc lists and IRC channels for years, and recently
wrote musl-libc.org from "git init" to "builds linux from scratch"
in 2 years. He's on the posix committe list and posts there
multiple times per week. Number of times he's posted to
linux-kernel: zero. I'm sure Sarah Sharp just facepalmed...)

I was recently reminded of initmpfs because I'm finishing up a
contract at Cray and they wanted to do this on their supercomputers
and I went "oh, that's easy", and then had to make it work.
(Embedded and supercomputing have always been closer to each other
than either is to the desktop...) This is very much Not My Area
but I've been waiting a _decade_ for other people to do this and
nada. Really, you could see this as just "fixing my documentation"
from way back when, by changing the code to match the docs. :)

> I prefer Rob's approach of making tmpfs usable for rootfs.

Me too. The resource accounting logic in tmpfs is hundreds of lines,
with shmem_default_max_blocks and shmem_default_max_inodes to specify
default size limits, mount-time option parsing to specify different
values for those limits, plus remount logic (what if you specify a
smaller size after the fact?), plus displaying the settings per-mount
in /proc/mounts... see mm/shmem.c lines 2414 through 2581 for the
largest chunk of it.

That's why we got tmpfs/shmfs as a separate filesystem in the first
place: it's a design decision. Ramfs is intentionally minimalist.

Ramfs can't say how big it is because it doesn't _know_ how big it is.
If you write unlimited data to ramfs, the OOM killer zaps everything but
init and then the system hangs in a page eviction loop. (The OOM killer
can't free pinned page cache with nowhere to evict it to.)

My patch series switching over tmpfs is much smaller than the tmpfs
size accounting code, and we get the swap backing store for free. Plus
hooking up years-old existing tested code (instead of putting new  
untested
logic in the boot path), without duplicating functionality.

I.E. "what Hugh said."

Rob
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
  2013-07-17 23:06     ` Andrew Morton
@ 2013-07-18 23:59       ` H. Peter Anvin
  -1 siblings, 0 replies; 18+ messages in thread
From: H. Peter Anvin @ 2013-07-18 23:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rob Landley, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On 07/17/2013 04:06 PM, Andrew Morton wrote:
> On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:
> 
>> Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
>> Specify rootfstype=ramfs to get the old initramfs behavior.
>>
>> The previous initramfs code provided a fairly crappy root filesystem:
>> didn't let you --bind mount directories out of it, reported zero
>> size/usage so it didn't show up in "df" and couldn't run things like
>> rpm that query available space before proceeding, would fill up all
>> available memory and panic the system if you wrote too much to it...
> 
> The df problem and the mount --bind thing are ramfs issues, are they
> not?  Can we fix them?  If so, that's a less intrusive change, and we
> also get a fixed ramfs.
> 

mount --bind might be useful to fix for ramfs in general (as ramfs
should provide minimal standard filesystem functionality, and that one
counts, I believe), but honestly... we should have had tmpfs as a root
filesystem option either as rootfs or as an automatic overmount a long
time ago.

The automatic overmount option (that is tmpfs on top of rootfs) is nice
in some ways, as it makes garbage-collecting the inittmpfs trivial; this
might save some boot time in the more conventional root scenarios.  On
the other hand, it doesn't exactly seem to be a big problem to just
unlink everything.

	-hpa


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs
@ 2013-07-18 23:59       ` H. Peter Anvin
  0 siblings, 0 replies; 18+ messages in thread
From: H. Peter Anvin @ 2013-07-18 23:59 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Rob Landley, linux-kernel, Alexander Viro, Eric W. Biederman,
	Greg Kroah-Hartman, Hugh Dickins, Jeff Layton, Jens Axboe,
	Jim Cromie, linux-fsdevel, linux-mm, Rusty Russell, Sam Ravnborg,
	Stephen Warren

On 07/17/2013 04:06 PM, Andrew Morton wrote:
> On Tue, 16 Jul 2013 08:31:13 -0700 (PDT) Rob Landley <rob@landley.net> wrote:
> 
>> Use tmpfs for rootfs when CONFIG_TMPFS=y and there's no root=.
>> Specify rootfstype=ramfs to get the old initramfs behavior.
>>
>> The previous initramfs code provided a fairly crappy root filesystem:
>> didn't let you --bind mount directories out of it, reported zero
>> size/usage so it didn't show up in "df" and couldn't run things like
>> rpm that query available space before proceeding, would fill up all
>> available memory and panic the system if you wrote too much to it...
> 
> The df problem and the mount --bind thing are ramfs issues, are they
> not?  Can we fix them?  If so, that's a less intrusive change, and we
> also get a fixed ramfs.
> 

mount --bind might be useful to fix for ramfs in general (as ramfs
should provide minimal standard filesystem functionality, and that one
counts, I believe), but honestly... we should have had tmpfs as a root
filesystem option either as rootfs or as an automatic overmount a long
time ago.

The automatic overmount option (that is tmpfs on top of rootfs) is nice
in some ways, as it makes garbage-collecting the inittmpfs trivial; this
might save some boot time in the more conventional root scenarios.  On
the other hand, it doesn't exactly seem to be a big problem to just
unlink everything.

	-hpa

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-07-19  0:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10  2:06 [RESEND] The initmpfs patches Rob Landley
2013-07-15 21:01 ` Andrew Morton
2013-07-16 15:31   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Rob Landley
2013-07-16  4:07   ` [RESEND] The initmpfs patches Rob Landley
2013-07-16  7:12     ` Ramkumar Ramachandra
2013-07-16 23:43       ` Rob Landley
2013-07-17  7:02         ` Ramkumar Ramachandra
2013-07-16 15:31   ` [PATCH 3/5] initmpfs v2: Move rootfs code from fs/ramfs/ to init/ Rob Landley
2013-07-16 15:31   ` [PATCH 4/5] initmpfs v2: Make rootfs use tmpfs when CONFIG_TMPFS enabled Rob Landley
2013-07-17 23:06   ` [PATCH 0/5] initmpfs v2: use tmpfs instead of ramfs for rootfs Andrew Morton
2013-07-17 23:06     ` Andrew Morton
2013-07-18  0:15     ` Hugh Dickins
2013-07-18  0:15       ` Hugh Dickins
2013-07-18 23:17       ` Rob Landley
2013-07-18 23:17         ` Rob Landley
2013-07-18 23:17         ` Rob Landley
2013-07-18 23:59     ` H. Peter Anvin
2013-07-18 23:59       ` H. Peter Anvin

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.