Skip to contentSkip to conversation

Btrfs: do not do filemap_write_and_wait_range in fsync

PATCH In review Josef Bacik 2 participants 4 messages Apr 23, 2012 – Apr 24, 2012 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: do not do filemap_write_and_wait_range in fsync

We already do the btrfs_wait_ordered_range which will do this for us, so just remove this call so we don't call it twice. Thanks,

---
 fs/btrfs/file.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/file.c +6 -5
index f0da02b..0c8ed6a 100644
@@ -1492,14 +1492,15 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 	trace_btrfs_sync_file(file, datasync);
 
-	ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
-	if (ret)
-		return ret;
 	mutex_lock(&inode->i_mutex);
 
-	/* we wait first, since the writeback may change the inode */
+	/*
+	 * we wait first, since the writeback may change the inode, also wait
+	 * ordered range does a filemape_write_and_wait_range which is why we
+	 * don't do it above like other file systems.
+	 */
 	root->log_batch++;
-	btrfs_wait_ordered_range(inode, 0, (u64)-1);
+	btrfs_wait_ordered_range(inode, start, end);
 	root->log_batch++;
 
 	/*
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 13 lines · Josef Bacik

We already do the btrfs_wait_ordered_range which will do this for us, so just remove this call so we don't call it twice. Thanks,

---
 fs/btrfs/file.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/file.c +0 -0
index f0da02b..0c8ed6a 100644

fs/btrfs/file.c int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 1495

Quoted 7 lines
fs/btrfs/file.c +0 -3
@@ -1492,14 +1492,15 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 	trace_btrfs_sync_file(file, datasync);
 
-	ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
-	if (ret)
-		return ret;
 	mutex_lock(&inode->i_mutex);

Hmmm, I think there are some good benefits to doing the wait outside of the mutex.

The question is, do we need to do it again after we take the mutex? I tend to think no, if you're racing another write with the fsync, you get what you deserve.

-chris

#2 lore raw
Quoted 25 lines · Chris Mason
Quoted 13 lines · Josef Bacik

We already do the btrfs_wait_ordered_range which will do this for us, so just remove this call so we don't call it twice. Thanks,

---
 fs/btrfs/file.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/file.c +0 -0
index f0da02b..0c8ed6a 100644

fs/btrfs/file.c int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 1495

Quoted 7 lines
fs/btrfs/file.c +0 -3
@@ -1492,14 +1492,15 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 	trace_btrfs_sync_file(file, datasync);
 
-	ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
-	if (ret)
-		return ret;
 	mutex_lock(&inode->i_mutex);

Hmmm, I think there are some good benefits to doing the wait outside of the mutex.

Quoted 4 lines

The question is, do we need to do it again after we take the mutex? I tend to think no, if you're racing another write with the fsync, you get what you deserve.

Yeah I thought about this and I wasn't sure, the only reason I left it where it was is because of the log_batch thing, I'm not sure what exactly that does and I didn't want to mess with what we have. If that can be done outside the mutex then lets do that. Thanks,

Josef

#3 lore raw
Quoted 31 lines · Josef Bacik
Quoted 25 lines · Chris Mason
Quoted 13 lines · Josef Bacik

We already do the btrfs_wait_ordered_range which will do this for us, so just remove this call so we don't call it twice. Thanks,

---
 fs/btrfs/file.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
fs/btrfs/file.c +0 -0
index f0da02b..0c8ed6a 100644

fs/btrfs/file.c int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) · line 1495

Quoted 7 lines
fs/btrfs/file.c +0 -3
@@ -1492,14 +1492,15 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 	trace_btrfs_sync_file(file, datasync);
 
-	ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
-	if (ret)
-		return ret;
 	mutex_lock(&inode->i_mutex);

Hmmm, I think there are some good benefits to doing the wait outside of the mutex.

Quoted 4 lines

The question is, do we need to do it again after we take the mutex? I tend to think no, if you're racing another write with the fsync, you get what you deserve.

Quoted 4 lines

Yeah I thought about this and I wasn't sure, the only reason I left it where it was is because of the log_batch thing, I'm not sure what exactly that does and I didn't want to mess with what we have. If that can be done outside the mutex then lets do that. Thanks,

The log batch is just something to kick the logging code so that it knows there are more loggers coming in. It's the wait around for more changes thing.

-chris