Patchwork [RFC,v2,03/10] vfs: add one new mount option '-o hottrack'

login
register
mail settings
Submitter Zhiyong Wu
Date Sept. 23, 2012, 12:56 p.m.
Message ID <1348404995-14372-4-git-send-email-zwu.kernel@gmail.com>
Download mbox | patch
Permalink /patch/186226/
State Not Applicable
Headers show

Comments

Zhiyong Wu - Sept. 23, 2012, 12:56 p.m.
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>

  Introduce one new mount option '-o hottrack',
and add its parsing support.
  Its usage looks like:
   mount -o hottrack
   mount -o nouser,hottrack
   mount -o nouser,hottrack,loop
   mount -o hottrack,nouser

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
 fs/hot_tracking.c            |   34 ++++++++++++++++++++++++++++++++++
 fs/hot_tracking.h            |    1 +
 fs/super.c                   |    5 +++++
 include/linux/hot_tracking.h |    7 +++++++
 4 files changed, 47 insertions(+), 0 deletions(-)
Dave Chinner - Sept. 25, 2012, 9:28 a.m.
On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> 
>   Introduce one new mount option '-o hottrack',
> and add its parsing support.
>   Its usage looks like:
>    mount -o hottrack
>    mount -o nouser,hottrack
>    mount -o nouser,hottrack,loop
>    mount -o hottrack,nouser

I think that this option parsing should be done by the filesystem,
even though the tracking functionality is in the VFS. That way ony
the filesystems that can use the tracking information will turn it
on, rather than being able to turn it on for everything regardless
of whether it is useful or not.

Along those lines, just using a normal superblock flag to indicate
it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
don't need to allocate the sb->s_hot_info structure just to be able
to check whether we are tracking hot inodes or not.

This then means the hot inode tracking for the superblock can be
initialised by the filesystem as part of it's fill_super method,
along with the filesystem specific code that will use the hot
tracking information the VFS gathers....

Cheers,

Dave.
Zhiyong Wu - Sept. 26, 2012, 2:56 a.m.
On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
> On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
>> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>>
>>   Introduce one new mount option '-o hottrack',
>> and add its parsing support.
>>   Its usage looks like:
>>    mount -o hottrack
>>    mount -o nouser,hottrack
>>    mount -o nouser,hottrack,loop
>>    mount -o hottrack,nouser
>
> I think that this option parsing should be done by the filesystem,
> even though the tracking functionality is in the VFS. That way ony
> the filesystems that can use the tracking information will turn it
> on, rather than being able to turn it on for everything regardless
> of whether it is useful or not.
>
> Along those lines, just using a normal superblock flag to indicate
> it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
> don't need to allocate the sb->s_hot_info structure just to be able
> to check whether we are tracking hot inodes or not.
>
> This then means the hot inode tracking for the superblock can be
> initialised by the filesystem as part of it's fill_super method,
> along with the filesystem specific code that will use the hot
> tracking information the VFS gathers....
I can see what you mean, but don't know if other guys also agree with this.
If so, all FS specific code which use hot tracking feature wll have to add
the same chunk of code in it fill_super method. Is it good?

>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
Dave Chinner - Sept. 27, 2012, 2:20 a.m.
On Wed, Sep 26, 2012 at 10:56:08AM +0800, Zhi Yong Wu wrote:
> On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
> > On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
> >> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> >>
> >>   Introduce one new mount option '-o hottrack',
> >> and add its parsing support.
> >>   Its usage looks like:
> >>    mount -o hottrack
> >>    mount -o nouser,hottrack
> >>    mount -o nouser,hottrack,loop
> >>    mount -o hottrack,nouser
> >
> > I think that this option parsing should be done by the filesystem,
> > even though the tracking functionality is in the VFS. That way ony
> > the filesystems that can use the tracking information will turn it
> > on, rather than being able to turn it on for everything regardless
> > of whether it is useful or not.
> >
> > Along those lines, just using a normal superblock flag to indicate
> > it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
> > don't need to allocate the sb->s_hot_info structure just to be able
> > to check whether we are tracking hot inodes or not.
> >
> > This then means the hot inode tracking for the superblock can be
> > initialised by the filesystem as part of it's fill_super method,
> > along with the filesystem specific code that will use the hot
> > tracking information the VFS gathers....
> I can see what you mean, but don't know if other guys also agree with this.
> If so, all FS specific code which use hot tracking feature wll have to add
> the same chunk of code in it fill_super method. Is it good?

Most filesystems will only need to add 3-4 lines of code to their
existing parser, so it's not a big deal I think...

Cheers,

