Skip to contentSkip to conversation

f2fs: use per-log target_bitmap to improve lookup performace of ssr allocation

PATCH In review Chao Yu 2 participants 8 messages Apr 11, 2024 – Oct 7, 2024 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH v2 1/2 f2fs: use per-log target_bitmap to improve lookup performace of ssr allocation

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch.

 fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
 fs/f2fs/segment.h |  1 +
 2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
 	return 0;
 }
 
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-					int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+					unsigned long *target_map,
+					int segno)
 {
 	struct seg_entry *se = get_seg_entry(sbi, segno);
 	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-	unsigned long *target_map = SIT_I(sbi)->tmp_map;
 	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
 	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
 	int i;
 
 	for (i = 0; i < entries; i++)
 		target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+					int segno, block_t start)
+{
+	__get_segment_bitmap(sbi, bitmap, segno);
 
-	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
 }
 
 static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-		struct curseg_info *seg)
+					struct curseg_info *seg)
 {
-	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+	return __find_rev_next_zero_bit(seg->target_map,
+				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
 }
 
 bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
 {
-	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+							BLKS_PER_SEG(sbi);
 }
 
 /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
 
 	reset_curseg(sbi, type, 1);
 	curseg->alloc_type = SSR;
-	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+							curseg->segno, 0);
 
 	sum_page = f2fs_get_sum_page(sbi, new_segno);
 	if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 				sizeof(struct f2fs_journal), GFP_KERNEL);
 		if (!array[i].journal)
 			return -ENOMEM;
+		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+								GFP_KERNEL);
+		if (!array[i].target_map)
+			return -ENOMEM;
 		if (i < NR_PERSISTENT_LOG)
 			array[i].seg_type = CURSEG_HOT_DATA + i;
 		else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		kfree(array[i].sum_blk);
 		kfree(array[i].journal);
+		kfree(array[i].target_map);
 	}
 	kfree(array);
 }
fs/f2fs/segment.h +1 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {
 	struct f2fs_summary_block *sum_blk;	/* cached summary block */
 	struct rw_semaphore journal_rwsem;	/* protect journal area */
 	struct f2fs_journal *journal;		/* cached journal info */
+	unsigned long *target_map;		/* bitmap for SSR allocator */
 	unsigned char alloc_type;		/* current allocation type */
 	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
 	unsigned int segno;			/* current segment number */
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH v2 2/2 f2fs: introduce written_map to indicate written datas

Currently, __exchange_data_block() will check checkpointed state of data, if it is not checkpointed, it will try to exchange blkaddrs directly in dnode.

However, after commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), in order to disallow SSR allocator to reuse all written data/node type blocks, all written blocks were set as checkpointed.

In order to reenable metadata exchange functionality, let's introduce written_map to indicate all written blocks including checkpointed one, or newly written and invalidated one, and use it for SSR allocation, and then ckpt_valid_bitmap can indicate real checkpointed status, and we can use it correctly in __exchange_data_block().

[testcase]
xfs_io -f /mnt/f2fs/src -c "pwrite 0 2m"
xfs_io -f /mnt/f2fs/dst -c "pwrite 0 2m"
xfs_io /mnt/f2fs/src -c "fiemap -v"
xfs_io /mnt/f2fs/dst -c "fiemap -v"
f2fs_io move_range /mnt/f2fs/src /mnt/f2fs/dst 0 0 2097152 xfs_io /mnt/f2fs/src -c "fiemap -v"
xfs_io /mnt/f2fs/dst -c "fiemap -v"

[before]
/mnt/f2fs/src:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 8445952..8450047 4096 0x1001
/mnt/f2fs/dst:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 143360..147455 4096 0x1001

/mnt/f2fs/src:
/mnt/f2fs/dst:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 4284416..4288511 4096 0x1001

[after]
/mnt/f2fs/src:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 147456..151551 4096 0x1001
/mnt/f2fs/dst:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 151552..155647 4096 0x1001

/mnt/f2fs/src:
/mnt/f2fs/dst:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..4095]: 147456..151551 4096 0x1001

