Skip to contentSkip to conversation

v2: write_super clean up

PATCH In review Jiro SEKIBA 2 participants 7 messages Jul 19, 2009 – Jul 22, 2009 4 messages not in the archive NILFS2 filesystem

lore
Share & tools
lore
#0 lore raw

cover v2: write_super clean up

Hi, this is revised version of write_super clean up patch.

It reflects most of Konishi-san's comment, except the nilfs_discontined() inline functions to be renamed. That inline funcion is one of inline functions defined by single macro. So as Konishi-san said, I'd rather like to rename it as separate patch.

Any comments and suggestions are appreciate.

Thanks,

regards,

 fs/nilfs2/segment.c   |   12 +++++++++++-
 fs/nilfs2/super.c     |   16 +++++++---------
 fs/nilfs2/the_nilfs.h |   12 ++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)
Signature · 1 line
Jiro SEKIBA <[email protected]>
#2 lore raw

PATCH 1/3 nilfs2: fix disorder of nilfs_write_super in nilfs_sync_fs

In reply to a message not in the archive

fix disorder of nilfs_write_super in nilfs_sync_fs. commiting super block must be the end of the function so that every chanages are reflected.

---
 fs/nilfs2/super.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
fs/nilfs2/super.c +3 -2
index 8e2ec43..ba69601 100644
@@ -388,11 +388,12 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
 {
 	int err = 0;
 
-	nilfs_write_super(sb);
-
 	/* This function is called when super block should be written back */
 	if (wait)
 		err = nilfs_construct_segment(sb);
+
+	nilfs_write_super(sb);
+
 	return err;
 }
 
Signature · 1 line
1.5.6.5
#7 lore raw

PATCH 2/3 nilfs2: clean up nilfs_write_super

In reply to a message not in the archive

Separated conditions to check if syncing super block and alternative super block are required as inline functions to reuse the conditions.

---
 fs/nilfs2/super.c     |    9 +++------
 fs/nilfs2/the_nilfs.h |   12 ++++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)
fs/nilfs2/super.c +3 -6
index ba69601..d85b360 100644
@@ -368,17 +368,14 @@ static void nilfs_write_super(struct super_block *sb)
 
 	down_write(&nilfs->ns_sem);
 	if (!(sb->s_flags & MS_RDONLY)) {
-		struct nilfs_super_block **sbp = nilfs->ns_sbp;
 		u64 t = get_seconds();
-		int dupsb;
 
-		if (!nilfs_discontinued(nilfs) && t >= nilfs->ns_sbwtime[0] &&
-		    t < nilfs->ns_sbwtime[0] + NILFS_SB_FREQ) {
+		if (!nilfs_discontinued(nilfs) &&
+		    !nilfs_sb_need_update(nilfs, t)) {
 			up_write(&nilfs->ns_sem);
 			return;
 		}
-		dupsb = sbp[1] && t > nilfs->ns_sbwtime[1] + NILFS_ALTSB_FREQ;
-		nilfs_commit_super(sbi, dupsb);
+		nilfs_commit_super(sbi, nilfs_altsb_need_update(nilfs, t));
 	}
 	sb->s_dirt = 0;
 	up_write(&nilfs->ns_sem);
fs/nilfs2/the_nilfs.h +12 -0
index e8adbff..0a77fb5 100644
@@ -202,6 +202,18 @@ THE_NILFS_FNS(DISCONTINUED, discontinued)
 #define NILFS_SB_FREQ		10
 #define NILFS_ALTSB_FREQ	60  /* spare superblock */
 
+static inline int nilfs_sb_need_update(struct the_nilfs *nilfs, u64 t)
+{
+	return t < nilfs->ns_sbwtime[0] ||
+		 t > nilfs->ns_sbwtime[0] + NILFS_SB_FREQ;
+}
+
+static inline int nilfs_altsb_need_update(struct the_nilfs *nilfs, u64 t)
+{
+	struct nilfs_super_block **sbp = nilfs->ns_sbp;
+	return sbp[1] && t > nilfs->ns_sbwtime[1] + NILFS_ALTSB_FREQ;
+}
+
 void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64);
 struct the_nilfs *find_or_create_nilfs(struct block_device *);
 void put_nilfs(struct the_nilfs *);
Signature · 1 line
1.5.6.5
#8 lore raw

PATCH 3/3 nilfs2: stop using periodic write_super callback

In reply to a message not in the archive

This patch makes commiting super block in nilfs internal thread, instead of periodic write_super callback.

VFS layer calls ->write_super callback periodically. However, it looks like that calling back is ommited when disk I/O is busy. And when cleanerd (nilfs GC) is runnig, disk I/O tend to be busy thus nilfs superblock is not synchronized as nilfs designed.

To avoid it, syncing superblock by nilfs thread instead of pdflush.

---
 fs/nilfs2/segment.c |   12 +++++++++++-
 fs/nilfs2/super.c   |    2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)
