Skip to contentSkip to conversation

f2fs: add a modify discard command function

PATCH Superseded Yunlei He 2 participants 5 messages Feb 27, 2017 – Mar 2, 2017 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: add a modify discard command function

This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range.

---
 fs/f2fs/segment.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +17 -1
index 9006d8e..5af736b 100644
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
 	kmem_cache_free(discard_cmd_slab, dc);
 }
 
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
+{
+	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+	if (dc->lstart + dc->len <= end_block) {
+		 __remove_discard_cmd(sbi, dc);
+		return;
+	}
+
+	if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
+		dc->lstart = end_block;
+		dc->len -= (end_block - dc->lstart);
+	} else
+		dc->len = blkaddr - dc->lstart;
+}
+
 /* This should be covered by global mutex, &sit_i->sentry_lock */
 void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 			if (dc->state == D_SUBMIT)
 				wait_for_completion_io(&dc->wait);
 			else
-				__remove_discard_cmd(sbi, dc);
+				__modify_discard_cmd(sbi, dc, blkaddr);
 		}
 	}
 	blk_finish_plug(&plug);
Signature · 6 lines
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
maintainer
#1 lore raw
Quoted 3 lines · Yunlei He

This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range.

Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no multi-sections discard range. Am I missing some cases?

Thanks,

Quoted 44 lines
---
 fs/f2fs/segment.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +17 -1
index 9006d8e..5af736b 100644
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
 	kmem_cache_free(discard_cmd_slab, dc);
 }
 
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
+{
+	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+	if (dc->lstart + dc->len <= end_block) {
+		 __remove_discard_cmd(sbi, dc);
+		return;
+	}
+
+	if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
+		dc->lstart = end_block;
+		dc->len -= (end_block - dc->lstart);
+	} else
+		dc->len = blkaddr - dc->lstart;
+}
+
 /* This should be covered by global mutex, &sit_i->sentry_lock */
 void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 			if (dc->state == D_SUBMIT)
 				wait_for_completion_io(&dc->wait);
 			else
-				__remove_discard_cmd(sbi, dc);
+				__modify_discard_cmd(sbi, dc, blkaddr);
 		}
 	}
 	blk_finish_plug(&plug);
Signature · 1 line
2.10.1

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

author
#2 lore raw

Hi Jaegeuk,

Quoted 7 lines · Jaegeuk Kim
Quoted 3 lines · Yunlei He

This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range.

Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no multi-sections discard range. Am I missing some cases?

I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs

can still send multi-segments discard range if prefree segments is continuous.

Thanks.

Quoted 41 lines

Thanks,

Quoted 38 lines
---
 fs/f2fs/segment.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +16 -1
index 9006d8e..5af736b 100644
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
 	kmem_cache_free(discard_cmd_slab, dc);
 }
 
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)
+{
+	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+	if (dc->lstart + dc->len <= end_block) {
+		 __remove_discard_cmd(sbi, dc);
+		return;
+	}
+
+	if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {
+		dc->lstart = end_block;
+		dc->len -= (end_block - dc->lstart);
+	} else
+		dc->len = blkaddr - dc->lstart;
+}
+
 /* This should be covered by global mutex, &sit_i->sentry_lock */
 void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 			if (dc->state == D_SUBMIT)
 				wait_for_completion_io(&dc->wait);
 			else
-				__remove_discard_cmd(sbi, dc);
Quoted 9 lines
Quoted 6 lines
fs/f2fs/segment.c +1 -1
+				__modify_discard_cmd(sbi, dc, blkaddr);
 		}
 	}
 	blk_finish_plug(&plug);
--

2.10.1

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

maintainer
#3 lore raw
Quoted 8 lines · heyunlei

Hi Jaegeuk,

Quoted 5 lines · Jaegeuk Kim
Quoted 3 lines · Yunlei He

This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range.

Quoted 6 lines
Quoted 2 lines

Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no multi-sections discard range. Am I missing some cases?

I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs

can still send multi-segments discard range if prefree segments is continuous.

Got it.
Comments below.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
---
 fs/f2fs/segment.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +0 -0
index 9006d8e..5af736b 100644
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
 	kmem_cache_free(discard_cmd_slab, dc);
 }
 
Quoted 1 line
Quoted 1 line

fs/f2fs/segment.c static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d · line 675

Quoted 1 line
fs/f2fs/segment.c +1 -0
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)

How about modifying the name "modify" to "punch"?

Quoted 9 lines
Quoted 9 lines

fs/f2fs/segment.c static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d · line 684

Quoted 9 lines
fs/f2fs/segment.c +9 -0
+{
+	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+	if (dc->lstart + dc->len <= end_block) {
+		 __remove_discard_cmd(sbi, dc);
+		return;
+	}
+
+	if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {

The blkaddr is larger than or equal to dc->lstart all the time, resulting in overflow?

Thanks,

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
fs/f2fs/segment.c +7 -1
+		dc->lstart = end_block;
+		dc->len -= (end_block - dc->lstart);
+	} else
+		dc->len = blkaddr - dc->lstart;
+}
+
 /* This should be covered by global mutex, &sit_i->sentry_lock */
 void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 			if (dc->state == D_SUBMIT)
 				wait_for_completion_io(&dc->wait);
 			else
-				__remove_discard_cmd(sbi, dc);
+				__modify_discard_cmd(sbi, dc, blkaddr);
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -1
 		}
 	}
 	blk_finish_plug(&plug);
--

2.10.1

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

author
#4 lore raw

Hi Jaegeuk,

Quoted 36 lines · Jaegeuk Kim
Quoted 8 lines · heyunlei

Hi Jaegeuk,

Quoted 5 lines · Jaegeuk Kim
Quoted 3 lines · Yunlei He

This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range.

Quoted 6 lines
Quoted 2 lines

Now MAX_DISCARD_BLOCKS() is set to section size, so there will be no multi-sections discard range. Am I missing some cases?

I think MAX_DISCARD_BLOCKS() just limit small discard and fstrim, f2fs

can still send multi-segments discard range if prefree segments is continuous.

Got it.
Comments below.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
---
 fs/f2fs/segment.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +0 -0
index 9006d8e..5af736b 100644
@@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d
 	kmem_cache_free(discard_cmd_slab, dc);
 }
 
Quoted 1 line
Quoted 1 line

fs/f2fs/segment.c static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d · line 675

Quoted 1 line
fs/f2fs/segment.c +1 -0
+static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr)

How about modifying the name "modify" to "punch"?

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines

fs/f2fs/segment.c static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d · line 684

Quoted 9 lines
fs/f2fs/segment.c +9 -0
+{
+	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);
+
+	if (dc->lstart + dc->len <= end_block) {
+		 __remove_discard_cmd(sbi, dc);
+		return;
+	}
+
+	if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) {

The blkaddr is larger than or equal to dc->lstart all the time, resulting in overflow?

Yes, here should be if (blkaddr - dc->lstart < dc->lstart + dc->len - end_block)

Quoted 27 lines

Thanks,

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
fs/f2fs/segment.c +7 -1
+		dc->lstart = end_block;
+		dc->len -= (end_block - dc->lstart);
+	} else
+		dc->len = blkaddr - dc->lstart;
+}
+
 /* This should be covered by global mutex, &sit_i->sentry_lock */
 void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
@@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 			if (dc->state == D_SUBMIT)
 				wait_for_completion_io(&dc->wait);
 			else
-				__remove_discard_cmd(sbi, dc);
+				__modify_discard_cmd(sbi, dc, blkaddr);
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -1
 		}
 	}
 	blk_finish_plug(&plug);
--

2.10.1

.

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot