Skip to contentSkip to conversation

f2fs: fix to ensure queued discard commands are properly issued

PATCH In review Yohan Joung 3 participants 4 messages Feb 4, 2025 – Feb 24, 2025 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: fix to ensure queued discard commands are properly issued

F2FS zone storage requires discard and reset zone for each conventional, zoned device.
In the current configuration, Discard granularity is set to the zone size but queuing is inserted into the pend list with a maximum size of the segment size As a result queued commands cannot be issued.
so we are restorting discard granularity to its original state

---
 fs/f2fs/segment.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/segment.c +0 -4
index c282e8a0a2ec..938bf5144ae8 100644
@@ -2320,10 +2320,6 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
 	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 = BLKS_PER_SEG(sbi);
-	else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
-		dcc->discard_granularity = BLKS_PER_SEC(sbi);
 
 	INIT_LIST_HEAD(&dcc->entry_list);
 	for (i = 0; i < MAX_PLIST_NUM; i++)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · Yohan Joung

F2FS zone storage requires discard and reset zone for each conventional, zoned device.
In the current configuration, Discard granularity is set to the zone size but queuing is inserted into the pend list with a maximum size of the segment size As a result queued commands cannot be issued.
so we are restorting discard granularity to its original state

It seems commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug: when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause bug. blkzoned feature became the victim since it use discard_unit=section option by default.

What:           /sys/fs/f2fs/<disk>/discard_granularity
Date:           July 2017
Contact:        "Chao Yu" <[email protected]>
Description:    Controls discard granularity of inner discard thread. Inner thread

will not issue discards with size that is smaller than granularity. The unit size is one block(4KB), now only support configuring in range of [1, 512]. Default value is 16.
For small devices, default value is 1.

What about this?

Subject: [PATCH] f2fs: fix to set .discard_granularity correctly

commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug, when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause issue_discard_thread() in DPOLICY_BG mode will not select discard entry w/ any granularity to issue.

Fixes 4f993264fe29 ("f2fs: introduce discard_unit mount option")
---
 fs/f2fs/segment.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/segment.c +2 -3
index 6ebe25eafafa..2b415926641f 100644
@@ -2320,10 +2320,9 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
 	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)
+	if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT ||
+		F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
 		dcc->discard_granularity = BLKS_PER_SEG(sbi);
-	else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
-		dcc->discard_granularity = BLKS_PER_SEC(sbi);
 
 	INIT_LIST_HEAD(&dcc->entry_list);
 	for (i = 0; i < MAX_PLIST_NUM; i++)
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
Reviewed-by
#2 lore raw
Quoted 61 lines · Chao Yu
Quoted 6 lines · Yohan Joung

F2FS zone storage requires discard and reset zone for each conventional, zoned device.
In the current configuration, Discard granularity is set to the zone size but queuing is inserted into the pend list with a maximum size of the segment size As a result queued commands cannot be issued.
so we are restorting discard granularity to its original state

It seems commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug: when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause bug. blkzoned feature became the victim since it use discard_unit=section option by default.

What:           /sys/fs/f2fs/<disk>/discard_granularity
Date:           July 2017
Contact:        "Chao Yu" <[email protected]>
Description:    Controls discard granularity of inner discard thread. Inner thread

will not issue discards with size that is smaller than granularity. The unit size is one block(4KB), now only support configuring in range of [1, 512]. Default value is 16.
For small devices, default value is 1.

What about this?

Subject: [PATCH] f2fs: fix to set .discard_granularity correctly

commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug, when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause issue_discard_thread() in DPOLICY_BG mode will not select discard entry w/ any granularity to issue.

Fixes 4f993264fe29 ("f2fs: introduce discard_unit mount option")
---
 fs/f2fs/segment.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/segment.c +2 -4
index 6ebe25eafafa..2b415926641f 100644
@@ -2320,10 +2320,9 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
        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)
+       if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT ||
+               F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
                dcc->discard_granularity = BLKS_PER_SEG(sbi);
-       else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
-               dcc->discard_granularity = BLKS_PER_SEC(sbi);
 
        INIT_LIST_HEAD(&dcc->entry_list);
        for (i = 0; i < MAX_PLIST_NUM; i++)
--
Quoted 2 lines

2.48.1.601.g30ceb7b040-goog

Quoted 1 line
maintainer
#3 lore raw
Quoted 59 lines · Daeho Jeong
Quoted 58 lines · Chao Yu
Quoted 6 lines · Yohan Joung

F2FS zone storage requires discard and reset zone for each conventional, zoned device.
In the current configuration, Discard granularity is set to the zone size but queuing is inserted into the pend list with a maximum size of the segment size As a result queued commands cannot be issued.
so we are restorting discard granularity to its original state

It seems commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug: when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause bug. blkzoned feature became the victim since it use discard_unit=section option by default.

What:           /sys/fs/f2fs/<disk>/discard_granularity
Date:           July 2017
Contact:        "Chao Yu" <[email protected]>
Description:    Controls discard granularity of inner discard thread. Inner thread

will not issue discards with size that is smaller than granularity. The unit size is one block(4KB), now only support configuring in range of [1, 512]. Default value is 16.
For small devices, default value is 1.

What about this?

Subject: [PATCH] f2fs: fix to set .discard_granularity correctly

commit 4f993264fe29 ("f2fs: introduce discard_unit mount option") introduced a bug, when we enable discard_unit=section option, it will set .discard_granularity to BLKS_PER_SEC(), however discard granularity only supports [1, 512], once section size is not equal to segment size, it will cause issue_discard_thread() in DPOLICY_BG mode will not select discard entry w/ any granularity to issue.

Fixes 4f993264fe29 ("f2fs: introduce discard_unit mount option")
---
 fs/f2fs/segment.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/segment.c +2 -3
index 6ebe25eafafa..2b415926641f 100644
@@ -2320,10 +2320,9 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
        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)
+       if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT ||
+               F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
                dcc->discard_granularity = BLKS_PER_SEG(sbi);
-       else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
-               dcc->discard_granularity = BLKS_PER_SEC(sbi);
 
Quoted 7 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -1
        INIT_LIST_HEAD(&dcc->entry_list);
        for (i = 0; i < MAX_PLIST_NUM; i++)
--

2.48.1.601.g30ceb7b040-goog

Thanks for the review, let me send a formal patch.

Thanks,

Quoted 2 lines
Quoted 2 lines