Skip to contentSkip to conversation

fsck.f2fs: read ahead xattr & direct node blocks

PATCH Superseded Yunlei He 2 participants 2 messages Jan 29, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH v2 1/1 fsck.f2fs: read ahead xattr & direct node blocks

This patch read ahead xattr & direct node blocks, and keep the order:

1. check data blocks
2. readahead xattr block
3. fsck xattr block
4. readahead {d,id,did}node block
5. fsck {d,id,did}node block

With above order, we can avoid unneeded readahead before sub-directory iterated traversing or encountering error.

---
 fsck/fsck.c | 66 ++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 22 deletions(-)
fsck/fsck.c +44 -22
index 6c1b9a7..5c33892 100644
@@ -621,6 +621,29 @@ unmatched:
 	child->state |= FSCK_UNMATCHED_EXTENT;
 }
 
+void fsck_reada_node_block(struct f2fs_sb_info *sbi, u32 nid)
+{
+	struct node_info ni;
+
+	if (nid != 0 && IS_VALID_NID(sbi, nid)) {
+		get_node_info(sbi, nid, &ni);
+		if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+			dev_reada_block(ni.blk_addr);
+	}
+}
+
+void fsck_reada_all_direct_node_blocks(struct f2fs_sb_info *sbi,
+						struct f2fs_node *node_blk)
+{
+	int i;
+
+	for (i = 0; i < NIDS_PER_BLOCK; i++) {
+		u32 nid = le32_to_cpu(node_blk->in.nid[i]);
+
+		fsck_reada_node_block(sbi, nid);
+	}
+}
+
 /* start with valid nid and blkaddr */
 void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		enum FILE_TYPE ftype, struct f2fs_node *node_blk,
@@ -680,15 +703,6 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		}
 	}
 
-	if (fsck_chk_xattr_blk(sbi, nid,
-			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
-			c.fix_on) {
-		node_blk->i.i_xattr_nid = 0;
-		need_fix = 1;
-		FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
-				nid, le32_to_cpu(node_blk->i.i_xattr_nid));
-	}
-
 	if (ftype == F2FS_FT_CHRDEV || ftype == F2FS_FT_BLKDEV ||
 			ftype == F2FS_FT_FIFO || ftype == F2FS_FT_SOCK)
 		goto check;
@@ -736,19 +750,6 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		goto check;
 	}
 
-	/* readahead node blocks */
-	for (idx = 0; idx < 5; idx++) {
-		u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]);
-
-		if (nid != 0 && IS_VALID_NID(sbi, nid)) {
-			struct node_info ni;
-
-			get_node_info(sbi, nid, &ni);
-			if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
-				dev_reada_block(ni.blk_addr);
-		}
-	}
-
 	/* init extent info */
 	get_extent_info(&child.ei, &node_blk->i.i_ext);
 	child.last_blk = 0;
@@ -778,6 +779,23 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		}
 	}
 
+	/* readahead node blocks */
+	fsck_reada_node_block(sbi, le32_to_cpu(node_blk->i.i_xattr_nid));
+	for (idx = 0; idx < 5; idx++) {
+		u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]);
+		fsck_reada_node_block(sbi, nid);
+	}
+
+
+	if (fsck_chk_xattr_blk(sbi, nid,
+			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
+			c.fix_on) {
+		node_blk->i.i_xattr_nid = 0;
+		need_fix = 1;
+		FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
+				nid, le32_to_cpu(node_blk->i.i_xattr_nid));
+	}
+
 	/* check node blocks in inode */
 	for (idx = 0; idx < 5; idx++) {
 		nid_t i_nid = le32_to_cpu(node_blk->i.i_nid[idx]);
@@ -997,6 +1015,8 @@ int fsck_chk_idnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
 	int need_fix = 0, ret;
 	int i = 0;
 
+	fsck_reada_all_direct_node_blocks(sbi, node_blk);
+
 	for (i = 0; i < NIDS_PER_BLOCK; i++) {
 		if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
 			goto skip;
@@ -1037,6 +1057,8 @@ int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
 	int i = 0;
 	int need_fix = 0, ret = 0;
 
+	fsck_reada_all_direct_node_blocks(sbi, node_blk);
+
 	for (i = 0; i < NIDS_PER_BLOCK; i++) {
 		if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
 			goto skip;
Signature · 6 lines
1.9.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#1 lore raw
Quoted 94 lines · Yunlei He

This patch read ahead xattr & direct node blocks, and keep the order:

1. check data blocks
2. readahead xattr block
3. fsck xattr block
4. readahead {d,id,did}node block
5. fsck {d,id,did}node block

With above order, we can avoid unneeded readahead before sub-directory iterated traversing or encountering error.

---
 fsck/fsck.c | 66 ++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 22 deletions(-)
fsck/fsck.c +25 -22
index 6c1b9a7..5c33892 100644
@@ -621,6 +621,29 @@ unmatched:
 	child->state |= FSCK_UNMATCHED_EXTENT;
 }
 
+void fsck_reada_node_block(struct f2fs_sb_info *sbi, u32 nid)
+{
+	struct node_info ni;
+
+	if (nid != 0 && IS_VALID_NID(sbi, nid)) {
+		get_node_info(sbi, nid, &ni);
+		if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+			dev_reada_block(ni.blk_addr);
+	}
+}
+
+void fsck_reada_all_direct_node_blocks(struct f2fs_sb_info *sbi,
+						struct f2fs_node *node_blk)
+{
+	int i;
+
+	for (i = 0; i < NIDS_PER_BLOCK; i++) {
+		u32 nid = le32_to_cpu(node_blk->in.nid[i]);
+
+		fsck_reada_node_block(sbi, nid);
+	}
+}
+
 /* start with valid nid and blkaddr */
 void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		enum FILE_TYPE ftype, struct f2fs_node *node_blk,
@@ -680,15 +703,6 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		}
 	}
 