---
v2:
- introduce written_blocks in struct seg_entry for ssr allocator.

 fs/f2fs/gc.c      |  2 +-
 fs/f2fs/segment.c | 22 ++++++++++++----------
 fs/f2fs/segment.h | 19 ++++++++++++++-----
 3 files changed, 27 insertions(+), 16 deletions(-)
fs/f2fs/gc.c +1 -1
index 8852814dab7f..ea7b5ca6f09b 100644
@@ -366,7 +366,7 @@ static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct victim_sel_policy *p)
 {
 	if (p->alloc_mode == SSR)
-		return get_seg_entry(sbi, segno)->ckpt_valid_blocks;
+		return get_seg_entry(sbi, segno)->written_blocks;
 
 	/* alloc_mode == LFS */
 	if (p->gc_mode == GC_GREEDY)
fs/f2fs/segment.c +12 -10
index af716925db19..0d110908e383 100644
@@ -2456,12 +2456,13 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
 			sbi->discard_blks--;
 
 		/*
-		 * SSR should never reuse block which is checkpointed
-		 * or newly invalidated.
+		 * if CP disabling is enable, it allows SSR to reuse newly
+		 * invalidated block, otherwise forbidding it to pretect fsyned
+		 * datas.
 		 */
 		if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
-			if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
-				se->ckpt_valid_blocks++;
+			if (!f2fs_test_and_set_bit(offset, se->written_map))
+				se->written_blocks++;
 		}
 	} else {
 		exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
@@ -2498,8 +2499,6 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
 			f2fs_test_and_clear_bit(offset, se->discard_map))
 			sbi->discard_blks++;
 	}
-	if (!f2fs_test_bit(offset, se->ckpt_valid_map))
-		se->ckpt_valid_blocks += del;
 
 	__mark_sit_entry_dirty(sbi, segno);
 
@@ -2847,11 +2846,11 @@ static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
 	struct seg_entry *se = get_seg_entry(sbi, segno);
 	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
 	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
-	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
+	unsigned long *written_map = (unsigned long *)se->written_map;
 	int i;
 
 	for (i = 0; i < entries; i++)
-		target_map[i] = ckpt_map[i] | cur_map[i];
+		target_map[i] = ckpt_map[i] | written_map[i];
 }
 
 static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
@@ -4512,9 +4511,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 		return -ENOMEM;
 
 #ifdef CONFIG_F2FS_CHECK_FS
-	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (3 + discard_map);
+	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (4 + discard_map);
 #else
-	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (2 + discard_map);
+	bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * (3 + discard_map);
 #endif
 	sit_i->bitmap = f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL);
 	if (!sit_i->bitmap)
@@ -4529,6 +4528,9 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 		sit_i->sentries[start].ckpt_valid_map = bitmap;
 		bitmap += SIT_VBLOCK_MAP_SIZE;
 
+		sit_i->sentries[start].written_map = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
+
 #ifdef CONFIG_F2FS_CHECK_FS
 		sit_i->sentries[start].cur_valid_map_mir = bitmap;
 		bitmap += SIT_VBLOCK_MAP_SIZE;
