Skip to contentSkip to conversation

f2fs: add sysfs nodes to get GC info for each GC mode

PATCH Superseded Daeho Jeong 2 participants 3 messages Jul 9, 2021 – Jul 10, 2021 F2FS file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 f2fs: add sysfs nodes to get GC info for each GC mode

From: Daeho Jeong <[email protected]>

Added gc_dirty_segs and gc_dirty_segs_mode sysfs nodes.
1) "gc_dirty_segs" shows how many dirty segments have been reclaimed by GC during a specific GC mode.
2) "gc_dirty_segs_mode" is used to control for which gc mode the "gc_dirty_segs" node shows.

---
 Documentation/ABI/testing/sysfs-fs-f2fs | 14 +++++++++++++
 fs/f2fs/debug.c                         |  9 ++++++++
 fs/f2fs/f2fs.h                          |  5 +++++
 fs/f2fs/gc.c                            |  1 +
 fs/f2fs/sysfs.c                         | 28 +++++++++++++++++++++++++
 5 files changed, 57 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +14 -0
index 95155e4ec7fe..0d863eb185f6 100644
@@ -493,3 +493,17 @@ Contact:	"Chao Yu" <[email protected]>
 Description:	When ATGC is on, it controls age threshold to bypass GCing young
 		candidates whose age is not beyond the threshold, by default it was
 		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/gc_dirty_segs
+Date:		July 2021
+Contact:	"Daeho Jeong" <[email protected]>
+Description:	Show how many dirty segments have been reclaimed by GC during
+		a specific GC mode (0: GC normal, 1: GC idle CB, 2: GC idle greedy,
+		3: gc idle AT, 4: GC urgent high, 5: GC urgent low)
+		You can re-initialize this value to "0".
+
+What:		/sys/fs/f2fs/<disk>/gc_dirty_segs_mode
+Date:		July 2021
+Contact:	"Daeho Jeong" <[email protected]>
+Description:	You can control for which gc mode the "gc_dirty_segs" node shows.
+		Refer to the description of the modes in "gc_dirty_segs".
fs/f2fs/debug.c +9 -0
index 833325038ef3..53ed1e9191f0 100644
@@ -450,6 +450,15 @@ static int stat_show(struct seq_file *s, void *v)
 				si->data_segs, si->bg_data_segs);
 		seq_printf(s, "  - node segments : %d (%d)\n",
 				si->node_segs, si->bg_node_segs);
+		seq_printf(s, "  - Reclaimed segs : Normal (%d), Idle CB (%d), "
+				"Idle Greedy (%d), Idle AT (%d), "
+				"Urgent High (%d), Urgent Low (%d)\n",
+				si->sbi->gc_reclaimed_segs[GC_NORMAL],
+				si->sbi->gc_reclaimed_segs[GC_IDLE_CB],
+				si->sbi->gc_reclaimed_segs[GC_IDLE_GREEDY],
+				si->sbi->gc_reclaimed_segs[GC_IDLE_AT],
+				si->sbi->gc_reclaimed_segs[GC_URGENT_HIGH],
+				si->sbi->gc_reclaimed_segs[GC_URGENT_LOW]);
 		seq_printf(s, "Try to move %d blocks (BG: %d)\n", si->tot_blks,
 				si->bg_data_blks + si->bg_node_blks);
 		seq_printf(s, "  - data blocks : %d (%d)\n", si->data_blks,
fs/f2fs/f2fs.h +5 -0
index 16ce1ade9fa6..74b1e621c15f 100644
@@ -1251,6 +1251,7 @@ enum {
 	GC_IDLE_AT,
 	GC_URGENT_HIGH,
 	GC_URGENT_LOW,
+	MAX_GC_MODE,
 };
 
 enum {
@@ -1728,6 +1729,10 @@ struct f2fs_sb_info {
 	struct kmem_cache *inline_xattr_slab;	/* inline xattr entry */
 	unsigned int inline_xattr_slab_size;	/* default inline xattr slab size */
 
+	/* For reclaimed dirty segs statistics per each GC mode */
+	unsigned int gc_dirty_segs_mode;	/* GC state for reclaimed dirty segments */
+	unsigned int gc_reclaimed_segs[MAX_GC_MODE];	/* Reclaimed dirty segs for each mode */
+
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	struct kmem_cache *page_array_slab;	/* page array entry */
 	unsigned int page_array_slab_size;	/* default page array slab size */
fs/f2fs/gc.c +1 -0
index da5947b30142..85f83ee38e24 100644
@@ -1648,6 +1648,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 							force_migrate);
 
 		stat_inc_seg_count(sbi, type, gc_type);
+		sbi->gc_reclaimed_segs[sbi->gc_mode]++;
 		migrated++;
 
 freed:
fs/f2fs/sysfs.c +28 -0
index 6642246206bd..6e5d46b1dbf5 100644
@@ -307,6 +307,14 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
 #endif
 
+	if (!strcmp(a->attr.name, "gc_dirty_segs_mode"))
+		return sysfs_emit(buf, "%u\n", sbi->gc_dirty_segs_mode);
+
+	if (!strcmp(a->attr.name, "gc_dirty_segs")) {
+		return sysfs_emit(buf, "%u\n",
+			sbi->gc_reclaimed_segs[sbi->gc_dirty_segs_mode]);
+	}
+
 	ui = (unsigned int *)(ptr + a->offset);
 
 	return sprintf(buf, "%u\n", *ui);
@@ -515,6 +523,21 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		return count;
 	}
 
+	if (!strcmp(a->attr.name, "gc_dirty_segs_mode")) {
+		if (t < MAX_GC_MODE)
+			sbi->gc_dirty_segs_mode = t;
+		else
+			return -EINVAL;
+		return count;
+	}
+
+	if (!strcmp(a->attr.name, "gc_dirty_segs")) {
+		if (t != 0)
+			return -EINVAL;
+		sbi->gc_reclaimed_segs[sbi->gc_dirty_segs_mode] = 0;
+		return count;
+	}
+
 	*ui = (unsigned int)t;
 
 	return count;
@@ -740,6 +763,9 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_dirty_segs_mode, gc_dirty_segs_mode);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_dirty_segs, gc_reclaimed_segs);
+
 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
 static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +838,8 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(atgc_candidate_count),
 	ATTR_LIST(atgc_age_weight),
 	ATTR_LIST(atgc_age_threshold),
