diff options
author | Andreas Rohner <andreas.rohner@gmx.net> | 2014-12-10 18:54:29 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-10 20:41:16 -0500 |
commit | 75dc857c46996e336cb2f9cf0ed1e5508fb241a7 (patch) | |
tree | b8893865031ac34609d7991478a71483b3ce8a5f /fs/nilfs2/file.c | |
parent | 6528b889955d36caa06712789746cfbd0ecf3898 (diff) |
nilfs2: avoid duplicate segment construction for fsync()
This patch removes filemap_write_and_wait_range() from nilfs_sync_file(),
because it triggers a data segment construction by calling
nilfs_writepages() with WB_SYNC_ALL. A data segment construction does not
remove the inode from the i_dirty list and it does not clear the
NILFS_I_DIRTY flag. Therefore nilfs_inode_dirty() still returns true,
which leads to an unnecessary duplicate segment construction in
nilfs_sync_file().
A call to filemap_write_and_wait_range() is not needed, because NILFS2
does not rely on the generic writeback mechanisms. Instead it implements
its own mechanism to collect all dirty pages and write them into segments.
It is more efficient to initiate the segment construction directly in
nilfs_sync_file() without the detour over filemap_write_and_wait_range().
Additionally the lock of i_mutex is not needed, because all code blocks
that are protected by i_mutex are also protected by a NILFS transaction:
Function i_mutex nilfs_transaction
------------------------------------------------------
nilfs_ioctl_setflags: yes yes
nilfs_fiemap: yes no
nilfs_write_begin: yes yes
nilfs_write_end: yes yes
nilfs_lookup: yes no
nilfs_create: yes yes
nilfs_link: yes yes
nilfs_mknod: yes yes
nilfs_symlink: yes yes
nilfs_mkdir: yes yes
nilfs_unlink: yes yes
nilfs_rmdir: yes yes
nilfs_rename: yes yes
nilfs_setattr: yes yes
For nilfs_lookup() i_mutex is held for the parent directory, to protect it
from modification. The segment construction does not modify directory
inodes, so no lock is needed.
nilfs_fiemap() reads the block layout on the disk, by using
nilfs_bmap_lookup_contig(). This is already protected by bmap->b_sem.
Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2/file.c')
-rw-r--r-- | fs/nilfs2/file.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index e9e3325f29f3..3a03e0aea1fb 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c | |||
@@ -39,21 +39,15 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
39 | */ | 39 | */ |
40 | struct the_nilfs *nilfs; | 40 | struct the_nilfs *nilfs; |
41 | struct inode *inode = file->f_mapping->host; | 41 | struct inode *inode = file->f_mapping->host; |
42 | int err; | 42 | int err = 0; |
43 | |||
44 | err = filemap_write_and_wait_range(inode->i_mapping, start, end); | ||
45 | if (err) | ||
46 | return err; | ||
47 | mutex_lock(&inode->i_mutex); | ||
48 | 43 | ||
49 | if (nilfs_inode_dirty(inode)) { | 44 | if (nilfs_inode_dirty(inode)) { |
50 | if (datasync) | 45 | if (datasync) |
51 | err = nilfs_construct_dsync_segment(inode->i_sb, inode, | 46 | err = nilfs_construct_dsync_segment(inode->i_sb, inode, |
52 | 0, LLONG_MAX); | 47 | start, end); |
53 | else | 48 | else |
54 | err = nilfs_construct_segment(inode->i_sb); | 49 | err = nilfs_construct_segment(inode->i_sb); |
55 | } | 50 | } |
56 | mutex_unlock(&inode->i_mutex); | ||
57 | 51 | ||
58 | nilfs = inode->i_sb->s_fs_info; | 52 | nilfs = inode->i_sb->s_fs_info; |
59 | if (!err) | 53 | if (!err) |