fs/f2fs/segment.h +14 -5
index 10f3e44f036f..71131a0b00d7 100644
@@ -191,10 +191,11 @@ struct victim_sel_policy {
 };
 
 struct seg_entry {
-	unsigned int type:6;		/* segment type like CURSEG_XXX_TYPE */
-	unsigned int valid_blocks:10;	/* # of valid blocks */
-	unsigned int ckpt_valid_blocks:10;	/* # of valid blocks last cp */
-	unsigned int padding:6;		/* padding */
+	unsigned long long type:6;		/* segment type like CURSEG_XXX_TYPE */
+	unsigned long long valid_blocks:10;	/* # of valid blocks */
+	unsigned long long ckpt_valid_blocks:10;/* # of valid blocks last cp */
+	unsigned long long written_blocks:10;	/* # of written blocks */
+	unsigned long long padding:28;		/* padding */
 	unsigned char *cur_valid_map;	/* validity bitmap of blocks */
 #ifdef CONFIG_F2FS_CHECK_FS
 	unsigned char *cur_valid_map_mir;	/* mirror of current valid bitmap */
@@ -204,6 +205,10 @@ struct seg_entry {
 	 * checkpoint pack. This information is used by the SSR mode.
 	 */
 	unsigned char *ckpt_valid_map;	/* validity bitmap of blocks last cp */
+	unsigned char *written_map;	/*
+					 * blocks were written, including newly
+					 * invalidated data
+					 */
 	unsigned char *discard_map;
 	unsigned long long mtime;	/* modification time of the segment */
 };
@@ -366,9 +371,11 @@ static inline void seg_info_from_raw_sit(struct seg_entry *se,
 					struct f2fs_sit_entry *rs)
 {
 	se->valid_blocks = GET_SIT_VBLOCKS(rs);
-	se->ckpt_valid_blocks = GET_SIT_VBLOCKS(rs);
+	se->ckpt_valid_blocks = se->valid_blocks;
+	se->written_blocks = se->valid_blocks;
 	memcpy(se->cur_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
 	memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
+	memcpy(se->written_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
 #ifdef CONFIG_F2FS_CHECK_FS
 	memcpy(se->cur_valid_map_mir, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
 #endif
@@ -411,7 +418,9 @@ static inline void seg_info_to_raw_sit(struct seg_entry *se,
 	__seg_info_to_raw_sit(se, rs);
 
 	memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
+	memcpy(se->written_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
 	se->ckpt_valid_blocks = se->valid_blocks;
+	se->written_blocks = se->valid_blocks;
 }
 
 static inline unsigned int find_next_inuse(struct free_segmap_info *free_i,
Signature · 1 line
2.40.1
author maintainer
#2 lore raw
In reply to Chao Yu

Jaegeuk, any comments for this serials?

Quoted 106 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch.

  fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
  fs/f2fs/segment.h |  1 +
  2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
  	return 0;
  }
 
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-					int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+					unsigned long *target_map,
+					int segno)
  {
  	struct seg_entry *se = get_seg_entry(sbi, segno);
  	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-	unsigned long *target_map = SIT_I(sbi)->tmp_map;
  	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
  	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
  	int i;
 
  	for (i = 0; i < entries; i++)
  		target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+					int segno, block_t start)
+{
+	__get_segment_bitmap(sbi, bitmap, segno);
 
-	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
  }
 
  static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-		struct curseg_info *seg)
+					struct curseg_info *seg)
  {
-	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+	return __find_rev_next_zero_bit(seg->target_map,
+				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
  }
 
  bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
  {
-	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+							BLKS_PER_SEG(sbi);
  }
 
  /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
 
  	reset_curseg(sbi, type, 1);
  	curseg->alloc_type = SSR;
-	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+							curseg->segno, 0);
 
  	sum_page = f2fs_get_sum_page(sbi, new_segno);
  	if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
  				sizeof(struct f2fs_journal), GFP_KERNEL);
  		if (!array[i].journal)
  			return -ENOMEM;
+		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+								GFP_KERNEL);
+		if (!array[i].target_map)
+			return -ENOMEM;
  		if (i < NR_PERSISTENT_LOG)
  			array[i].seg_type = CURSEG_HOT_DATA + i;
  		else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
  	for (i = 0; i < NR_CURSEG_TYPE; i++) {
  		kfree(array[i].sum_blk);
  		kfree(array[i].journal);
+		kfree(array[i].target_map);
  	}
  	kfree(array);
  }
fs/f2fs/segment.h +1 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {
  	struct f2fs_summary_block *sum_blk;	/* cached summary block */
  	struct rw_semaphore journal_rwsem;	/* protect journal area */
  	struct f2fs_journal *journal;		/* cached journal info */
+	unsigned long *target_map;		/* bitmap for SSR allocator */
  	unsigned char alloc_type;		/* current allocation type */
  	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
  	unsigned int segno;			/* current segment number */
author maintainer
#3 lore raw

Ping,

Quoted 107 lines · Chao Yu

Jaegeuk, any comments for this serials?

Quoted 91 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch. fs/f2fs/segment.c | 30 ++++++++++++++++++++++-------- fs/f2fs/segment.h |  1 +

  2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
       return 0;
   }
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-                    int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+                    unsigned long *target_map,
+                    int segno)
   {
       struct seg_entry *se = get_seg_entry(sbi, segno);
       int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-    unsigned long *target_map = SIT_I(sbi)->tmp_map;
       unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
       unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
       int i;
       for (i = 0; i < entries; i++)
           target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+                    int segno, block_t start)
