linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: add sysfs nodes to get GC info for each GC urgent mode
@ 2021-07-02 21:44 Daeho Jeong
  2021-07-07  5:33 ` [f2fs-dev] " Jaegeuk Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Daeho Jeong @ 2021-07-02 21:44 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

Added gc_urgent_dirty_segs and gc_urgent_dirty_segs_mode sysfs nodes.
1) "gc_urgent_dirty_segs" shows how many dirty segments have been
reclaimed by GC during a specific GC urgent mode.
2) "gc_urgent_dirty_segs_mode" is used to control for which gc urgent
mode the "gc_urgent_dirty_segs" node shows.
(1: GC urgent high, 2: GC urgent low)

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 Documentation/ABI/testing/sysfs-fs-f2fs | 14 ++++++++
 fs/f2fs/f2fs.h                          |  5 +++
 fs/f2fs/gc.c                            |  4 +++
 fs/f2fs/sysfs.c                         | 46 +++++++++++++++++++++++++
 4 files changed, 69 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 95155e4ec7fe..9851c3f2efad 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -493,3 +493,17 @@ Contact:	"Chao Yu" <yuchao0@huawei.com>
 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_urgent_dirty_segs
+Date:		July 2021
+Contact:	"Daeho Jeong" <daehojeong@google.com>
+Description:	Show how many dirty segments have been reclaimed by GC during
+		a specific GC urgent mode (1: GC urgent high, 2: GC urgent low)
+		You can re-initialize this value to "0".
+
+What:		/sys/fs/f2fs/<disk>/gc_urgent_dirty_segs_mode
+Date:		July 2021
+Contact:	"Daeho Jeong" <daehojeong@google.com>
+Description:	You can control for which gc urgent mode the "gc_urgent_dirty_segs"
+		node shows (1: GC urgent high, 2: GC urgent low). You can set the
+		value to "0" when you want not to select one of them.
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 16ce1ade9fa6..d838c373f188 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1728,6 +1728,11 @@ 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 urgent mode */
+	unsigned int gc_dirty_segs_mode;	/* GC state for reclaimed dirty segments */
+	u64 gc_urgent_high_dirty_segs;		/* Reclaimed dirty segs in GC_URGENT_HIGH */
+	u64 gc_urgent_low_dirty_segs;		/* Reclaimed dirty segs in GC_URGENT_LOW */
+
 #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 */
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index da5947b30142..233e2a500379 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1648,6 +1648,10 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 							force_migrate);
 
 		stat_inc_seg_count(sbi, type, gc_type);
+		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
+			sbi->gc_urgent_high_dirty_segs++;
+		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
+			sbi->gc_urgent_low_dirty_segs++;
 		migrated++;
 
 freed:
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 6642246206bd..9ede97fe12cf 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -307,6 +307,25 @@ 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_urgent_dirty_segs_mode")) {
+		if (sbi->gc_dirty_segs_mode == GC_NORMAL)
+			return sysfs_emit(buf, "0\n");
+		else if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
+			return sysfs_emit(buf, "1\n");
+		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
+			return sysfs_emit(buf, "2\n");
+	}
+
+	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs")) {
+		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
+			return sysfs_emit(buf, "%llu\n",
+					sbi->gc_urgent_high_dirty_segs);
+		if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
+			return sysfs_emit(buf, "%llu\n",
+					sbi->gc_urgent_low_dirty_segs);
+		return sysfs_emit(buf, "0\n");
+	}
+
 	ui = (unsigned int *)(ptr + a->offset);
 
 	return sprintf(buf, "%u\n", *ui);
@@ -515,6 +534,28 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
 		return count;
 	}
 
+	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs_mode")) {
+		if (t == 0)
+			sbi->gc_dirty_segs_mode = GC_NORMAL;
+		else if (t == 1)
+			sbi->gc_dirty_segs_mode = GC_URGENT_HIGH;
+		else if (t == 2)
+			sbi->gc_dirty_segs_mode = GC_URGENT_LOW;
+		else
+			return -EINVAL;
+		return count;
+	}
+
+	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs")) {
+		if (t != 0 || sbi->gc_dirty_segs_mode == GC_NORMAL)
+			return -EINVAL;
+		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
+			sbi->gc_urgent_high_dirty_segs = 0;
+		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
+			sbi->gc_urgent_low_dirty_segs = 0;
+		return count;
+	}
+
 	*ui = (unsigned int)t;
 
 	return count;
@@ -740,6 +781,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_urgent_dirty_segs_mode, gc_dirty_segs_mode);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_dirty_segs, gc_urgent_high_dirty_segs);
+
 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
 static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +856,8 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(atgc_candidate_count),
 	ATTR_LIST(atgc_age_weight),
 	ATTR_LIST(atgc_age_threshold),
+	ATTR_LIST(gc_urgent_dirty_segs_mode),
+	ATTR_LIST(gc_urgent_dirty_segs),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
-- 
2.32.0.93.g670b81a890-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: add sysfs nodes to get GC info for each GC urgent mode
  2021-07-02 21:44 [PATCH] f2fs: add sysfs nodes to get GC info for each GC urgent mode Daeho Jeong
@ 2021-07-07  5:33 ` Jaegeuk Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Jaegeuk Kim @ 2021-07-07  5:33 UTC (permalink / raw)
  To: Daeho Jeong; +Cc: linux-kernel, linux-f2fs-devel, kernel-team, Daeho Jeong

