On-demand Filesystem Initialisation
Subsystems (2)
cover On-demand Filesystem Initialisation
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(-)
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
@@ -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
@@ -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
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
@@ -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
Re: [RFC PATCH 2/2] xfs: Make XFS use the new file system init infrastructure
Quoted 7 lines · Tom Spink
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.
Yes please. Removing gazillion kernel threads when xfs is unused is nice.
You should probably have cced fsdevel and xfs lists?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [RFC PATCH 2/2] xfs: Make XFS use the new file system init infrastructure
2008/5/31 Pavel Machek <[email protected]>:
Quoted 9 lines · Tom Spink
Quoted 7 lines
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.
Quoted 9 lines
Yes please. Removing gazillion kernel threads when xfs is unused is nice.
You should probably have cced fsdevel and xfs lists?
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
I'll re-send with those CC's!
Signature · 1 line
Tom Spink