Skip to contentSkip to conversation

Interface proposal for dentry grouping

RFC New Glauber Costa 1 participant 6 messages Jul 25, 2011 VFS

lore
Share & tools
lore
#0 lore raw

cover Interface proposal for dentry grouping

Hello folks,

If you would remember, Pavel recently posted a series proposing a way of grouping entries in the dcache, in order to in the future limit the per-container dcache size growth
(http://article.gmane.org/gmane.linux.file-systems/53346).

At the time, a proper interface for proper operation of those entities was missing. This patchset contains my proposal on how to do so. Note that I am not reposting Pavel original series (+ changes) this time. This is on purpose, since I want to focus on the interface here.

So here's briefly what I am proposing:

* dentry groups are created per-mntpoint. Combined with our ability to bind mount, this means that we can specify a dentry group root to be at any arbitrary point of the filesystem.
* Also, per-mntpoint also ties the dentry groups to a fs-independent entity, instead of a super-block, which is tied to a filesystem / real mount.
* Any mount helper is able to pass arbitrary strings to mount(). I build on it by allowing the generic vfs code to parse these options. A reference to a super block is hard to obtain at this point, which is one more reason (given of course this interface will be liked) to tie this to a mntpoint, not sb.
* Although options to the vfs are a new thing introduced here, mount() is a natural way to specify attributes of a filesystem hierarchy, I believe.

Glauber Costa (5):
Accept per-mntpoint named options
introduce dentry_is_mob_root
parse options at mount operation
destroy 0-sized mobs
save mnt info in do_loopback.

 fs/dcache.c            |   11 ++++++
 fs/namespace.c         |   84 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/dcache.h |    1 +
 include/linux/mount.h  |    2 +
 4 files changed, 98 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.5.1
#1 lore raw

RFC 1/5 Accept per-mntpoint named options

This is the core patch of the proposed interface.
It basically consists of an option parser much like the one
some filesystems, like for instance the ext family, ships.
It does, however, have two fundamental differences:
* Since it is generic, it does not operate on a super block. Rather, a mountpoint, which is a file-system independent entity, is its argument. Per-mntpoint options are expected to be tweaked here.
* It modifies the option string to remove whatever option it handled. This allow us to chain this parser with whatever parser the underlying filesystem may have.

Its first option is vfs_dcache_size. It specifies how many dentries are allowed to exist at any given time in the dentry group that lives in this mount point.

---
 fs/namespace.c        |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mount.h |    2 +
 2 files changed, 67 insertions(+), 0 deletions(-)
fs/namespace.c +65 -0
index dffe6f4..3ccd264 100644
@@ -33,6 +33,7 @@
 #include <linux/fsnotify.h>
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+#include <linux/parser.h>
 #include "pnode.h"
 #include "internal.h"
 
@@ -2190,6 +2191,70 @@ int copy_mount_string(const void __user *data, char **where)
 	return 0;
 }
 
+static const match_table_t tokens = {
+	{1, "vfs_dcache_size=%u"},
+};
+
+int vfs_parse_options(char *options, struct vfsmount *mnt)
+{
+	substring_t args[MAX_OPT_ARGS];
+	unsigned int option;
+	char *p;
+	char *opt;
+	char *start = NULL;
+	
+	/* FIXME: remove options from original string */
+	if (!options)
+		return 1;
+
+	opt = kstrdup(options, GFP_KERNEL);
+	if (!opt)
+		return 0;
+	
+	start = opt;
+
+	while ((p = strsep(&opt, ",")) != NULL) {
+		int token;
+		if (!*p)
+			continue;
+
+		/*
+		 * Initialize args struct so we know whether arg was
+		 * found; some options take optional arguments.
+		 */
+		args[0].to = args[0].from = 0;
+		token = match_token(p, tokens, args);
+		switch (token) {
+		case 1:
+			if (args[0].from) {
+				if (match_int(&args[0], &option)) {
+					break;
+				}
+				else {
+					mnt->dcache_size = option;
+				}
+			}
+			else {
+				printk("did not give an option\n");
+				break;
+			}
+
+			if (!opt) /* it is the last option listed */
+				*(options + (p - start)) = '\0';
+			else
+				strcpy(options + (p - start), opt);
+			break;
+		default:
+			break;
+		}
+	}
+	kfree(start);
+
+	return 0;
+}
+
+
+
 /*
  * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to
  * be given to the mount() call (ie: read-only, no-dev, no-suid etc).
include/linux/mount.h +2 -0
index 604f122..cf50da2 100644
@@ -86,6 +86,8 @@ struct vfsmount {
 	int mnt_expiry_mark;		/* true if marked for expiry */
 	int mnt_pinned;
 	int mnt_ghosts;
