[PATCH v3 3/3] f2fs: introduce ipu_mode sysfs node

From: Yangtao Li
Date: Thu Feb 02 2023 - 03:49:07 EST


Add a ipu_mode sysfs node to show the current ipu policy as a string
for readability, like we do in commit a3951cd199a5 ("f2fs: introduce
gc_mode sysfs node").

Since we use ipu_policy as a bitmap, and the bitmap API parameter is
unsigned long type data, let's change ipu_policy to unsigned long type.

Signed-off-by: Yangtao Li <frank.li@xxxxxxxx>
---
v3:
-drop old_ipu_policy type conversion
Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
fs/f2fs/f2fs.h | 4 ++--
fs/f2fs/segment.h | 1 +
fs/f2fs/sysfs.c | 28 ++++++++++++++++++++++++-
4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 8a71397fa060..10e34753d246 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -724,3 +724,9 @@ Description: Controls background discard granularity of inner discard thread
is smaller than granularity. The unit size is one block(4KB), now only
support configuring in range of [0, 512].
Default: 512
+
+What: /sys/fs/f2fs/<disk>/ipu_mode
+Date: February 2023
+Contact: "Yangtao Li" <frank.li@xxxxxxxx>
+Description: Show the current ipu policy as a string.
+ This is a read-only entry.
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 08dc64c5050e..066cd497be09 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1070,7 +1070,7 @@ struct f2fs_sm_info {

struct list_head sit_entry_set; /* sit entry set list */

- unsigned int ipu_policy; /* in-place-update policy */
+ unsigned long ipu_policy; /* in-place-update policy */
unsigned int min_ipu_util; /* in-place-update threshold */
unsigned int min_fsync_blocks; /* threshold for fsync */
unsigned int min_seq_blocks; /* threshold for sequential blocks */
@@ -1322,7 +1322,7 @@ enum {
MAX_TIME,
};

-/* Note that you need to keep synchronization with this gc_mode_names array */
+/* Modification on enum should be synchronized with gc_mode_names array */
enum {
GC_NORMAL,
GC_IDLE_CB,
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 8ee5e5db9287..92c8be00d396 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -672,6 +672,7 @@ static inline int utilization(struct f2fs_sb_info *sbi)

#define F2FS_IPU_DISABLE 0

+/* Modification on enum should be synchronized with ipu_mode_names array */
enum {
F2FS_IPU_FORCE,
F2FS_IPU_SSR,
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index e1f1ebfa59d6..2a95545b2938 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -51,6 +51,17 @@ static const char *gc_mode_names[MAX_GC_MODE] = {
"GC_URGENT_MID"
};

+static const char *ipu_mode_names[F2FS_IPU_MAX] = {
+ "FORCE",
+ "SSR",
+ "UTIL",
+ "SSR_UTIL",
+ "FSYNC",
+ "ASYNC",
+ "NOCACHE",
+ "HONOR_OPU_WRITE",
+};
+
struct f2fs_attr {
struct attribute attr;
ssize_t (*show)(struct f2fs_attr *a, struct f2fs_sb_info *sbi, char *buf);
@@ -149,6 +160,19 @@ static ssize_t gc_mode_show(struct f2fs_attr *a,
return sysfs_emit(buf, "%s\n", gc_mode_names[sbi->gc_mode]);
}

+static ssize_t ipu_mode_show(struct f2fs_attr *a,
+ struct f2fs_sb_info *sbi, char *buf)
+{
+ int len = 0, i = 0;
+
+ if (SM_I(sbi)->ipu_policy == F2FS_IPU_DISABLE)
+ return sysfs_emit(buf, "DISABLE\n");
+
+ for_each_set_bit(i, &SM_I(sbi)->ipu_policy, F2FS_IPU_MAX)
+ len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n", ipu_mode_names[i]);
+ return len;
+}
+
static ssize_t features_show(struct f2fs_attr *a,
struct f2fs_sb_info *sbi, char *buf)
{
@@ -702,7 +726,7 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return -EINVAL;
if (t >= BIT(F2FS_IPU_MAX))
return -EINVAL;
- SM_I(sbi)->ipu_policy = (unsigned int)t;
+ SM_I(sbi)->ipu_policy = t;
return count;
}

@@ -898,6 +922,7 @@ F2FS_GENERAL_RO_ATTR(mounted_time_sec);
F2FS_GENERAL_RO_ATTR(main_blkaddr);
F2FS_GENERAL_RO_ATTR(pending_discard);
F2FS_GENERAL_RO_ATTR(gc_mode);
+F2FS_GENERAL_RO_ATTR(ipu_mode);
#ifdef CONFIG_F2FS_STAT_FS
F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
@@ -987,6 +1012,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(max_ordered_discard),
ATTR_LIST(pending_discard),
ATTR_LIST(gc_mode),
+ ATTR_LIST(ipu_mode),
ATTR_LIST(ipu_policy),
ATTR_LIST(min_ipu_util),
ATTR_LIST(min_fsync_blocks),
--
2.25.1