linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix abnormal long waiting in fsync
@ 2014-07-15  9:31 Liu Bo
  2014-07-15 10:22 ` Miao Xie
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Liu Bo @ 2014-07-15  9:31 UTC (permalink / raw)
  To: linux-btrfs

xfstests generic/127 detected this problem.

With commit 7fc34a62ca4434a79c68e23e70ed26111b7a4cf8, now fsync will only flush
data within the passed range.  This is the cause of the above problem,
-- btrfs's fsync has a stage called 'sync log' which will wait for all the
ordered extents it've recorded to finish.

In xfstests/generic/127, with mixed operations such as truncate, fallocate,
punch hole, and mapwrite, we get some pre-allocated extents, and mapwrite will
mmap, and then msync.  And I find that msync will wait for quite a long time
(about 20s in my case), thanks to ftrace, it turns out that the previous
fallocate calls 'btrfs_wait_ordered_range()' to flush dirty pages, but as the
range of dirty pages may be larger than 'btrfs_wait_ordered_range()' wants,
there can be some ordered extents created but not getting corresponding pages
flushed, then they're left in memory until we fsync which runs into the
stage 'sync log', and fsync will just wait for the system writeback thread
to flush those pages and get ordered extents finished, so the latency is
inevitable.

This adds a non-blocked flush, filemap_flush(), in btrfs_sync_file() to fix
that.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1f2b99c..1af395d 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2002,6 +2002,8 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 
 	if (ret != BTRFS_NO_LOG_SYNC) {
 		if (!ret) {
+			filemap_flush(inode->i_mapping);
+
 			ret = btrfs_sync_log(trans, root, &ctx);
 			if (!ret) {
 				ret = btrfs_end_transaction(trans, root);
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-07-17 12:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-15  9:31 [PATCH] Btrfs: fix abnormal long waiting in fsync Liu Bo
2014-07-15 10:22 ` Miao Xie
2014-07-15 10:41   ` constantine
2014-07-15 10:47   ` Liu Bo
2014-07-16  7:37 ` [PATCH v2] " Liu Bo
2014-07-16  9:36   ` Miao Xie
2014-07-17  3:00     ` Liu Bo
2014-07-17  8:08 ` [PATCH v3] " Liu Bo
2014-07-17 12:36   ` Chris Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).