+
+	unsigned int dcache_size;
 };
 
 struct file; /* forward dec */
Signature · 1 line
1.7.5.1
#2 lore raw

RFC 2/5 introduce dentry_is_mob_root

In reply to Glauber Costa

Very simple function to test if a given dentry is the root of a dentry group (mob)

---
 fs/dcache.c            |    6 ++++++
 include/linux/dcache.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)
fs/dcache.c +6 -0
index 39db354..0960b80 100644
@@ -3000,6 +3000,12 @@ rename_retry:
 	goto again;
 }
 
+
+int dentry_is_mob_root(struct dentry *root)
+{
+	return (root->d_flags & DCACHE_MOB_ROOT);
+}
+
 int dcache_new_mob(struct dentry *root)
 {
 	struct dentry_mob *dmob, *old = NULL;
include/linux/dcache.h +1 -0
index 7b1fdc1..fd137c7 100644
@@ -62,6 +62,7 @@ struct dentry_mob_stat {
 };
 
 int dcache_new_mob(struct dentry *root);
+int dentry_is_mob_root(struct dentry *root);
 int dcache_set_mob_size(struct dentry *de, unsigned long size);
 int dcache_get_mob_stat(struct dentry *de, struct dentry_mob_stat __user *stat);
 
Signature · 1 line
1.7.5.1
#3 lore raw

RFC 3/5 parse options at mount operation

In reply to Glauber Costa

This patch presents a proposed use of the just introduced interface. The caller is expected to have passed a vfs_dcache_size=%d option. If this is not true, nothing should be changed.

If such an option is present, however, two things can happen:
* A new dentry group (mob) is created, rooted at the given mount point. It has the size specified in the arguments.
* An existing dentry group (mob) is modified, such that the argument passed reflects the new maximum number of dentries.

Note that the existance of bind mounts allow us to specify dentry groups starting at any arbitrary point in the hierarchy.

---
 fs/namespace.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
fs/namespace.c +16 -0
index 3ccd264..0d8a53b 100644
@@ -2275,6 +2275,7 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
 	struct path path;
 	int retval = 0;
 	int mnt_flags = 0;
+	int dcache_size = 0;
 
 	/* Discard magic */
 	if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
@@ -2298,6 +2299,10 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
 	if (retval)
 		goto dput_out;
 
+
+	dcache_size = path.mnt->dcache_size;
+	vfs_parse_options(data_page, path.mnt);
+
 	/* Default to relatime unless overriden */
 	if (!(flags & MS_NOATIME))
 		mnt_flags |= MNT_RELATIME;
@@ -2334,6 +2339,17 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
 	else
 		retval = do_new_mount(&path, type_page, flags, mnt_flags,
 				      dev_name, data_page);
+
+
+	if (retval || !path.mnt->dcache_size)
+		goto dput_out;
+
+	if (!dentry_is_mob_root(path.mnt->mnt_mountpoint))
+		dcache_new_mob(path.mnt->mnt_mountpoint);
+	if (dcache_size != path.mnt->dcache_size)
+		dcache_set_mob_size(path.mnt->mnt_mountpoint, path.mnt->dcache_size);
+
+
 dput_out:
 	path_put(&path);
 	return retval;
Signature · 1 line
1.7.5.1
#4 lore raw

RFC 4/5 destroy 0-sized mobs

In reply to Glauber Costa

Our API should consider vfs_dcache_size=0 to mean that the dentry group should be destroyed. Nothing else is meaningful.

---
 fs/dcache.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
fs/dcache.c +5 -0
index 0960b80..c9e988d 100644
@@ -3044,6 +3044,11 @@ int dcache_set_mob_size(struct dentry *de, unsigned long size)
 	if (mob == &init_dentry_mob) /* for safety */
 		return 0;
 
+	if (size == 0) {
+		destroy_mob(de->d_mob);
+		return 0;
+	}
+
 	mob->nr_dentry_max = size;
 	usage = percpu_counter_sum_positive(&mob->nr_dentry);
 	if (usage > mob->nr_dentry_max)
Signature · 1 line
1.7.5.1
#5 lore raw

RFC 5/5 save mnt info in do_loopback.

In reply to Glauber Costa

It is overwritten by a new mnt structure, so save it.

---
 fs/namespace.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/namespace.c +3 -0
index 0d8a53b..1a67f0d 100644
@@ -1741,6 +1741,9 @@ static int do_loopback(struct path *path, char *old_name,
 		release_mounts(&umount_list);
 	}
 
+	mnt->dcache_size = path->mnt->dcache_size;
+	path->mnt = mnt;
+
 out:
 	up_write(&namespace_sem);
 	path_put(&old_path);
Signature · 1 line
1.7.5.1