+{
+    __get_segment_bitmap(sbi, bitmap, segno);
-    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
   }
   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-        struct curseg_info *seg)
+                    struct curseg_info *seg)
   {
-    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+    return __find_rev_next_zero_bit(seg->target_map,
+                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
   }
   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
   {
-    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+                            BLKS_PER_SEG(sbi);
   }
   /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
       reset_curseg(sbi, type, 1);
       curseg->alloc_type = SSR;
-    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+                            curseg->segno, 0);
       sum_page = f2fs_get_sum_page(sbi, new_segno);
       if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
                   sizeof(struct f2fs_journal), GFP_KERNEL);
           if (!array[i].journal)
               return -ENOMEM;
+        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+                                GFP_KERNEL);
+        if (!array[i].target_map)
+            return -ENOMEM;
           if (i < NR_PERSISTENT_LOG)
               array[i].seg_type = CURSEG_HOT_DATA + i;
           else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
       for (i = 0; i < NR_CURSEG_TYPE; i++) {
           kfree(array[i].sum_blk);
           kfree(array[i].journal);
+        kfree(array[i].target_map);
       }
       kfree(array);
   }
fs/f2fs/segment.h +0 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {
Quoted 7 lines

      struct f2fs_summary_block *sum_blk;    /* cached summary block */ struct rw_semaphore journal_rwsem;    /* protect journal area */ struct f2fs_journal *journal;        /* cached journal info */ +    unsigned long *target_map;        /* bitmap for SSR allocator */ unsigned char alloc_type;        /* current allocation type */ unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */ unsigned int segno;            /* current segment number */

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#4 lore raw
Quoted 1 line · Chao Yu

Ping,

Chao, sorry, I might need some time to take a look at the change cautiously.

Quoted 109 lines · Chao Yu
Quoted 107 lines

Jaegeuk, any comments for this serials?

Quoted 91 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch. fs/f2fs/segment.c | 30 ++++++++++++++++++++++-------- fs/f2fs/segment.h |  1 +

  2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
       return 0;
   }
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-                    int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+                    unsigned long *target_map,
+                    int segno)
   {
       struct seg_entry *se = get_seg_entry(sbi, segno);
       int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-    unsigned long *target_map = SIT_I(sbi)->tmp_map;
       unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
       unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
       int i;
       for (i = 0; i < entries; i++)
           target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+                    int segno, block_t start)
+{
+    __get_segment_bitmap(sbi, bitmap, segno);
-    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
   }
   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-        struct curseg_info *seg)
+                    struct curseg_info *seg)
   {
-    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+    return __find_rev_next_zero_bit(seg->target_map,
+                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
   }
   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
   {
-    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+                            BLKS_PER_SEG(sbi);
   }
   /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
       reset_curseg(sbi, type, 1);
       curseg->alloc_type = SSR;
-    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+                            curseg->segno, 0);
       sum_page = f2fs_get_sum_page(sbi, new_segno);
       if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
                   sizeof(struct f2fs_journal), GFP_KERNEL);
           if (!array[i].journal)
               return -ENOMEM;
+        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+                                GFP_KERNEL);
+        if (!array[i].target_map)
+            return -ENOMEM;
           if (i < NR_PERSISTENT_LOG)
               array[i].seg_type = CURSEG_HOT_DATA + i;
           else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
       for (i = 0; i < NR_CURSEG_TYPE; i++) {
           kfree(array[i].sum_blk);
           kfree(array[i].journal);
+        kfree(array[i].target_map);
       }
       kfree(array);
   }