-	if (fsck_chk_xattr_blk(sbi, nid,
-			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
-			c.fix_on) {
-		node_blk->i.i_xattr_nid = 0;
-		need_fix = 1;
-		FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
-				nid, le32_to_cpu(node_blk->i.i_xattr_nid));
-	}
-
 	if (ftype == F2FS_FT_CHRDEV || ftype == F2FS_FT_BLKDEV ||
 			ftype == F2FS_FT_FIFO || ftype == F2FS_FT_SOCK)
 		goto check;
@@ -736,19 +750,6 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		goto check;
 	}
 
-	/* readahead node blocks */
-	for (idx = 0; idx < 5; idx++) {
-		u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]);
-
-		if (nid != 0 && IS_VALID_NID(sbi, nid)) {
-			struct node_info ni;
-
-			get_node_info(sbi, nid, &ni);
-			if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
-				dev_reada_block(ni.blk_addr);
-		}
-	}
-
 	/* init extent info */
 	get_extent_info(&child.ei, &node_blk->i.i_ext);
 	child.last_blk = 0;
@@ -778,6 +779,23 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		}
 	}
 
+	/* readahead node blocks */
+	fsck_reada_node_block(sbi, le32_to_cpu(node_blk->i.i_xattr_nid));
 
Quoted 2 lines

2. readahead xattr block
3. fsck xattr block

if (fsck_chk_xattr_blk()) {
...
}

Expect that, it looks good to me.

Thanks,

Quoted 29 lines
fsck/fsck.c +17 -0
+	for (idx = 0; idx < 5; idx++) {
+		u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]);
+		fsck_reada_node_block(sbi, nid);
+	}
+
+
+	if (fsck_chk_xattr_blk(sbi, nid,
+			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
+			c.fix_on) {
+		node_blk->i.i_xattr_nid = 0;
+		need_fix = 1;
+		FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
+				nid, le32_to_cpu(node_blk->i.i_xattr_nid));
+	}
+
 	/* check node blocks in inode */
 	for (idx = 0; idx < 5; idx++) {
 		nid_t i_nid = le32_to_cpu(node_blk->i.i_nid[idx]);
@@ -997,6 +1015,8 @@ int fsck_chk_idnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
 	int need_fix = 0, ret;
 	int i = 0;
 
+	fsck_reada_all_direct_node_blocks(sbi, node_blk);
+
 	for (i = 0; i < NIDS_PER_BLOCK; i++) {
 		if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
 			goto skip;

fsck/fsck.c int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode, · line 1064

Quoted 8 lines
fsck/fsck.c +2 -0
@@ -1037,6 +1057,8 @@ int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
 	int i = 0;
 	int need_fix = 0, ret = 0;
 
+	fsck_reada_all_direct_node_blocks(sbi, node_blk);
+
 	for (i = 0; i < NIDS_PER_BLOCK; i++) {
 		if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
 			goto skip;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot