浏览代码

fs: introduce mnt_clone_write

This patch speeds up lmbench lat_mmap test by about another 2% after the
first patch.

Before:
 avg = 462.286
 std = 5.46106

After:
 avg = 453.12
 std = 9.58257

(50 runs of each, stddev gives a reasonable confidence)

It does this by introducing mnt_clone_write, which avoids some heavyweight
operations of mnt_want_write if called on a vfsmount which we know already
has a write count; and mnt_want_write_file, which can call mnt_clone_write
if the file is open for write.

After these two patches, mnt_want_write and mnt_drop_write go from 7% on
the profile down to 1.3% (including mnt_clone_write).

[AV: mnt_want_write_file() should take file alone and derive mnt from it;
not only all callers have that form, but that's the only mnt about which
we know that it's already held for write if file is opened for write]

Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
npiggin@suse.de 16 年之前
父节点
当前提交
96029c4e09
共有 6 个文件被更改,包括 50 次插入6 次删除
  1. 1 1
      fs/file_table.c
  2. 1 1
      fs/inode.c
  3. 40 0
      fs/namespace.c
  4. 2 2
      fs/open.c
  5. 2 2
      fs/xattr.c
  6. 4 0
      include/linux/mount.h

+ 1 - 1
fs/file_table.c

@@ -214,7 +214,7 @@ int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
 	 */
 	 */
 	if ((mode & FMODE_WRITE) && !special_file(dentry->d_inode->i_mode)) {
 	if ((mode & FMODE_WRITE) && !special_file(dentry->d_inode->i_mode)) {
 		file_take_write(file);
 		file_take_write(file);
-		error = mnt_want_write(mnt);
+		error = mnt_clone_write(mnt);
 		WARN_ON(error);
 		WARN_ON(error);
 	}
 	}
 	return error;
 	return error;

+ 1 - 1
fs/inode.c

@@ -1422,7 +1422,7 @@ void file_update_time(struct file *file)
 	if (IS_NOCMTIME(inode))
 	if (IS_NOCMTIME(inode))
 		return;
 		return;
 
 
-	err = mnt_want_write(file->f_path.mnt);
+	err = mnt_want_write_file(file);
 	if (err)
 	if (err)
 		return;
 		return;
 
 

+ 40 - 0
fs/namespace.c

@@ -264,6 +264,46 @@ out:
 }
 }
 EXPORT_SYMBOL_GPL(mnt_want_write);
 EXPORT_SYMBOL_GPL(mnt_want_write);
 
 
+/**
+ * mnt_clone_write - get write access to a mount
+ * @mnt: the mount on which to take a write
+ *
+ * This is effectively like mnt_want_write, except
+ * it must only be used to take an extra write reference
+ * on a mountpoint that we already know has a write reference
+ * on it. This allows some optimisation.
+ *
+ * After finished, mnt_drop_write must be called as usual to
+ * drop the reference.
+ */
+int mnt_clone_write(struct vfsmount *mnt)
+{
+	/* superblock may be r/o */
+	if (__mnt_is_readonly(mnt))
+		return -EROFS;
+	preempt_disable();
+	inc_mnt_writers(mnt);
+	preempt_enable();
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mnt_clone_write);
+
+/**
+ * mnt_want_write_file - get write access to a file's mount
+ * @file: the file who's mount on which to take a write
+ *
+ * This is like mnt_want_write, but it takes a file and can
+ * do some optimisations if the file is open for write already
+ */
+int mnt_want_write_file(struct file *file)
+{
+	if (!(file->f_mode & FMODE_WRITE))
+		return mnt_want_write(file->f_path.mnt);
+	else
+		return mnt_clone_write(file->f_path.mnt);
+}
+EXPORT_SYMBOL_GPL(mnt_want_write_file);
+
 /**
 /**
  * mnt_drop_write - give up write access to a mount
  * mnt_drop_write - give up write access to a mount
  * @mnt: the mount on which to give up write access
  * @mnt: the mount on which to give up write access

+ 2 - 2
fs/open.c

@@ -612,7 +612,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
 
 
 	audit_inode(NULL, dentry);
 	audit_inode(NULL, dentry);
 
 
-	err = mnt_want_write(file->f_path.mnt);
+	err = mnt_want_write_file(file);
 	if (err)
 	if (err)
 		goto out_putf;
 		goto out_putf;
 	mutex_lock(&inode->i_mutex);
 	mutex_lock(&inode->i_mutex);
@@ -761,7 +761,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
 	if (!file)
 	if (!file)
 		goto out;
 		goto out;
 
 
-	error = mnt_want_write(file->f_path.mnt);
+	error = mnt_want_write_file(file);
 	if (error)
 	if (error)
 		goto out_fput;
 		goto out_fput;
 	dentry = file->f_path.dentry;
 	dentry = file->f_path.dentry;

+ 2 - 2
fs/xattr.c

@@ -297,7 +297,7 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
 		return error;
 		return error;
 	dentry = f->f_path.dentry;
 	dentry = f->f_path.dentry;
 	audit_inode(NULL, dentry);
 	audit_inode(NULL, dentry);
-	error = mnt_want_write(f->f_path.mnt);
+	error = mnt_want_write_file(f);
 	if (!error) {
 	if (!error) {
 		error = setxattr(dentry, name, value, size, flags);
 		error = setxattr(dentry, name, value, size, flags);
 		mnt_drop_write(f->f_path.mnt);
 		mnt_drop_write(f->f_path.mnt);
@@ -524,7 +524,7 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
 		return error;
 		return error;
 	dentry = f->f_path.dentry;
 	dentry = f->f_path.dentry;
 	audit_inode(NULL, dentry);
 	audit_inode(NULL, dentry);
-	error = mnt_want_write(f->f_path.mnt);
+	error = mnt_want_write_file(f);
 	if (!error) {
 	if (!error) {
 		error = removexattr(dentry, name);
 		error = removexattr(dentry, name);
 		mnt_drop_write(f->f_path.mnt);
 		mnt_drop_write(f->f_path.mnt);

+ 4 - 0
include/linux/mount.h

@@ -88,7 +88,11 @@ static inline struct vfsmount *mntget(struct vfsmount *mnt)
 	return mnt;
 	return mnt;
 }
 }
 
 
+struct file; /* forward dec */
+
 extern int mnt_want_write(struct vfsmount *mnt);
 extern int mnt_want_write(struct vfsmount *mnt);
+extern int mnt_want_write_file(struct file *file);
+extern int mnt_clone_write(struct vfsmount *mnt);
 extern void mnt_drop_write(struct vfsmount *mnt);
 extern void mnt_drop_write(struct vfsmount *mnt);
 extern void mntput_no_expire(struct vfsmount *mnt);
 extern void mntput_no_expire(struct vfsmount *mnt);
 extern void mnt_pin(struct vfsmount *mnt);
 extern void mnt_pin(struct vfsmount *mnt);