Skip to contentSkip to conversation

f2fs: return directly if block has been removed from the victim

PATCH Superseded Yunlei He 3 participants 6 messages Oct 24, 2016 – Nov 2, 2016 F2FS file system

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: return directly if block has been removed from the victim

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +12 -5
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))
+		if (!check_valid_map(F2FS_I_SB(inode), segno, off))
 			goto out;
+
+		f2fs_wait_on_page_writeback(page, DATA, false);
 		set_page_dirty(page);
 		set_cold_data(page);
 	} else {
@@ -797,9 +804,9 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 			start_bidx = start_bidx_of_node(nofs, inode)
 								+ ofs_in_node;
 			if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
-				move_encrypted_block(inode, start_bidx);
+				move_encrypted_block(inode, start_bidx, segno, off);
 			else
-				move_data_page(inode, start_bidx, gc_type);
+				move_data_page(inode, start_bidx, gc_type, segno, off);
 
 			if (locked) {
 				up_write(&fi->dio_rwsem[WRITE]);
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

Hi Yunlei,

Quoted 23 lines · Yunlei He

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +2 -1
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),

fs/f2fs/gc.c static void move_encrypted_block(struct inode *inode, block_t bidx) · line 585

Quoted 5 lines
fs/f2fs/gc.c +2 -0
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;

This is done by gc_data_segment() before calling move function. Why do we need this again?

Quoted 15 lines
fs/f2fs/gc.c +3 -1
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 

fs/f2fs/gc.c static void move_data_page(struct inode *inode, block_t bidx, int gc_type) · line 658

Quoted 4 lines
fs/f2fs/gc.c +0 -1
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))

Seems there is no reason to remove the existing writeback case. This is a BG_GC case and we don't need to proceed GC in this case.

Quoted 30 lines
fs/f2fs/gc.c +5 -2
+		if (!check_valid_map(F2FS_I_SB(inode), segno, off))
 			goto out;
+
+		f2fs_wait_on_page_writeback(page, DATA, false);
 		set_page_dirty(page);
 		set_cold_data(page);
 	} else {
@@ -797,9 +804,9 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 			start_bidx = start_bidx_of_node(nofs, inode)
 								+ ofs_in_node;
 			if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
-				move_encrypted_block(inode, start_bidx);
+				move_encrypted_block(inode, start_bidx, segno, off);
 			else
-				move_data_page(inode, start_bidx, gc_type);
+				move_data_page(inode, start_bidx, gc_type, segno, off);
 
 			if (locked) {
 				up_write(&fi->dio_rwsem[WRITE]);
Signature · 10 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
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik

author
#2 lore raw

On 2016/10/26 9:09, Jaegeuk Kim wrote:
Hi Kim,

Quoted 19 lines

Hi Yunlei,

Quoted 16 lines · Yunlei He

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +0 -0
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
Quoted 15 lines

fs/f2fs/gc.c static void move_encrypted_block(struct inode *inode, block_t bidx) · line 585

Quoted 12 lines
fs/f2fs/gc.c +4 -1
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;

This is done by gc_data_segment() before calling move function. Why do we need this again?

gc_data_segment() check this without lock the data page. If this block is written to a new place between check in gc_data_segment() and locked the page, it will need to wait this page write back, and write it again, it's unnecessary.

Quoted 15 lines
Quoted 15 lines
fs/f2fs/gc.c +3 -1
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 
Quoted 8 lines

fs/f2fs/gc.c static void move_data_page(struct inode *inode, block_t bidx, int gc_type) · line 658

Quoted 5 lines
fs/f2fs/gc.c +0 -1
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))

Seems there is no reason to remove the existing writeback case. This is a BG_GC case and we don't need to proceed GC in this case.

Here, PageWriteback(page) means two cases:
1. write to this victim segment
2. write to a new place

In the first case, if we return directly, this victim bg_gc will fail for some blocks are still valid.

Thanks.

Quoted 24 lines
Quoted 24 lines
fs/f2fs/gc.c +5 -3
+		if (!check_valid_map(F2FS_I_SB(inode), segno, off))
 			goto out;
+
+		f2fs_wait_on_page_writeback(page, DATA, false);
 		set_page_dirty(page);
 		set_cold_data(page);
 	} else {
@@ -797,9 +804,9 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 			start_bidx = start_bidx_of_node(nofs, inode)
 								+ ofs_in_node;
 			if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
-				move_encrypted_block(inode, start_bidx);
+				move_encrypted_block(inode, start_bidx, segno, off);
 			else
-				move_data_page(inode, start_bidx, gc_type);
+				move_data_page(inode, start_bidx, gc_type, segno, off);
 
 			if (locked) {
 				up_write(&fi->dio_rwsem[WRITE]);
--

2.10.1

Quoted 10 lines
Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

.

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik

maintainer
#3 lore raw
Quoted 67 lines · heyunlei

On 2016/10/26 9:09, Jaegeuk Kim wrote:
Hi Kim,

Quoted 19 lines

Hi Yunlei,

Quoted 16 lines · Yunlei He

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +0 -0
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
Quoted 15 lines

fs/f2fs/gc.c static void move_encrypted_block(struct inode *inode, block_t bidx) · line 585

Quoted 12 lines
fs/f2fs/gc.c +4 -1
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;

This is done by gc_data_segment() before calling move function. Why do we need this again?

gc_data_segment() check this without lock the data page. If this block is written to a new place between check in gc_data_segment() and locked the page, it will need to wait this page write back, and write it again, it's unnecessary.

Quoted 15 lines
Quoted 15 lines
fs/f2fs/gc.c +3 -1
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 
Quoted 8 lines

fs/f2fs/gc.c static void move_data_page(struct inode *inode, block_t bidx, int gc_type) · line 658

Quoted 5 lines
fs/f2fs/gc.c +0 -1
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))

