mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-23 20:24:12 +08:00
vfs: optimize touch_time() too
Do a similar optimization as earlier for touch_atime. Getting the lock in mnt_get_write is relatively costly, so try all avenues to avoid it first. This patch is careful to still only update inode fields inside the lock region. This didn't show up in benchmarks, but it's easy enough to do. [akpm@linux-foundation.org: fix typo in comment] [hugh.dickins@tiscali.co.uk: fix inverted test of mnt_want_write_file()] Signed-off-by: Andi Kleen <ak@linux.intel.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Valerie Aurora <vaurora@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
b12536c270
commit
ce06e0b21d
43
fs/inode.c
43
fs/inode.c
@ -1461,34 +1461,37 @@ void file_update_time(struct file *file)
|
|||||||
{
|
{
|
||||||
struct inode *inode = file->f_path.dentry->d_inode;
|
struct inode *inode = file->f_path.dentry->d_inode;
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
int sync_it = 0;
|
enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0;
|
||||||
int err;
|
|
||||||
|
|
||||||
|
/* First try to exhaust all avenues to not sync */
|
||||||
if (IS_NOCMTIME(inode))
|
if (IS_NOCMTIME(inode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err = mnt_want_write_file(file);
|
now = current_fs_time(inode->i_sb);
|
||||||
if (err)
|
if (!timespec_equal(&inode->i_mtime, &now))
|
||||||
|
sync_it = S_MTIME;
|
||||||
|
|
||||||
|
if (!timespec_equal(&inode->i_ctime, &now))
|
||||||
|
sync_it |= S_CTIME;
|
||||||
|
|
||||||
|
if (IS_I_VERSION(inode))
|
||||||
|
sync_it |= S_VERSION;
|
||||||
|
|
||||||
|
if (!sync_it)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
now = current_fs_time(inode->i_sb);
|
/* Finally allowed to write? Takes lock. */
|
||||||
if (!timespec_equal(&inode->i_mtime, &now)) {
|
if (mnt_want_write_file(file))
|
||||||
inode->i_mtime = now;
|
return;
|
||||||
sync_it = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timespec_equal(&inode->i_ctime, &now)) {
|
/* Only change inode inside the lock region */
|
||||||
inode->i_ctime = now;
|
if (sync_it & S_VERSION)
|
||||||
sync_it = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_I_VERSION(inode)) {
|
|
||||||
inode_inc_iversion(inode);
|
inode_inc_iversion(inode);
|
||||||
sync_it = 1;
|
if (sync_it & S_CTIME)
|
||||||
}
|
inode->i_ctime = now;
|
||||||
|
if (sync_it & S_MTIME)
|
||||||
if (sync_it)
|
inode->i_mtime = now;
|
||||||
mark_inode_dirty_sync(inode);
|
mark_inode_dirty_sync(inode);
|
||||||
mnt_drop_write(file->f_path.mnt);
|
mnt_drop_write(file->f_path.mnt);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(file_update_time);
|
EXPORT_SYMBOL(file_update_time);
|
||||||
|
Loading…
Reference in New Issue
Block a user