f2fs: sysfs: support discard_io_aware
authorChao Yu <chao@kernel.org>
Wed, 22 Nov 2023 14:47:15 +0000 (22:47 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 28 Nov 2023 18:59:51 +0000 (10:59 -0800)
It gives a way to enable/disable IO aware feature for background
discard, so that we can tune background discard more precisely
based on undiscard condition. e.g. force to disable IO aware if
there are large number of discard extents, and discard IO may
always be interrupted by frequent common IO.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/ABI/testing/sysfs-fs-f2fs
fs/f2fs/f2fs.h
fs/f2fs/segment.c
fs/f2fs/sysfs.c

index 36c3cb5..4f1d4e6 100644 (file)
@@ -740,3 +740,9 @@ Description:        When compress cache is on, it controls cached page
                If cached page percent exceed threshold, then deny caching compress page.
                The value should be in range of (0, 100], by default it was initialized
                as 20(%).
+
+What:          /sys/fs/f2fs/<disk>/discard_io_aware
+Date:          November 2023
+Contact:       "Chao Yu" <chao@kernel.org>
+Description:   It controls to enable/disable IO aware feature for background discard.
+               By default, the value is 1 which indicates IO aware is on.
index 9043ced..86a145b 100644 (file)
@@ -374,6 +374,12 @@ enum {
        MAX_DPOLICY,
 };
 
+enum {
+       DPOLICY_IO_AWARE_DISABLE,       /* force to not be aware of IO */
+       DPOLICY_IO_AWARE_ENABLE,        /* force to be aware of IO */
+       DPOLICY_IO_AWARE_MAX,
+};
+
 struct discard_policy {
        int type;                       /* type of discard */
        unsigned int min_interval;      /* used for candidates exist */
@@ -406,6 +412,7 @@ struct discard_cmd_control {
        unsigned int discard_urgent_util;       /* utilization which issue discard proactively */
        unsigned int discard_granularity;       /* discard granularity */
        unsigned int max_ordered_discard;       /* maximum discard granularity issued by lba order */
+       unsigned int discard_io_aware;          /* io_aware policy */
        unsigned int undiscard_blks;            /* # of undiscard blocks */
        unsigned int next_pos;                  /* next discard position */
        atomic_t issued_discard;                /* # of issued discard */
index f4ffd64..08e2f44 100644 (file)
@@ -1172,7 +1172,10 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi,
                dpolicy->min_interval = dcc->min_discard_issue_time;
                dpolicy->mid_interval = dcc->mid_discard_issue_time;
                dpolicy->max_interval = dcc->max_discard_issue_time;
-               dpolicy->io_aware = true;
+               if (dcc->discard_io_aware == DPOLICY_IO_AWARE_ENABLE)
+                       dpolicy->io_aware = true;
+               else if (dcc->discard_io_aware == DPOLICY_IO_AWARE_DISABLE)
+                       dpolicy->io_aware = false;
                dpolicy->sync = false;
                dpolicy->ordered = true;
                if (utilization(sbi) > dcc->discard_urgent_util) {
@@ -2275,6 +2278,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
        dcc->discard_io_aware_gran = MAX_PLIST_NUM;
        dcc->discard_granularity = DEFAULT_DISCARD_GRANULARITY;
        dcc->max_ordered_discard = DEFAULT_MAX_ORDERED_DISCARD_GRANULARITY;
+       dcc->discard_io_aware = DPOLICY_IO_AWARE_ENABLE;
        if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT)
                dcc->discard_granularity = sbi->blocks_per_seg;
        else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
index 417fae9..7099ffa 100644 (file)
@@ -516,6 +516,13 @@ out:
                return count;
        }
 
+       if (!strcmp(a->attr.name, "discard_io_aware")) {
+               if (t >= DPOLICY_IO_AWARE_MAX)
+                       return -EINVAL;
+               *ui = t;
+               return count;
+       }
+
        if (!strcmp(a->attr.name, "migration_granularity")) {
                if (t == 0 || t > sbi->segs_per_sec)
                        return -EINVAL;
@@ -926,6 +933,7 @@ DCC_INFO_GENERAL_RW_ATTR(discard_io_aware_gran);
 DCC_INFO_GENERAL_RW_ATTR(discard_urgent_util);
 DCC_INFO_GENERAL_RW_ATTR(discard_granularity);
 DCC_INFO_GENERAL_RW_ATTR(max_ordered_discard);
+DCC_INFO_GENERAL_RW_ATTR(discard_io_aware);
 
 /* NM_INFO ATTR */
 NM_INFO_RW_ATTR(max_roll_forward_node_blocks, max_rf_node_blocks);
@@ -1074,6 +1082,7 @@ static struct attribute *f2fs_attrs[] = {
        ATTR_LIST(discard_urgent_util),
        ATTR_LIST(discard_granularity),
        ATTR_LIST(max_ordered_discard),
+       ATTR_LIST(discard_io_aware),
        ATTR_LIST(pending_discard),
        ATTR_LIST(gc_mode),
        ATTR_LIST(ipu_policy),