Seems there is no reason to remove the existing writeback case. This is a BG_GC case and we don't need to proceed GC in this case.

Quoted 6 lines

Here, PageWriteback(page) means two cases:
1. write to this victim segment
2. write to a new place

In the first case, if we return directly, this victim bg_gc will fail for some blocks are still valid.

It should be fine, and its main reason would be to avoid wait_on_page_writeback. Next bg_gc will do better.

Thanks,

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik

#4 lore raw
Quoted 72 lines · Jaegeuk Kim
Quoted 71 lines · heyunlei

On 2016/10/26 9:09, Jaegeuk Kim wrote:
Hi Kim,

Quoted 19 lines

Hi Yunlei,

Quoted 16 lines · Yunlei He

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +0 -0
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
Quoted 15 lines

fs/f2fs/gc.c static void move_encrypted_block(struct inode *inode, block_t bidx) · line 585

Quoted 12 lines
fs/f2fs/gc.c +4 -1
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;

This is done by gc_data_segment() before calling move function. Why do we need this again?

gc_data_segment() check this without lock the data page. If this block is written to a new place between check in gc_data_segment() and locked the page, it will need to wait this page write back, and write it again, it's unnecessary.

Quoted 15 lines
Quoted 15 lines
fs/f2fs/gc.c +3 -1
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 
Quoted 8 lines

fs/f2fs/gc.c static void move_data_page(struct inode *inode, block_t bidx, int gc_type) · line 658

Quoted 5 lines
fs/f2fs/gc.c +0 -1
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))

Seems there is no reason to remove the existing writeback case. This is a BG_GC case and we don't need to proceed GC in this case.

Here, PageWriteback(page) means two cases:
1. write to this victim segment
2. write to a new place

Quoted 5 lines
Quoted 2 lines

In the first case, if we return directly, this victim bg_gc will fail for some blocks are still valid.

It should be fine, and its main reason would be to avoid wait_on_page_writeback. Next bg_gc will do better.

Agreed.

Yunlei, I think it's better add this judgment condition after we grabbed locked data page for covering both background and foreground GC cases, instead of changing previous process logic.

Thanks,

Quoted 14 lines

Thanks,

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 2 lines

.

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi

author
#5 lore raw
Quoted 79 lines · Chao Yu
Quoted 72 lines · Jaegeuk Kim
Quoted 71 lines · heyunlei

On 2016/10/26 9:09, Jaegeuk Kim wrote:
Hi Kim,

Quoted 19 lines

Hi Yunlei,

Quoted 16 lines · Yunlei He

If one block has been to written to a new place, just return in move data process.

---
 fs/f2fs/gc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +0 -0
index f35fca5..fc78f3e 100644
@@ -545,7 +545,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 	return true;
 }
 
Quoted 15 lines

fs/f2fs/gc.c static void move_encrypted_block(struct inode *inode, block_t bidx) · line 585

Quoted 12 lines
fs/f2fs/gc.c +4 -1
-static void move_encrypted_block(struct inode *inode, block_t bidx)
+static void move_encrypted_block(struct inode *inode, block_t bidx,
+						unsigned int segno, int off)
 {
 	struct f2fs_io_info fio = {
 		.sbi = F2FS_I_SB(inode),
@@ -580,6 +581,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	 * don't cache encrypted data into meta inode until previous dirty
 	 * data were writebacked to avoid racing between GC and flush.
 	 */
+	if (!check_valid_map(F2FS_I_SB(inode), segno, off))
+		goto out;

This is done by gc_data_segment() before calling move function. Why do we need this again?

gc_data_segment() check this without lock the data page. If this block is written to a new place between check in gc_data_segment() and locked the page, it will need to wait this page write back, and write it again, it's unnecessary.

Quoted 15 lines
Quoted 15 lines
fs/f2fs/gc.c +3 -1
+
 	f2fs_wait_on_page_writeback(page, DATA, true);
 
 	get_node_info(fio.sbi, dn.nid, &ni);
@@ -646,7 +650,8 @@ static void move_encrypted_block(struct inode *inode, block_t bidx)
 	f2fs_put_page(page, 1);
 }
 
-static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
+static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
+							unsigned int segno, int off)
 {
 	struct page *page;
 
Quoted 8 lines

fs/f2fs/gc.c static void move_data_page(struct inode *inode, block_t bidx, int gc_type) · line 658

Quoted 5 lines
fs/f2fs/gc.c +0 -1
@@ -655,8 +660,10 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type)
 		return;
 
 	if (gc_type == BG_GC) {
-		if (PageWriteback(page))

Seems there is no reason to remove the existing writeback case. This is a BG_GC case and we don't need to proceed GC in this case.

Here, PageWriteback(page) means two cases:
1. write to this victim segment
2. write to a new place

Quoted 5 lines
Quoted 2 lines

In the first case, if we return directly, this victim bg_gc will fail for some blocks are still valid.

It should be fine, and its main reason would be to avoid wait_on_page_writeback. Next bg_gc will do better.

Quoted 7 lines

Agreed.

Yunlei, I think it's better add this judgment condition after we grabbed locked data page for covering both background and foreground GC cases, instead of changing previous process logic.

Thanks,

Ok, I have sent a new version.

Thanks,

Quoted 15 lines
Quoted 15 lines

Thanks,

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers Did the resurgence of CLI tooling catch you by surprise? Reconnect with the command line and become more productive. Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 6 lines
Quoted 2 lines

.

.

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi