Skip to contentSkip to conversation

mkfs.f2fs: update allocation policy for ro feature

PATCH New Chao Yu 1 participant 2 messages Oct 6, 2022 Library code

lore
Share & tools
lore
author
#1 lore raw

PATCH 2/2 fsck.f2fs: export valid image size

In reply to Chao Yu

Change to calculate and export max image size with valid blocks used of image rather than last used block of image.

[FSCK] Max image size: xx MB, Free space: xx MB

---
 fsck/f2fs.h       |  2 ++
 fsck/fsck.c       | 15 +++++++++++----
 include/f2fs_fs.h |  1 -
 lib/libf2fs_io.c  |  9 ---------
 4 files changed, 13 insertions(+), 14 deletions(-)
fsck/f2fs.h +2 -0
index 2fd241f..703f340 100644
@@ -421,6 +421,8 @@ static inline block_t __end_block_addr(struct f2fs_sb_info *sbi)
 		sbi->log_blocks_per_seg);
 }
 
+#define BLKS_PER_SEC(sbi)						\
+	((sbi)->segs_per_sec * (sbi)->blocks_per_seg)
 #define GET_ZONENO_FROM_SEGNO(sbi, segno)                               \
 	((segno / sbi->segs_per_sec) / sbi->secs_per_zone)
 
fsck/fsck.c +11 -4
index b1b6722..2f6cc72 100644
@@ -3179,6 +3179,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
 	struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
 	struct hard_link_node *node = NULL;
 	bool verify_failed = false;
+	uint64_t max_blks, data_secs, node_secs, free_blks;
 
 	if (c.show_file_map)
 		return 0;
@@ -3229,10 +3230,16 @@ int fsck_verify(struct f2fs_sb_info *sbi)
 		}
 		c.bug_on = 1;
 	}