Dave.
Zhiyong Wu - Sept. 27, 2012, 2:30 a.m.
On Thu, Sep 27, 2012 at 10:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> On Wed, Sep 26, 2012 at 10:56:08AM +0800, Zhi Yong Wu wrote:
>> On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
>> > On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
>> >> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>> >>
>> >>   Introduce one new mount option '-o hottrack',
>> >> and add its parsing support.
>> >>   Its usage looks like:
>> >>    mount -o hottrack
>> >>    mount -o nouser,hottrack
>> >>    mount -o nouser,hottrack,loop
>> >>    mount -o hottrack,nouser
>> >
>> > I think that this option parsing should be done by the filesystem,
>> > even though the tracking functionality is in the VFS. That way ony
>> > the filesystems that can use the tracking information will turn it
>> > on, rather than being able to turn it on for everything regardless
>> > of whether it is useful or not.
>> >
>> > Along those lines, just using a normal superblock flag to indicate
>> > it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
>> > don't need to allocate the sb->s_hot_info structure just to be able
>> > to check whether we are tracking hot inodes or not.
>> >
>> > This then means the hot inode tracking for the superblock can be
>> > initialised by the filesystem as part of it's fill_super method,
>> > along with the filesystem specific code that will use the hot
>> > tracking information the VFS gathers....
>> I can see what you mean, but don't know if other guys also agree with this.
>> If so, all FS specific code which use hot tracking feature wll have to add
>> the same chunk of code in it fill_super method. Is it good?
>
> Most filesystems will only need to add 3-4 lines of code to their
> existing parser, so it's not a big deal I think...
OK, i try to do it. thanks a lot.
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
Zhiyong Wu - Sept. 27, 2012, 5:25 a.m.
On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
> On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
>> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>>
>>   Introduce one new mount option '-o hottrack',
>> and add its parsing support.
>>   Its usage looks like:
>>    mount -o hottrack
>>    mount -o nouser,hottrack
>>    mount -o nouser,hottrack,loop
>>    mount -o hottrack,nouser
>
> I think that this option parsing should be done by the filesystem,
> even though the tracking functionality is in the VFS. That way ony
> the filesystems that can use the tracking information will turn it
> on, rather than being able to turn it on for everything regardless
> of whether it is useful or not.
>
> Along those lines, just using a normal superblock flag to indicate
> it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
> don't need to allocate the sb->s_hot_info structure just to be able
If we don't allocate one sb->s_hot_info, where will those hash list
head and btree roots locate?

> to check whether we are tracking hot inodes or not.
>
> This then means the hot inode tracking for the superblock can be
> initialised by the filesystem as part of it's fill_super method,
> along with the filesystem specific code that will use the hot
> tracking information the VFS gathers....
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
Dave Chinner - Sept. 27, 2012, 7:05 a.m.
On Thu, Sep 27, 2012 at 01:25:34PM +0800, Zhi Yong Wu wrote:
> On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
> > On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
> >> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> >>
> >>   Introduce one new mount option '-o hottrack',
> >> and add its parsing support.
> >>   Its usage looks like:
> >>    mount -o hottrack
> >>    mount -o nouser,hottrack
> >>    mount -o nouser,hottrack,loop
> >>    mount -o hottrack,nouser
> >
> > I think that this option parsing should be done by the filesystem,
> > even though the tracking functionality is in the VFS. That way ony
> > the filesystems that can use the tracking information will turn it
> > on, rather than being able to turn it on for everything regardless
> > of whether it is useful or not.
> >
> > Along those lines, just using a normal superblock flag to indicate
> > it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
> > don't need to allocate the sb->s_hot_info structure just to be able
> If we don't allocate one sb->s_hot_info, where will those hash list
> head and btree roots locate?

I wrote that thinking (mistakenly) that s-hot)info was dynamically
allocated rather than being embedded in the struct super_block.

Indeed, if the mount option is held in s_flags, then it could be
dynamically allocated, but I don't think that's really necessary...

Cheers,

