Skip to content

Commit 2f0264d

Browse files
committed
GFS2: Split data write & wait in fsync
Now that the data writing is part of fsync proper, we can split the waiting part out and do it later on. This reduces the number of waits that we do during fsync on average. There is also no need to take the i_mutex unless we are flushing metadata to disk, so we can move that to within the metadata flushing code. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 4c28d33 commit 2f0264d

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

‎fs/gfs2/file.c‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,39 +551,53 @@ static int gfs2_close(struct inode *inode, struct file *file)
551551
* @end: the end position in the file to sync
552552
* @datasync: set if we can ignore timestamp changes
553553
*
554-
* The VFS will flush data for us. We only need to worry
555-
* about metadata here.
554+
* We split the data flushing here so that we don't wait for the data
555+
* until after we've also sent the metadata to disk. Note that for
556+
* data=ordered, we will write & wait for the data at the log flush
557+
* stage anyway, so this is unlikely to make much of a difference
558+
* except in the data=writeback case.
559+
*
560+
* If the fdatawrite fails due to any reason except -EIO, we will
561+
* continue the remainder of the fsync, although we'll still report
562+
* the error at the end. This is to match filemap_write_and_wait_range()
563+
* behaviour.
556564
*
557565
* Returns: errno
558566
*/
559567

560568
static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
561569
int datasync)
562570
{
563-
struct inode *inode = file->f_mapping->host;
571+
struct address_space *mapping = file->f_mapping;
572+
struct inode *inode = mapping->host;
564573
int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC);
565574
struct gfs2_inode *ip = GFS2_I(inode);
566-
int ret;
575+
int ret, ret1 = 0;
567576

568-
ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
569-
if (ret)
570-
return ret;
571-
mutex_lock(&inode->i_mutex);
577+
if (mapping->nrpages) {
578+
ret1 = filemap_fdatawrite_range(mapping, start, end);
579+
if (ret1 == -EIO)
580+
return ret1;
581+
}
572582

573583
if (datasync)
574584
sync_state &= ~I_DIRTY_SYNC;
575585

576586
if (sync_state) {
587+
mutex_lock(&inode->i_mutex);
577588
ret = sync_inode_metadata(inode, 1);
578589
if (ret) {
579590
mutex_unlock(&inode->i_mutex);
580591
return ret;
581592
}
582593
gfs2_ail_flush(ip->i_gl);
594+
mutex_unlock(&inode->i_mutex);
583595
}
584596

585-
mutex_unlock(&inode->i_mutex);
586-
return 0;
597+
if (mapping->nrpages)
598+
ret = filemap_fdatawait_range(mapping, start, end);
599+
600+
return ret ? ret : ret1;
587601
}
588602

589603
/**

0 commit comments

Comments
 (0)