+	ATTR_LIST(gc_dirty_segs_mode),
+	ATTR_LIST(gc_dirty_segs),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
Signature · 1 line
2.32.0.93.g670b81a890-goog
maintainer
#1 lore raw
Quoted 22 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Added gc_dirty_segs and gc_dirty_segs_mode sysfs nodes.
1) "gc_dirty_segs" shows how many dirty segments have been reclaimed by GC during a specific GC mode.
2) "gc_dirty_segs_mode" is used to control for which gc mode the "gc_dirty_segs" node shows.

---
  Documentation/ABI/testing/sysfs-fs-f2fs | 14 +++++++++++++
  fs/f2fs/debug.c                         |  9 ++++++++
  fs/f2fs/f2fs.h                          |  5 +++++
  fs/f2fs/gc.c                            |  1 +
  fs/f2fs/sysfs.c                         | 28 +++++++++++++++++++++++++
  5 files changed, 57 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index 95155e4ec7fe..0d863eb185f6 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 497

Quoted 5 lines
Documentation/ABI/testing/sysfs-fs-f2fs +2 -0
@@ -493,3 +493,17 @@ Contact:	"Chao Yu" <[email protected]>
  Description:	When ATGC is on, it controls age threshold to bypass GCing young
  		candidates whose age is not beyond the threshold, by default it was
  		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/gc_dirty_segs

How about renaming gc_dirty_segs to gc_reclaimed_segments?

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 5 lines
Documentation/ABI/testing/sysfs-fs-f2fs +5 -0
+Date:		July 2021
+Contact:	"Daeho Jeong" <[email protected]>
+Description:	Show how many dirty segments have been reclaimed by GC during
+		a specific GC mode (0: GC normal, 1: GC idle CB, 2: GC idle greedy,
+		3: gc idle AT, 4: GC urgent high, 5: GC urgent low)

3. GC idle AT

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 505

Quoted 3 lines
Documentation/ABI/testing/sysfs-fs-f2fs +3 -0
+		You can re-initialize this value to "0".
+
+What:		/sys/fs/f2fs/<disk>/gc_dirty_segs_mode

You know, F2FS_IOC_FLUSH_DEVICE/F2FS_IOC_RESIZE_FS needs to migrate all blocks of target segment to other place, no matter the segment has partially or fully valid blocks, so it looks 'gc_segment_mode' will be more appropriate?

Thanks,

#2 lore raw
Quoted 19 lines · Chao Yu
Quoted 17 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Added gc_dirty_segs and gc_dirty_segs_mode sysfs nodes.
1) "gc_dirty_segs" shows how many dirty segments have been reclaimed by GC during a specific GC mode.
2) "gc_dirty_segs_mode" is used to control for which gc mode the "gc_dirty_segs" node shows.

---
  Documentation/ABI/testing/sysfs-fs-f2fs | 14 +++++++++++++
  fs/f2fs/debug.c                         |  9 ++++++++
  fs/f2fs/f2fs.h                          |  5 +++++
  fs/f2fs/gc.c                            |  1 +
  fs/f2fs/sysfs.c                         | 28 +++++++++++++++++++++++++
  5 files changed, 57 insertions(+)
Quoted 12 lines

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 497

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +2 -0
index 95155e4ec7fe..0d863eb185f6 100644
@@ -493,3 +493,17 @@ Contact: "Chao Yu" <[email protected]>
  Description:        When ATGC is on, it controls age threshold to bypass GCing young
              candidates whose age is not beyond the threshold, by default it was
              initialized as 604800 seconds (equals to 7 days).
+
+What:                /sys/fs/f2fs/<disk>/gc_dirty_segs

How about renaming gc_dirty_segs to gc_reclaimed_segments?

Makes sense.

Quoted 9 lines

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 7 lines
Documentation/ABI/testing/sysfs-fs-f2fs +5 -0
+Date:                July 2021
+Contact:     "Daeho Jeong" <[email protected]>
+Description: Show how many dirty segments have been reclaimed by GC during
+             a specific GC mode (0: GC normal, 1: GC idle CB, 2: GC idle greedy,
+             3: gc idle AT, 4: GC urgent high, 5: GC urgent low)

3. GC idle AT

Got it.

Quoted 10 lines

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 505

Quoted 4 lines
Documentation/ABI/testing/sysfs-fs-f2fs +3 -0
+             You can re-initialize this value to "0".
+
+What:                /sys/fs/f2fs/<disk>/gc_dirty_segs_mode

You know, F2FS_IOC_FLUSH_DEVICE/F2FS_IOC_RESIZE_FS needs to migrate all blocks of target segment to other place, no matter the segment has partially or fully valid blocks, so it looks 'gc_segment_mode' will be more appropriate?

Thanks,

Reasonable~ Got it.