On 07/02, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> Added gc_urgent_dirty_segs and gc_urgent_dirty_segs_mode sysfs nodes.
> 1) "gc_urgent_dirty_segs" shows how many dirty segments have been
> reclaimed by GC during a specific GC urgent mode.
> 2) "gc_urgent_dirty_segs_mode" is used to control for which gc urgent
> mode the "gc_urgent_dirty_segs" node shows.
> (1: GC urgent high, 2: GC urgent low)
> 
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> ---
>  Documentation/ABI/testing/sysfs-fs-f2fs | 14 ++++++++
>  fs/f2fs/f2fs.h                          |  5 +++
>  fs/f2fs/gc.c                            |  4 +++
>  fs/f2fs/sysfs.c                         | 46 +++++++++++++++++++++++++
>  4 files changed, 69 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index 95155e4ec7fe..9851c3f2efad 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -493,3 +493,17 @@ Contact:	"Chao Yu" <yuchao0@huawei.com>
>  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_urgent_dirty_segs
> +Date:		July 2021
> +Contact:	"Daeho Jeong" <daehojeong@google.com>
> +Description:	Show how many dirty segments have been reclaimed by GC during
> +		a specific GC urgent mode (1: GC urgent high, 2: GC urgent low)
> +		You can re-initialize this value to "0".
> +
> +What:		/sys/fs/f2fs/<disk>/gc_urgent_dirty_segs_mode
> +Date:		July 2021
> +Contact:	"Daeho Jeong" <daehojeong@google.com>
> +Description:	You can control for which gc urgent mode the "gc_urgent_dirty_segs"
> +		node shows (1: GC urgent high, 2: GC urgent low). You can set the
> +		value to "0" when you want not to select one of them.
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 16ce1ade9fa6..d838c373f188 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1728,6 +1728,11 @@ 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 urgent mode */
> +	unsigned int gc_dirty_segs_mode;	/* GC state for reclaimed dirty segments */
> +	u64 gc_urgent_high_dirty_segs;		/* Reclaimed dirty segs in GC_URGENT_HIGH */
> +	u64 gc_urgent_low_dirty_segs;		/* Reclaimed dirty segs in GC_URGENT_LOW */

How about modifying like this? And, can we add this in debug/f2fs/status?

enum {
	GC_NORMAL,
	GC_URGENT_HIGH,
	GC_URGENT_LOW,
	GC_IDLE_CB,
	GC_IDLE_GREEDY,
	GC_IDLE_AT,
};