fs/nilfs2/segment.c +11 -1
index 8b5e477..46f7a49 100644
@@ -2486,8 +2486,10 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci,
 			atomic_set(&nilfs->ns_ndirtyblks, 0);
 		if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) &&
 		    nilfs_discontinued(nilfs)) {
+			u64 t = get_seconds();
 			down_write(&nilfs->ns_sem);
-			req->sb_err = nilfs_commit_super(sbi, 0);
+			req->sb_err = nilfs_commit_super(sbi,
+					nilfs_altsb_need_update(nilfs, t));
 			up_write(&nilfs->ns_sem);
 		}
 	}
@@ -2675,6 +2677,9 @@ static int nilfs_segctor_thread(void *arg)
 	} else {
 		DEFINE_WAIT(wait);
 		int should_sleep = 1;
+		u64 t;
+		struct nilfs_sb_info *sbi;
+		struct the_nilfs *nilfs;
 
 		prepare_to_wait(&sci->sc_wait_daemon, &wait,
 				TASK_INTERRUPTIBLE);
@@ -2695,6 +2700,11 @@ static int nilfs_segctor_thread(void *arg)
 		finish_wait(&sci->sc_wait_daemon, &wait);
 		timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
 			   time_after_eq(jiffies, sci->sc_timer->expires));
+		t = get_seconds();
+		sbi = sci->sc_sbi;
+		nilfs = sbi->s_nilfs;
+		if (sci->sc_super->s_dirt && nilfs_sb_need_update(nilfs, t))
+			set_nilfs_discontinued(nilfs);
 	}
 	goto loop;
 
fs/nilfs2/super.c +1 -1
index d85b360..a8c5875 100644
@@ -534,7 +534,7 @@ static struct super_operations nilfs_sops = {
 	/* .drop_inode	  = nilfs_drop_inode, */
 	.delete_inode   = nilfs_delete_inode,
 	.put_super      = nilfs_put_super,
-	.write_super    = nilfs_write_super,
+	/* .write_super    = nilfs_write_super, */
 	.sync_fs        = nilfs_sync_fs,
 	/* .write_super_lockfs */
 	/* .unlockfs */
Signature · 1 line
1.5.6.5
#4 lore raw

Re: [PATCH 1/3] nilfs2: fix disorder of nilfs_write_super in nilfs_sync_fs

In reply to a message not in the archive

Hi,

Quoted 15 lines · Jiro SEKIBA

fix disorder of nilfs_write_super in nilfs_sync_fs. commiting super block must be the end of the function so that every chanages are reflected.

---
 fs/nilfs2/super.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
fs/nilfs2/super.c +0 -0
index 8e2ec43..ba69601 100644
@@ -388,11 +388,12 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
 {

fs/nilfs2/super.c static int nilfs_sync_fs(struct super_block *sb, int wait) · line 396

Quoted 10 lines
fs/nilfs2/super.c +3 -2
 	int err = 0;
 
-	nilfs_write_super(sb);
-
 	/* This function is called when super block should be written back */
 	if (wait)
 		err = nilfs_construct_segment(sb);
+
+	nilfs_write_super(sb);
+

I read callers of the sync_fs callback, and I felt that nilfs_sync_fs() would rather call nilfs_commit_super() directly.

nilfs_write_super is written to handle periodic callback, and it moderates frequency of actual write back.

Is sync_fs called periodically or frequently?

If neither was, I think it's only necessary to do:

    down_write(&nilfs->ns_sem);
    if (sb->s_dirt)
        nilfs_commit_super(NILFS_SB(sb), 1);
    up_write(&nilfs->ns_sem);

Note that ->sync_fs() is not called for read-only filesystems.

The recent migration of write_super into sync_fs made this transformation possible.

Thanks,
Ryusuke Konishi

Quoted 10 lines
fs/nilfs2/super.c +0 -0
 	return err;
 }
 
Signature · 6 lines
1.5.6.5

_______________________________________________
users mailing list
[email protected]
https://www.nilfs.org/mailman/listinfo/users
#10 lore raw

Re: [PATCH 3/3] nilfs2: stop using periodic write_super callback

In reply to a message not in the archive
Quoted 11 lines · Jiro SEKIBA

This patch makes commiting super block in nilfs internal thread, instead of periodic write_super callback.

VFS layer calls ->write_super callback periodically. However, it looks like that calling back is ommited when disk I/O is busy. And when cleanerd (nilfs GC) is runnig, disk I/O tend to be busy thus nilfs superblock is not synchronized as nilfs designed.

To avoid it, syncing superblock by nilfs thread instead of pdflush.

Thanks.

If you replaced nilfs_write_super() in nilfs_sync_super(), you can get rid of nilfs_write_super() in this patch including the comments and prototype declaration for it.

Here are a few additional comments on that condition.

Quoted 10 lines
---
 fs/nilfs2/segment.c |   12 +++++++++++-
 fs/nilfs2/super.c   |    2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)
fs/nilfs2/segment.c +0 -0
index 8b5e477..46f7a49 100644