fs/f2fs/segment.h +0 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {
Quoted 7 lines

      struct f2fs_summary_block *sum_blk;    /* cached summary block */ struct rw_semaphore journal_rwsem;    /* protect journal area */ struct f2fs_journal *journal;        /* cached journal info */ +    unsigned long *target_map;        /* bitmap for SSR allocator */ unsigned char alloc_type;        /* current allocation type */ unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */ unsigned int segno;            /* current segment number */

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#5 lore raw
Quoted 2 lines · Jaegeuk Kim
Quoted 1 line · Chao Yu

Ping,

Jaegeuk,

Quoted 2 lines

Chao, sorry, I might need some time to take a look at the change cautiously.

No problem, I've done some tests on this patch, though, I will keeping this in my queue, and do test base on the queue whenever it comes new patches.

Thanks,

Quoted 110 lines
Quoted 110 lines · Chao Yu
Quoted 107 lines

Jaegeuk, any comments for this serials?

Quoted 91 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch.

   fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
   fs/f2fs/segment.h |  1 +
   2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
       return 0;
   }
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-                    int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+                    unsigned long *target_map,
+                    int segno)
   {
       struct seg_entry *se = get_seg_entry(sbi, segno);
       int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-    unsigned long *target_map = SIT_I(sbi)->tmp_map;
       unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
       unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
       int i;
       for (i = 0; i < entries; i++)
           target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+                    int segno, block_t start)
+{
+    __get_segment_bitmap(sbi, bitmap, segno);
-    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
   }
   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-        struct curseg_info *seg)
+                    struct curseg_info *seg)
   {
-    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+    return __find_rev_next_zero_bit(seg->target_map,
+                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
   }
   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
   {
-    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+                            BLKS_PER_SEG(sbi);
   }
   /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
       reset_curseg(sbi, type, 1);
       curseg->alloc_type = SSR;
-    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+                            curseg->segno, 0);
       sum_page = f2fs_get_sum_page(sbi, new_segno);
       if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
                   sizeof(struct f2fs_journal), GFP_KERNEL);
           if (!array[i].journal)
               return -ENOMEM;
+        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+                                GFP_KERNEL);
+        if (!array[i].target_map)
+            return -ENOMEM;
           if (i < NR_PERSISTENT_LOG)
               array[i].seg_type = CURSEG_HOT_DATA + i;
           else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
       for (i = 0; i < NR_CURSEG_TYPE; i++) {
           kfree(array[i].sum_blk);
           kfree(array[i].journal);
+        kfree(array[i].target_map);
       }
       kfree(array);
   }
fs/f2fs/segment.h +0 -0
index e1c0f418aa11..10f3e44f036f 100644

fs/f2fs/segment.h struct curseg_info { · line 298

Quoted 7 lines
fs/f2fs/segment.h +1 -0
@@ -292,6 +292,7 @@ struct curseg_info {
       struct f2fs_summary_block *sum_blk;    /* cached summary block */
       struct rw_semaphore journal_rwsem;    /* protect journal area */
       struct f2fs_journal *journal;        /* cached journal info */
+    unsigned long *target_map;        /* bitmap for SSR allocator */
       unsigned char alloc_type;        /* current allocation type */
       unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */
       unsigned int segno;            /* current segment number */

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#6 lore raw
Quoted 11 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim
Quoted 1 line · Chao Yu

Ping,

Jaegeuk,

Quoted 2 lines

Chao, sorry, I might need some time to take a look at the change cautiously.

No problem, I've done some tests on this patch, though, I will keeping this in my queue, and do test base on the queue whenever it comes new patches.

Jaegeuk,

Any progress on this patchset?

Thanks,

Quoted 119 lines

Thanks,

Quoted 102 lines
Quoted 102 lines · Chao Yu
Quoted 99 lines

Jaegeuk, any comments for this serials?

Quoted 96 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch. fs/f2fs/segment.c | 30 ++++++++++++++++++++++-------- fs/f2fs/segment.h |  1 +

   2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
        return 0;
    }
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-                    int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+                    unsigned long *target_map,
+                    int segno)
    {
        struct seg_entry *se = get_seg_entry(sbi, segno);
        int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-    unsigned long *target_map = SIT_I(sbi)->tmp_map;
        unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
        unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
        int i;
        for (i = 0; i < entries; i++)
            target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+                    int segno, block_t start)
+{
+    __get_segment_bitmap(sbi, bitmap, segno);
-    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
    }
    static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-        struct curseg_info *seg)
