Skip to contentSkip to conversation

On-demand Filesystem Initialisation

RFC PATCH In review Tom Spink 3 participants 7 messages Jun 1, 2008 – Jun 2, 2008

Subsystems (2)
lore
Share & tools
lore

Tom Spink

author
#0 lore raw

cover On-demand Filesystem Initialisation

(resend to include CCs)

This (short) patch series is another RFC for the patch that introduces on-demand filesystem initialisation. In addition to the original infrastructure implementation (with clean-ups), it changes XFS to use this new infrastructure.

I wrote a toy filesystem (testfs) to simulate scheduling/allocation delays and to torture the mount/unmount cycles. I didn't manage to deadlock the system in my tests. XFS also works as expected aswell, in that the global threads are not created until an XFS filesystem is mounted for the first time. When the last XFS filesystem is unmounted, the threads go away.

Please let me know what you think!

-- Tom

fs/filesystems.c             |    2 +
fs/super.c                   |   47 +++++++++++++++++++++++++++++++++++-
fs/xfs/linux-2.6/xfs_super.c |   55 +++++++++++++++++++++++-------------------
include/linux/fs.h           |    3 ++
4 files changed, 81 insertions(+), 26 deletions(-)
author
#1 lore raw

RFC PATCH 1/2 vfs: Introduce on-demand filesystem initialisation

This patch adds on-demand filesystem initialisation capabilities to the VFS, whereby an init routine will be executed on first use of a particular filesystem type. Also, an exit routine will be executed when the last superblock of a filesystem type is deactivated.

This is useful for filesystems that share global resources between all instances of the filesystem, but only need those resources when there are any users of the filesystem. This lets the filesystem initialise those resources (kernel threads or caches, say) when the first superblock is created. It also lets the filesystem clean up those resources when the last superblock is deactivated.

---
 fs/filesystems.c   |    2 ++
 fs/super.c         |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/fs.h |    3 +++
 3 files changed, 51 insertions(+), 1 deletions(-)
fs/filesystems.c +2 -0
index f37f872..59b2eaa 100644
@@ -79,6 +79,7 @@ int register_filesystem(struct file_system_type * fs)
 		res = -EBUSY;
 	else
 		*p = fs;
+	mutex_init(&fs->fs_supers_lock);
 	write_unlock(&file_systems_lock);
 	return res;
 }