Dave.
Zhiyong Wu - Sept. 27, 2012, 7:21 a.m.
On Thu, Sep 27, 2012 at 3:05 PM, Dave Chinner <david@fromorbit.com> wrote:
> On Thu, Sep 27, 2012 at 01:25:34PM +0800, Zhi Yong Wu wrote:
>> On Tue, Sep 25, 2012 at 5:28 PM, Dave Chinner <david@fromorbit.com> wrote:
>> > On Sun, Sep 23, 2012 at 08:56:28PM +0800, zwu.kernel@gmail.com wrote:
>> >> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>> >>
>> >>   Introduce one new mount option '-o hottrack',
>> >> and add its parsing support.
>> >>   Its usage looks like:
>> >>    mount -o hottrack
>> >>    mount -o nouser,hottrack
>> >>    mount -o nouser,hottrack,loop
>> >>    mount -o hottrack,nouser
>> >
>> > I think that this option parsing should be done by the filesystem,
>> > even though the tracking functionality is in the VFS. That way ony
>> > the filesystems that can use the tracking information will turn it
>> > on, rather than being able to turn it on for everything regardless
>> > of whether it is useful or not.
>> >
>> > Along those lines, just using a normal superblock flag to indicate
>> > it is active (e.g. MS_HOT_INODE_TRACKING in sb->s_flags) means you
>> > don't need to allocate the sb->s_hot_info structure just to be able
>> If we don't allocate one sb->s_hot_info, where will those hash list
>> head and btree roots locate?
>
> I wrote that thinking (mistakenly) that s-hot)info was dynamically
> allocated rather than being embedded in the struct super_block.
>
> Indeed, if the mount option is held in s_flags, then it could be
> dynamically allocated, but I don't think that's really necessary...
ah, you prefer allocating it, OK, let me try. thanks for your explaination.

>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com

Patch

diff --git a/fs/hot_tracking.c b/fs/hot_tracking.c
index 52ed926..f97e8a6 100644
--- a/fs/hot_tracking.c
+++ b/fs/hot_tracking.c
@@ -465,6 +465,40 @@  void hot_rb_update_freqs(struct inode *inode, u64 start,
 }
 
 /*
+ * Regular mount options parser for -hottrack option.
+ * return false if no -hottrack is specified;
+ * otherwise return true. And the -hottrack will be
+ * removed from options.
+ */
+bool hot_track_parse_options(char *options)
+{
+	long len;
+	char *p;
+	static char opts_hot[] = "hottrack";
+
+	if (!options)
+		return false;
+
+	p = strstr(options, opts_hot);
+	if (!p)
+		return false;
+
+	while (p) {
+		len = options + strlen(options) - (p + strlen(opts_hot));
+		if (len == 0) {
+			options[0] = '\0';
+			break;
+		}
+
+		memmove(p, p + strlen(opts_hot) + 1, len);
+		p = strstr(options, opts_hot);
+	}
+
+	printk(KERN_INFO "vfs: turning on hot data tracking\n");
+	return true;
+}
+
+/*
  * Initialize kmem cache for hot_inode_item
  * and hot_range_item
  */
diff --git a/fs/hot_tracking.h b/fs/hot_tracking.h
index 2ba29e4..6bd09eb 100644
--- a/fs/hot_tracking.h
+++ b/fs/hot_tracking.h
@@ -37,6 +37,7 @@  void hot_rb_free_hot_inode_item(struct hot_inode_item *he);
 void hot_rb_update_freqs(struct inode *inode, u64 start, u64 len,
 			int rw);
 
+bool hot_track_parse_options(char *options);
 void __init hot_track_cache_init(void);
 
 #endif /* __HOT_TRACKING__ */
diff --git a/fs/super.c b/fs/super.c
index 0902cfa..7eb3b0c 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -34,6 +34,7 @@ 
 #include <linux/cleancache.h>
 #include <linux/fsnotify.h>
 #include <linux/lockdep.h>
+#include "hot_tracking.h"
 #include "internal.h"
 
 
@@ -1125,6 +1126,7 @@  mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
 	struct dentry *root;
 	struct super_block *sb;
 	char *secdata = NULL;
+	bool hottrack = false;
 	int error = -ENOMEM;
 
 	if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
@@ -1137,6 +1139,9 @@  mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
 			goto out_free_secdata;
 	}
 
+	if (data && hot_track_parse_options(data))
+		hottrack = true;
+
 	root = type->mount(type, flags, name, data);
 	if (IS_ERR(root)) {
 		error = PTR_ERR(root);
diff --git a/include/linux/hot_tracking.h b/include/linux/hot_tracking.h
index a566f91..bb2a41c 100644
--- a/include/linux/hot_tracking.h
+++ b/include/linux/hot_tracking.h
@@ -20,6 +20,11 @@ 
 #include <linux/rbtree.h>
 #include <linux/kref.h>
 
+/*
+ * Flags for hot data tracking mount options.
+ */
+#define HOT_MOUNT_HOT_TRACK		(1 << 0)
+
 /* A tree that sits on the hot_info */
 struct hot_inode_tree {
 	struct rb_root map;
@@ -89,6 +94,8 @@  struct hot_range_item {
 };
 
 struct hot_info {
+	unsigned long mount_opt;
+
 	/* red-black tree that keeps track of fs-wide hot data */
 	struct hot_inode_tree hot_inode_tree;
 };