+                    struct curseg_info *seg)
    {
-    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+    return __find_rev_next_zero_bit(seg->target_map,
+                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
    }
    bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
    {
-    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+                            BLKS_PER_SEG(sbi);
    }
    /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
        reset_curseg(sbi, type, 1);
        curseg->alloc_type = SSR;
-    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+                            curseg->segno, 0);
        sum_page = f2fs_get_sum_page(sbi, new_segno);
        if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
                    sizeof(struct f2fs_journal), GFP_KERNEL);
            if (!array[i].journal)
                return -ENOMEM;
+        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+                                GFP_KERNEL);
+        if (!array[i].target_map)
+            return -ENOMEM;
            if (i < NR_PERSISTENT_LOG)
                array[i].seg_type = CURSEG_HOT_DATA + i;
            else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
        for (i = 0; i < NR_CURSEG_TYPE; i++) {
            kfree(array[i].sum_blk);
            kfree(array[i].journal);
+        kfree(array[i].target_map);
        }
        kfree(array);
    }
fs/f2fs/segment.h +0 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {

       struct f2fs_summary_block *sum_blk;    /* cached summary block */ struct rw_semaphore journal_rwsem;    /* protect journal area */ struct f2fs_journal *journal;        /* cached journal info */ +    unsigned long *target_map;        /* bitmap for SSR allocator */ unsigned char alloc_type;        /* current allocation type */

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

       unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */ unsigned int segno;            /* current segment number */

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#7 lore raw
In reply to Chao Yu

Hi Chao,

This introduces another bitmap increasing memory footprint. Do we know how much performance benefit with this?

Quoted 108 lines · Chao Yu

After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by forbidding SSR overwrite"), valid block bitmap of current openned segment is fixed, let's introduce a per-log bitmap instead of temp bitmap to avoid unnecessary calculation overhead whenever allocating free slot w/ SSR allocator.

---
v2:
- rebase to last dev-test branch.

 fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
 fs/f2fs/segment.h |  1 +
 2 files changed, 23 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +22 -8
index 6474b7338e81..af716925db19 100644
@@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
 	return 0;
 }
 
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-					int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+					unsigned long *target_map,
+					int segno)
 {
 	struct seg_entry *se = get_seg_entry(sbi, segno);
 	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-	unsigned long *target_map = SIT_I(sbi)->tmp_map;
 	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
 	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
 	int i;
 
 	for (i = 0; i < entries; i++)
 		target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+					int segno, block_t start)
+{
+	__get_segment_bitmap(sbi, bitmap, segno);
 
-	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
 }
 
 static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-		struct curseg_info *seg)
+					struct curseg_info *seg)
 {
-	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+	return __find_rev_next_zero_bit(seg->target_map,
+				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
 }
 
 bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
 {
-	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+							BLKS_PER_SEG(sbi);
 }
 
 /*
@@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
 
 	reset_curseg(sbi, type, 1);
 	curseg->alloc_type = SSR;
-	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+							curseg->segno, 0);
 
 	sum_page = f2fs_get_sum_page(sbi, new_segno);
 	if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 				sizeof(struct f2fs_journal), GFP_KERNEL);
 		if (!array[i].journal)
 			return -ENOMEM;
+		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+								GFP_KERNEL);
+		if (!array[i].target_map)
+			return -ENOMEM;
 		if (i < NR_PERSISTENT_LOG)
 			array[i].seg_type = CURSEG_HOT_DATA + i;
 		else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		kfree(array[i].sum_blk);
 		kfree(array[i].journal);
+		kfree(array[i].target_map);
 	}
 	kfree(array);
 }
fs/f2fs/segment.h +1 -0
index e1c0f418aa11..10f3e44f036f 100644
@@ -292,6 +292,7 @@ struct curseg_info {
 	struct f2fs_summary_block *sum_blk;	/* cached summary block */
 	struct rw_semaphore journal_rwsem;	/* protect journal area */
 	struct f2fs_journal *journal;		/* cached journal info */
+	unsigned long *target_map;		/* bitmap for SSR allocator */
 	unsigned char alloc_type;		/* current allocation type */
 	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
 	unsigned int segno;			/* current segment number */
Signature · 1 line
2.40.1