@@ -105,6 +106,7 @@ int unregister_filesystem(struct file_system_type * fs)
 	tmp = &file_systems;
 	while (*tmp) {
 		if (fs == *tmp) {
+			mutex_destroy(&fs->fs_supers_lock);
 			*tmp = fs->next;
 			fs->next = NULL;
 			write_unlock(&file_systems_lock);
fs/super.c +46 -1

87 lines not on this page · raw message

include/linux/fs.h +3 -0
index f413085..92d446f 100644
@@ -1477,8 +1477,11 @@ struct file_system_type {
 	int (*get_sb) (struct file_system_type *, int,
 		       const char *, void *, struct vfsmount *);
 	void (*kill_sb) (struct super_block *);
+	int (*init) (void);
+	void (*exit) (void);
 	struct module *owner;
 	struct file_system_type * next;
+	struct mutex fs_supers_lock;
 	struct list_head fs_supers;
 
 	struct lock_class_key s_lock_key;
Signature · 1 line
1.5.4.3
author
#2 lore raw

RFC PATCH 2/2 xfs: Make XFS use the new file system init infrastructure

This patch makes XFS use the file system type specific init and exit callbacks, so that XFS only initialises when it's used for the first time.

This is useful for when XFS is compiled into the kernel, but never actually used as it stops XFS from creating global threads, until they are needed.

---
 fs/xfs/linux-2.6/xfs_super.c |   55 +++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 25 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +30 -25
index 742b2c7..3e7340a 100644
@@ -1422,23 +1422,9 @@ static struct quotactl_ops xfs_quotactl_operations = {
 	.set_xquota		= xfs_fs_setxquota,
 };
 
-static struct file_system_type xfs_fs_type = {
-	.owner			= THIS_MODULE,
-	.name			= "xfs",
-	.get_sb			= xfs_fs_get_sb,
-	.kill_sb		= kill_block_super,
-	.fs_flags		= FS_REQUIRES_DEV,
-};
-
-
-STATIC int __init
-init_xfs_fs( void )
+static int xfs_fs_init(void)
 {
-	int			error;
-	static char		message[] __initdata = KERN_INFO \
-		XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
-
-	printk(message);
+	int error;
 
 	ktrace_init(64);
 
@@ -1455,14 +1441,8 @@ init_xfs_fs( void )
 	uuid_init();
 	vfs_initquota();
 
-	error = register_filesystem(&xfs_fs_type);
-	if (error)
-		goto undo_register;
 	return 0;
 
-undo_register:
-	xfs_buf_terminate();
-
 undo_buffers:
 	xfs_destroy_zones();
 
@@ -1470,17 +1450,42 @@ undo_zones:
 	return error;
 }
 
-STATIC void __exit
-exit_xfs_fs( void )
+static void xfs_fs_exit(void)
 {
 	vfs_exitquota();
-	unregister_filesystem(&xfs_fs_type);
 	xfs_cleanup();
 	xfs_buf_terminate();
 	xfs_destroy_zones();
 	ktrace_uninit();
 }
 
+static struct file_system_type xfs_fs_type = {
+	.owner			= THIS_MODULE,
+	.name			= "xfs",
+	.get_sb			= xfs_fs_get_sb,
+	.kill_sb		= kill_block_super,
+	.fs_flags		= FS_REQUIRES_DEV,
+	.init			= xfs_fs_init,
+	.exit			= xfs_fs_exit,
+};
+
+
+STATIC int __init
+init_xfs_fs( void )
+{
+	static char		message[] __initdata = KERN_INFO \
+		XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
+
+	printk(message);
+	return register_filesystem(&xfs_fs_type);
+}
+
+STATIC void __exit
+exit_xfs_fs( void )
+{
+	unregister_filesystem(&xfs_fs_type);
+}
+
 module_init(init_xfs_fs);
 module_exit(exit_xfs_fs);
 
Signature · 1 line
1.5.4.3
maintainer
#3 lore raw

Re: [RFC PATCH 1/2] vfs: Introduce on-demand filesystem initialisation

In reply to Tom Spink

On Sun, Jun 01, 2008 at 03:51:54PM +0100, Tom Spink wrote:

Occam's Razor...

You've just serialized ->kill_sb() for given fs type (and made sure that if one gets stuck, _everything_ gets stuck). Moreover, you've serialized sget() against the same thing (i.e. pretty much each ->get_sb()).

All of that (and a couple of new methods) is done for something that just plain does not belong to VFS. It's trivially doable in filesystem *and* it's about the objects with lifetimes that make sense only for filesystem itself.

Hell, just do

int want_xfs_threads(void)

{
	int res = 0;
	mutex_lock(&foo_lock);
	if (!count++) {
		start threads
		if failed {
			count--;
			res = -Esomething;
		}
	}
	mutex_unlock(&foo_lock);
	return res;
}

void leave_xfs_threads(void)

{
	mutex_lock(&foo_lock);
	if (!--count)
		stop threads
	mutex_unlock(&foo_lock);
}

Call want_xfs_threads() in xfs_fs_fill_super(); call leave_xfs_threads() in the end of xfs_put_super() and on failure exit from xfs_fs_fill_super(). End of story... Any other fs that wants such things can do the same.

author
#4 lore raw

Re: [RFC PATCH 1/2] vfs: Introduce on-demand filesystem initialisation

2008/6/1 Al Viro <[email protected]>:

Quoted 5 lines · Tom Spink

Occam's Razor...

Quoted 8 lines

You've just serialized ->kill_sb() for given fs type (and made sure that if one gets stuck, _everything_ gets stuck). Moreover, you've serialized sget() against the same thing (i.e. pretty much each ->get_sb()).

All of that (and a couple of new methods) is done for something that just plain does not belong to VFS. It's trivially doable in filesystem *and* it's about the objects with lifetimes that make sense only for filesystem itself.

Okay! Thanks for reviewing, anyway. :-)

Signature · 1 line
Tom Spink
#5 lore raw
In reply to Tom Spink
Quoted 2 lines · Tom Spink

(resend to include CCs)

What cc's? Still no xfs cc on it. I added it to this reply....

Quoted 11 lines

This (short) patch series is another RFC for the patch that introduces on-demand filesystem initialisation. In addition to the original infrastructure implementation (with clean-ups), it changes XFS to use this new infrastructure.

I wrote a toy filesystem (testfs) to simulate scheduling/allocation delays and to torture the mount/unmount cycles. I didn't manage to deadlock the system in my tests. XFS also works as expected aswell, in that the global threads are not created until an XFS filesystem is mounted for the first time. When the last XFS filesystem is unmounted, the threads go away.

Please let me know what you think!

Why even bother? This is why we have /modular/ kernels - if you're not using XFS then don't load it and you won't see those pesky threads. That'll save on a bunch of memory as well because the xfs module ain't small (>480k on i386)....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#6 lore raw

2008/6/2 Dave Chinner <[email protected]>:

Quoted 16 lines · Tom Spink
Quoted 2 lines

(resend to include CCs)

What cc's? Still no xfs cc on it. I added it to this reply....

Quoted 10 lines

This (short) patch series is another RFC for the patch that introduces on-demand filesystem initialisation. In addition to the original infrastructure implementation (with clean-ups), it changes XFS to use this new infrastructure.

I wrote a toy filesystem (testfs) to simulate scheduling/allocation delays and to torture the mount/unmount cycles. I didn't manage to deadlock the system in my tests. XFS also works as expected aswell, in that the global threads are not created until an XFS filesystem is mounted for the first time. When the last XFS filesystem is unmounted, the threads go away.

Quoted 6 lines
Quoted 1 line

Please let me know what you think!

Why even bother? This is why we have /modular/ kernels - if you're not using XFS then don't load it and you won't see those pesky threads. That'll save on a bunch of memory as well because the xfs module ain't small (>480k on i386)....

Yeah, absolutely. But if the filesystem is built-in, you can't unload it.

Quoted 3 lines

Cheers,

Dave.

Thanks for taking a look, anyway!

Signature · 1 line
Tom Spink