Skip to content

Commit 1da2f2d

Browse files
Christoph HellwigAlex Elder
authored andcommitted
xfs: optimize fsync on directories
Directories are only updated transactionally, which means fsync only needs to flush the log the inode is currently dirty, but not bother with checking for dirty data, non-transactional updates, and most importanly doesn't have to flush disk caches except as part of a transaction commit. While the first two optimizations can't easily be measured, the latter actually makes a difference when doing lots of fsync that do not actually have to commit the inode, e.g. because an earlier fsync already pushed the log far enough. The new xfs_dir_fsync is identical to xfs_nfs_commit_metadata except for the prototype, but I'm not sure creating a common helper for the two is worth it given how simple the functions are. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Elder <aelder@sgi.com>
1 parent 670ce93 commit 1da2f2d

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎fs/xfs/xfs_file.c‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,35 @@ xfs_iozero(
124124
return (-status);
125125
}
126126

127+
/*
128+
* Fsync operations on directories are much simpler than on regular files,
129+
* as there is no file data to flush, and thus also no need for explicit
130+
* cache flush operations, and there are no non-transaction metadata updates
131+
* on directories either.
132+
*/
133+
STATIC int
134+
xfs_dir_fsync(
135+
struct file *file,
136+
loff_t start,
137+
loff_t end,
138+
int datasync)
139+
{
140+
struct xfs_inode *ip = XFS_I(file->f_mapping->host);
141+
struct xfs_mount *mp = ip->i_mount;
142+
xfs_lsn_t lsn = 0;
143+
144+
trace_xfs_dir_fsync(ip);
145+
146+
xfs_ilock(ip, XFS_ILOCK_SHARED);
147+
if (xfs_ipincount(ip))
148+
lsn = ip->i_itemp->ili_last_lsn;
149+
xfs_iunlock(ip, XFS_ILOCK_SHARED);
150+
151+
if (!lsn)
152+
return 0;
153+
return _xfs_log_force_lsn(mp, lsn, XFS_LOG_SYNC, NULL);
154+
}
155+
127156
STATIC int
128157
xfs_file_fsync(
129158
struct file *file,
@@ -1140,7 +1169,7 @@ const struct file_operations xfs_dir_file_operations = {
11401169
#ifdef CONFIG_COMPAT
11411170
.compat_ioctl = xfs_file_compat_ioctl,
11421171
#endif
1143-
.fsync = xfs_file_fsync,
1172+
.fsync = xfs_dir_fsync,
11441173
};
11451174

11461175
static const struct vm_operations_struct xfs_file_vm_ops = {

‎fs/xfs/xfs_trace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ DEFINE_INODE_EVENT(xfs_vm_bmap);
576576
DEFINE_INODE_EVENT(xfs_file_ioctl);
577577
DEFINE_INODE_EVENT(xfs_file_compat_ioctl);
578578
DEFINE_INODE_EVENT(xfs_ioctl_setattr);
579+
DEFINE_INODE_EVENT(xfs_dir_fsync);
579580
DEFINE_INODE_EVENT(xfs_file_fsync);
580581
DEFINE_INODE_EVENT(xfs_destroy_inode);
581582
DEFINE_INODE_EVENT(xfs_write_inode);

0 commit comments

Comments
 (0)