#define GC_URGENT_MAX	(GC_URGENT_LOW + 1)
unsigned int reclaimed_segs[GC_URGENT_MAX];

> +
>  #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 */
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index da5947b30142..233e2a500379 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1648,6 +1648,10 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
>  							force_migrate);
>  
>  		stat_inc_seg_count(sbi, type, gc_type);
> +		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)

		if (sbi->gc_mode < GC_URGENT_MAX)
			sbi->gc_reclaimed_segs[sbi->gc_mode]++;

> +			sbi->gc_urgent_high_dirty_segs++;
> +		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
> +			sbi->gc_urgent_low_dirty_segs++;
>  		migrated++;
>  
>  freed:
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 6642246206bd..9ede97fe12cf 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -307,6 +307,25 @@ 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_urgent_dirty_segs_mode")) {
> +		if (sbi->gc_dirty_segs_mode == GC_NORMAL)
> +			return sysfs_emit(buf, "0\n");

						"0:gc_normal"?

> +		else if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
> +			return sysfs_emit(buf, "1\n");

						"1:gc_urgent_high"?

> +		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
> +			return sysfs_emit(buf, "2\n");

						"2:gc_urgent_low"?

> +	}
> +
> +	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs")) {
> +		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
> +			return sysfs_emit(buf, "%llu\n",
> +					sbi->gc_urgent_high_dirty_segs);
> +		if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
> +			return sysfs_emit(buf, "%llu\n",
> +					sbi->gc_urgent_low_dirty_segs);
> +		return sysfs_emit(buf, "0\n");
> +	}
> +
>  	ui = (unsigned int *)(ptr + a->offset);
>  
>  	return sprintf(buf, "%u\n", *ui);
> @@ -515,6 +534,28 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
>  		return count;
>  	}
>  
> +	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs_mode")) {
> +		if (t == 0)
> +			sbi->gc_dirty_segs_mode = GC_NORMAL;
> +		else if (t == 1)
> +			sbi->gc_dirty_segs_mode = GC_URGENT_HIGH;
> +		else if (t == 2)
> +			sbi->gc_dirty_segs_mode = GC_URGENT_LOW;
> +		else
> +			return -EINVAL;
> +		return count;
> +	}
> +
> +	if (!strcmp(a->attr.name, "gc_urgent_dirty_segs")) {
> +		if (t != 0 || sbi->gc_dirty_segs_mode == GC_NORMAL)
> +			return -EINVAL;
> +		if (sbi->gc_dirty_segs_mode == GC_URGENT_HIGH)
> +			sbi->gc_urgent_high_dirty_segs = 0;
> +		else if (sbi->gc_dirty_segs_mode == GC_URGENT_LOW)
> +			sbi->gc_urgent_low_dirty_segs = 0;
> +		return count;
> +	}
> +
>  	*ui = (unsigned int)t;
>  
>  	return count;
> @@ -740,6 +781,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_urgent_dirty_segs_mode, gc_dirty_segs_mode);
> +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_dirty_segs, gc_urgent_high_dirty_segs);
> +
>  #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
>  static struct attribute *f2fs_attrs[] = {
>  	ATTR_LIST(gc_urgent_sleep_time),
> @@ -812,6 +856,8 @@ static struct attribute *f2fs_attrs[] = {
>  	ATTR_LIST(atgc_candidate_count),
>  	ATTR_LIST(atgc_age_weight),
>  	ATTR_LIST(atgc_age_threshold),
> +	ATTR_LIST(gc_urgent_dirty_segs_mode),
> +	ATTR_LIST(gc_urgent_dirty_segs),
>  	NULL,
>  };
>  ATTRIBUTE_GROUPS(f2fs);
> -- 
> 2.32.0.93.g670b81a890-goog
> 
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-07  5:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-02 21:44 [PATCH] f2fs: add sysfs nodes to get GC info for each GC urgent mode Daeho Jeong
2021-07-07  5:33 ` [f2fs-dev] " Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).