-	printf("[FSCK] Max image size: %"PRIu64" MB, Free space: %u MB\n",
-		c.max_size >> 20,
-		(sbi->user_block_count - sbi->total_valid_block_count) >>
-		(20 - F2FS_BLKSIZE_BITS));
+
+	data_secs = round_up(sbi->total_valid_node_count, BLKS_PER_SEC(sbi));
+	node_secs = round_up(sbi->total_valid_block_count -
+				sbi->total_valid_node_count, BLKS_PER_SEC(sbi));
+	free_blks = (sbi->total_sections - data_secs - node_secs) *
+							BLKS_PER_SEC(sbi);
+	max_blks = SM_I(sbi)->main_blkaddr + (data_secs + node_secs) *
+							BLKS_PER_SEC(sbi);
+	printf("[FSCK] Max image size: %"PRIu64" MB, Free space: %"PRIu64" MB\n",
+						max_blks >> 8, free_blks >> 8);
 	printf("[FSCK] Unreachable nat entries                       ");
 	if (nr_unref_nid == 0x0) {
 		printf(" [Ok..] [0x%x]\n", nr_unref_nid);
include/f2fs_fs.h +0 -1
index 509d75a..c36c623 100644
@@ -480,7 +480,6 @@ struct f2fs_configuration {
 	uint64_t wanted_total_sectors;
 	uint64_t wanted_sector_size;
 	uint64_t target_sectors;
-	uint64_t max_size;
 	uint32_t sectors_per_blk;
 	uint32_t blks_per_seg;
 	__u8 init_version[VERSION_LEN + 1];
lib/libf2fs_io.c +0 -9
index a392255..1a8167d 100644
@@ -524,9 +524,6 @@ int dev_read(void *buf, __u64 offset, size_t len)
 	int fd;
 	int err;
 
-	if (c.max_size < (offset + len))
-		c.max_size = offset + len;
-
 	if (c.sparse_mode)
 		return sparse_read_blk(offset / F2FS_BLKSIZE,
 					len / F2FS_BLKSIZE, buf);
@@ -568,9 +565,6 @@ int dev_write(void *buf, __u64 offset, size_t len)
 {
 	int fd;
 
-	if (c.max_size < (offset + len))
-		c.max_size = offset + len;
-
 	if (c.dry_run)
 		return 0;
 
@@ -613,9 +607,6 @@ int dev_fill(void *buf, __u64 offset, size_t len)
 {
 	int fd;
 
-	if (c.max_size < (offset + len))
-		c.max_size = offset + len;
-
 	if (c.sparse_mode)
 		return sparse_write_zeroed_blk(offset / F2FS_BLKSIZE,
 						len / F2FS_BLKSIZE);
Signature · 8 lines
2.36.1



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

Chao Yu

author
#0 lore raw

PATCH 1/2 mkfs.f2fs: update allocation policy for ro feature

Update allocation policy for ro feature:
- hot_data: allocating blocks by LBA ascending order
- hot_node: allocating blocks by LBA descending order

---
 fsck/mount.c       |  8 ++++++++
 fsck/segment.c     | 15 ++++++++++++++-
 mkfs/f2fs_format.c |  4 ++--
 3 files changed, 24 insertions(+), 3 deletions(-)
fsck/mount.c +8 -0
index af24484..aebe363 100644
@@ -2777,6 +2777,14 @@ static void move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left,
 	if ((get_sb(feature) & cpu_to_le32(F2FS_FEATURE_RO))) {
 		if (i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE)
 			return;
+
+		if (i == CURSEG_HOT_DATA) {
+			left = 0;
+			from = SM_I(sbi)->main_blkaddr;
+		} else {
+			left = 1;
+			from = __end_block_addr(sbi);
+		}
 		goto bypass_ssa;
 	}
 
fsck/segment.c +14 -1
index 401cbb6..0307bdd 100644
@@ -28,6 +28,7 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
 	u64 blkaddr, offset;
 	u64 old_blkaddr = *to;
 	bool is_node = IS_NODESEG(type);
+	int left = 0;
 
 	if (old_blkaddr == NULL_ADDR) {
 		if (c.func == FSCK) {
@@ -56,7 +57,19 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
 
 	blkaddr = SM_I(sbi)->main_blkaddr;
 
-	if (find_next_free_block(sbi, &blkaddr, 0, type, false)) {
+	if (sbi->raw_super->feature & cpu_to_le32(F2FS_FEATURE_RO)) {
+		if (IS_NODESEG(type)) {
+			type = CURSEG_HOT_NODE;
+			blkaddr = __end_block_addr(sbi);
+			left = 1;
+		} else if (IS_DATASEG(type)) {
+			type = CURSEG_HOT_DATA;
+			blkaddr = SM_I(sbi)->main_blkaddr;
+			left = 0;
+		}
+	}
+
+	if (find_next_free_block(sbi, &blkaddr, left, type, false)) {
 		ERR_MSG("Can't find free block");
 		ASSERT(0);
 	}
mkfs/f2fs_format.c +2 -2
index 40ac589..8d0f410 100644
@@ -544,10 +544,10 @@ static int f2fs_prepare_super_block(void)
 	}
 
 	if (c.feature & cpu_to_le32(F2FS_FEATURE_RO)) {
-		c.cur_seg[CURSEG_HOT_NODE] = 0;
+		c.cur_seg[CURSEG_HOT_NODE] = last_section(last_zone(total_zones));
 		c.cur_seg[CURSEG_WARM_NODE] = 0;
 		c.cur_seg[CURSEG_COLD_NODE] = 0;
-		c.cur_seg[CURSEG_HOT_DATA] = 1;
+		c.cur_seg[CURSEG_HOT_DATA] = 0;
 		c.cur_seg[CURSEG_COLD_DATA] = 0;
 		c.cur_seg[CURSEG_WARM_DATA] = 0;
 	} else if (c.heap) {
Signature · 8 lines
2.36.1



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