linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>,
	Curt Wohlgemuth <curtw@google.com>,
	Al Viro <viro@ZenIV.linux.org.uk>, Jan Kara <jack@suse.cz>
Subject: [PATCH 5/5] vfs: Avoid unnecessary WB_SYNC_NONE writeback during sync(1)
Date: Wed, 27 Jul 2011 00:38:06 +0200	[thread overview]
Message-ID: <1311719886-1130-6-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1311719886-1130-1-git-send-email-jack@suse.cz>

wakeup_flusher_thread(0) will queue work doing complete writeback for
each flusher thread. Thus there is not much point in submitting another
work doing full inode WB_SYNC_NONE writeback by sync_filesystems(). So change
sync to do:
  wakeup_flusher_threads(0);
  for each filesystem
    WB_SYNC_ALL inode writeback
    sync_fs(wait=0)
  submit dirty buffers from all block devices
  for each filesystem
    sync_fs(wait=1)
  synchronous writeout of all block devices

  Note that this changes ordering of sync_fs() calls and inode writeback.
Previously we called sync_fs(wait=0) after WB_SYNC_NONE inode writeback and
before WB_SYNC_ALL inode writeback. Now we call it after WB_SYNC_ALL inode
writeback because there is no point in calling it while flusher threads woken
by wakeup_flusher_threads(0) are still writing out data and there is no easy
way to find out when work submitted by wakeup_flusher_threads() is finished.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/sync.c |   55 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/fs/sync.c b/fs/sync.c
index f07f991..ca40cda 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -28,15 +28,16 @@
  * speeds up the wait == 1 case since in that case write_inode() functions do
  * sync_dirty_buffer() and thus effectively write one block at a time.
  */
-static void __sync_filesystem(struct super_block *sb, int wait)
+static void __sync_filesystem(struct super_block *sb, int emergency)
 {
-	if (wait)
-		sync_inodes_sb(sb);
-	else
+	/* In case of emergency sync we don't want to wait for locks and IO */
+	if (unlikely(emergency))
 		writeback_inodes_sb(sb);
+	else
+		sync_inodes_sb(sb);
 
 	if (sb->s_op->sync_fs)
-		sb->s_op->sync_fs(sb, wait);
+		sb->s_op->sync_fs(sb, 0);
 }
 
 /*
@@ -60,11 +61,23 @@ int sync_filesystem(struct super_block *sb)
 	if (sb->s_flags & MS_RDONLY)
 		return 0;
 
-	__sync_filesystem(sb, 0);
+	/* Asynchronous pass of sync to speed things up */
+	writeback_inodes_sb(sb);
+	if (sb->s_op->sync_fs) {
+		ret = sb->s_op->sync_fs(sb, 0);
+		if (ret)
+			return ret;
+	}
 	ret = __sync_blockdev(sb->s_bdev, 0);
 	if (ret < 0)
 		return ret;
-	__sync_filesystem(sb, 1);
+	/* Synchronous pass of sync to guarantee data integrity */
+	sync_inodes_sb(sb);
+	if (sb->s_op->sync_fs) {
+		ret = sb->s_op->sync_fs(sb, 1);
+		if (ret)
+			return ret;
+	}
 	return __sync_blockdev(sb->s_bdev, 1);
 }
 EXPORT_SYMBOL_GPL(sync_filesystem);
@@ -79,9 +92,9 @@ static void sync_one_sb(struct super_block *sb, void *arg)
  * Sync all the data for all the filesystems (called by sys_sync() and
  * emergency sync)
  */
-static void sync_filesystems(int wait)
+static void sync_filesystems(int emergency)
 {
-	iterate_supers(sync_one_sb, &wait);
+	iterate_supers(sync_one_sb, &emergency);
 }
 
 static void sync_all_bdevs(int wait)
@@ -120,16 +133,34 @@ static void sync_all_bdevs(int wait)
 	iput(old_inode);
 }
 
+static void sb_sync_fs(struct super_block *sb, void *arg)
+{
+	/* Avoid read-only filesystems */
+	if (sb->s_flags & MS_RDONLY)
+		return;
+	if (sb->s_op->sync_fs)
+		sb->s_op->sync_fs(sb, 1);
+}
+
 /*
  * sync everything.  Start out by waking pdflush, because that writes back
  * all queues in parallel.
  */
 SYSCALL_DEFINE0(sync)
 {
+	/* Start flushing on all devices */
 	wakeup_flusher_threads(0);
+	/*
+	 * Above call queued work doing complete writeout on each filesystem.
+	 * Now we queue work which guarantees data integrity of all inodes
+	 * - not much should be left for it to write. The WB_SYNC_ALL inode
+	 * writeback also guarantees that sync_fs() is called after inodes
+	 * are written out and thus it can do meaningful work.
+	 */
 	sync_filesystems(0);
-	sync_filesystems(1);
 	sync_all_bdevs(0);
+	/* Call blocking ->sync_fs() for each filesystem */
+	iterate_supers(sb_sync_fs, NULL);
 	sync_all_bdevs(1);
 	if (unlikely(laptop_mode))
 		laptop_sync_completion();
@@ -142,8 +173,8 @@ static void do_sync_work(struct work_struct *work)
 	 * Sync twice to reduce the possibility we skipped some inodes / pages
 	 * because they were temporarily locked
 	 */
-	sync_filesystems(0);
-	sync_filesystems(0);
+	sync_filesystems(1);
+	sync_filesystems(1);
 	printk("Emergency Sync complete\n");
 	kfree(work);
 }
-- 
1.7.1


  parent reply	other threads:[~2011-07-26 22:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26 22:38 [PATCH 0/5 v2] Improve sync(2) handling Jan Kara
2011-07-26 22:38 ` [PATCH 1/5] vfs: Make sync(1) writeout also block device inodes Jan Kara
2011-07-27  9:44   ` Christoph Hellwig
2011-07-28 20:13     ` Jan Kara
2011-07-26 22:38 ` [PATCH 2/5] vfs: Move noop_backing_dev_info check from sync into writeback Jan Kara
2011-07-27  9:44   ` Christoph Hellwig
2011-07-26 22:38 ` [PATCH 3/5] quota: Split dquot_quota_sync() to writeback and cache flushing part Jan Kara
2011-07-27  8:26   ` Steven Whitehouse
2011-07-27  9:45   ` Christoph Hellwig
2011-07-26 22:38 ` [PATCH 4/5] quota: Move quota syncing to ->sync_fs method Jan Kara
2011-07-27  8:32   ` Steven Whitehouse
2011-07-27  9:46   ` Christoph Hellwig
2011-07-27 13:44   ` Dave Kleikamp
2011-07-26 22:38 ` Jan Kara [this message]
2011-07-27  9:52   ` [PATCH 5/5] vfs: Avoid unnecessary WB_SYNC_NONE writeback during sync(1) Christoph Hellwig
2011-07-28 17:42     ` Jan Kara
2011-07-28 20:37       ` Christoph Hellwig
2011-07-28 21:20         ` Curt Wohlgemuth
2011-07-29 11:09           ` Christoph Hellwig
2011-09-28 15:00 ` [PATCH 0/5 v2] Improve sync(2) handling Christoph Hellwig
2011-10-06 22:20   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311719886-1130-6-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=curtw@google.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).