fs/nilfs2/segment.c static int nilfs_segctor_construct(struct nilfs_sc_info *sci, · line 2493

Quoted 9 lines
fs/nilfs2/segment.c +3 -1
@@ -2486,8 +2486,10 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci,
 			atomic_set(&nilfs->ns_ndirtyblks, 0);
 		if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) &&
 		    nilfs_discontinued(nilfs)) {
+			u64 t = get_seconds();
 			down_write(&nilfs->ns_sem);
-			req->sb_err = nilfs_commit_super(sbi, 0);
+			req->sb_err = nilfs_commit_super(sbi,
+					nilfs_altsb_need_update(nilfs, t));
 			up_write(&nilfs->ns_sem);

You can hide get_seconds() inside nilfs_sb_need_update() and nilfs_altsb_need_update() especially if you will get rid of nilfs_write_super().

Quoted 13 lines
fs/nilfs2/segment.c +3 -0
 		}
 	}
@@ -2675,6 +2677,9 @@ static int nilfs_segctor_thread(void *arg)
 	} else {
 		DEFINE_WAIT(wait);
 		int should_sleep = 1;
+		u64 t;
+		struct nilfs_sb_info *sbi;
+		struct the_nilfs *nilfs;
 
 		prepare_to_wait(&sci->sc_wait_daemon, &wait,
 				TASK_INTERRUPTIBLE);

fs/nilfs2/segment.c static int nilfs_segctor_thread(void *arg) · line 2707

Quoted 8 lines
fs/nilfs2/segment.c +5 -0
@@ -2695,6 +2700,11 @@ static int nilfs_segctor_thread(void *arg)
 		finish_wait(&sci->sc_wait_daemon, &wait);
 		timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
 			   time_after_eq(jiffies, sci->sc_timer->expires));
+		t = get_seconds();
+		sbi = sci->sc_sbi;
+		nilfs = sbi->s_nilfs;
+		if (sci->sc_super->s_dirt && nilfs_sb_need_update(nilfs, t))
+			set_nilfs_discontinued(nilfs);

ditto.

And the sbi local variable seems omissible.

Quoted 19 lines
fs/nilfs2/segment.c +0 -0
 	}
 	goto loop;
 
fs/nilfs2/super.c +1 -1
index d85b360..a8c5875 100644
@@ -534,7 +534,7 @@ static struct super_operations nilfs_sops = {
 	/* .drop_inode	  = nilfs_drop_inode, */
 	.delete_inode   = nilfs_delete_inode,
 	.put_super      = nilfs_put_super,
-	.write_super    = nilfs_write_super,
+	/* .write_super    = nilfs_write_super, */
 	.sync_fs        = nilfs_sync_fs,
 	/* .write_super_lockfs */
 	/* .unlockfs */
Signature · 1 line
1.5.6.5

Thanks,
Ryusuke Konishi

#6 lore raw

Re: [PATCH 1/3] nilfs2: fix disorder of nilfs_write_super in nilfs_sync_fs

In reply to a message not in the archive

Hi,

At Sun, 19 Jul 2009 19:53:58 +0900 (JST),

Quoted 32 lines · Ryusuke Konishi

Hi,

Quoted 15 lines · Jiro SEKIBA

fix disorder of nilfs_write_super in nilfs_sync_fs. commiting super block must be the end of the function so that every chanages are reflected.

---
 fs/nilfs2/super.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
fs/nilfs2/super.c +0 -0
index 8e2ec43..ba69601 100644
@@ -388,11 +388,12 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
 {

fs/nilfs2/super.c static int nilfs_sync_fs(struct super_block *sb, int wait) · line 396

Quoted 10 lines
fs/nilfs2/super.c +3 -2
 	int err = 0;
 
-	nilfs_write_super(sb);
-
 	/* This function is called when super block should be written back */
 	if (wait)
 		err = nilfs_construct_segment(sb);
+
+	nilfs_write_super(sb);
+

I read callers of the sync_fs callback, and I felt that nilfs_sync_fs() would rather call nilfs_commit_super() directly.

Quoted 4 lines

nilfs_write_super is written to handle periodic callback, and it moderates frequency of actual write back.

Is sync_fs called periodically or frequently?

I added printk in nilfs_sync_fs and nilfs_write_super. As you mentioned, nilfs_sync_fs is not called periodically nor frequently like nilfs_write_super.

Quoted 8 lines

If neither was, I think it's only necessary to do:

    down_write(&nilfs->ns_sem);
    if (sb->s_dirt)
        nilfs_commit_super(NILFS_SB(sb), 1);
    up_write(&nilfs->ns_sem);

Note that ->sync_fs() is not called for read-only filesystems.

So this change be applicable.

thank you for the comments! I'll revise patches and resent it.

Quoted 23 lines

The recent migration of write_super into sync_fs made this transformation possible.

Thanks,
Ryusuke Konishi

Quoted 10 lines
fs/nilfs2/super.c +0 -0
 	return err;
 }
 
Signature · 6 lines
1.5.6.5

_______________________________________________
users mailing list
[email protected]
https://www.nilfs.org/mailman/listinfo/users

_______________________________________________
users mailing list
[email protected]
https://www.nilfs.org/mailman/listinfo/users

Signature · 1 line
Jiro SEKIBA <[email protected]>