Skip to contentSkip to conversation

f2fs: clear cold data flag if IO is not counted

PATCH In review Jaegeuk Kim 3 participants 11 messages Oct 10, 2018 – Oct 19, 2018 F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: clear cold data flag if IO is not counted

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -4
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

I didn't get it, which count do you mean?

Thanks,

Quoted 22 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -4
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);
author maintainer
#2 lore raw
Quoted 5 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

I didn't get it, which count do you mean?

It's the number of dirty pages.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( 0 129304)) cmd: 0 undiscard: 0

Quoted 25 lines

Thanks,

Quoted 22 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -4
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);
#3 lore raw
Quoted 5 lines · Jaegeuk Kim
Quoted 4 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Quoted 7 lines
Quoted 1 line

I didn't get it, which count do you mean?

It's the number of dirty pages.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( 0 129304)) cmd: 0 undiscard: 0

So I guess the race should be:

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

How about relocate wait_writeback & set_page_dirty to avoid above race:

move_data_page()

retry:

		f2fs_wait_on_page_writeback(page, DATA, true);
		set_page_dirty(page);

Thanks,

Quoted 28 lines
Quoted 17 lines

Thanks,

Quoted 14 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -0
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
Quoted 8 lines

fs/f2fs/data.c static int f2fs_set_data_page_dirty(struct page *page) · line 2641

Quoted 8 lines
fs/f2fs/data.c +0 -4
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);

.

author maintainer
#4 lore raw
Quoted 26 lines · Chao Yu
Quoted 5 lines · Jaegeuk Kim
Quoted 4 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Quoted 7 lines
Quoted 1 line

I didn't get it, which count do you mean?

It's the number of dirty pages.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( 0 129304)) cmd: 0 undiscard: 0

So I guess the race should be:

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

Quoted 1 line

How about relocate wait_writeback & set_page_dirty to avoid above race:

Well, wait_on_stable_page() doesn't guarantee its end_io. So, I'm not sure this is the only case.

Quoted 37 lines

move_data_page()

retry:

		f2fs_wait_on_page_writeback(page, DATA, true);
		set_page_dirty(page);

Thanks,

Quoted 28 lines
Quoted 17 lines

Thanks,

Quoted 14 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -0
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
Quoted 8 lines

fs/f2fs/data.c static int f2fs_set_data_page_dirty(struct page *page) · line 2641

Quoted 8 lines
fs/f2fs/data.c +0 -4
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);

.

#5 lore raw
Quoted 7 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu
Quoted 5 lines · Jaegeuk Kim
Quoted 4 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

I didn't get it, which count do you mean?

It's the number of dirty pages.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( 0 129304)) cmd: 0 undiscard: 0

Better to add such info in commit message. :)

Quoted 14 lines
Quoted 14 lines
Quoted 1 line

So I guess the race should be:

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

Quoted 4 lines
Quoted 1 line

How about relocate wait_writeback & set_page_dirty to avoid above race:

Well, wait_on_stable_page() doesn't guarantee its end_io. So, I'm not sure this is the only case.

Yes, you're right, I missed that case.

Can you use git-revert to generate the patch? so we can remain original commit info for better backward tracking.

How do you think pick up original patch I submitted:

https://lkml.org/lkml/2018/7/27/415

Thanks,

Quoted 41 lines
Quoted 38 lines

move_data_page()

retry:

		f2fs_wait_on_page_writeback(page, DATA, true);
		set_page_dirty(page);

Thanks,

Quoted 28 lines
Quoted 17 lines

Thanks,

Quoted 14 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -0
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
Quoted 8 lines

fs/f2fs/data.c static int f2fs_set_data_page_dirty(struct page *page) · line 2641

Quoted 8 lines
fs/f2fs/data.c +0 -4
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);

.

.

author maintainer
#6 lore raw
Quoted 36 lines · Chao Yu
Quoted 7 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu
Quoted 5 lines · Jaegeuk Kim
Quoted 4 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

I didn't get it, which count do you mean?

It's the number of dirty pages.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( 0 129304)) cmd: 0 undiscard: 0

Better to add such info in commit message. :)

Quoted 14 lines
Quoted 14 lines
Quoted 1 line

So I guess the race should be:

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

Quoted 4 lines
Quoted 1 line

How about relocate wait_writeback & set_page_dirty to avoid above race:

Well, wait_on_stable_page() doesn't guarantee its end_io. So, I'm not sure this is the only case.

Quoted 8 lines

Yes, you're right, I missed that case.

Can you use git-revert to generate the patch? so we can remain original commit info for better backward tracking.

How do you think pick up original patch I submitted:

https://lkml.org/lkml/2018/7/27/415

Seems that works.

Thanks,

Quoted 44 lines

Thanks,

Quoted 41 lines
Quoted 38 lines

move_data_page()

retry:

		f2fs_wait_on_page_writeback(page, DATA, true);
		set_page_dirty(page);

Thanks,

Quoted 28 lines
Quoted 17 lines

Thanks,

Quoted 14 lines
---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -0
index 29a9d3b8f709..4102799b5558 100644
@@ -2636,10 +2636,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
Quoted 8 lines

fs/f2fs/data.c static int f2fs_set_data_page_dirty(struct page *page) · line 2641

Quoted 8 lines
fs/f2fs/data.c +0 -4
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);

.

.

author maintainer
#7 lore raw
In reply to Jaegeuk Kim

This reverts commit 66110abc4c931f879d70e83e1281f891699364bf.

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( ...

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -4
index 3f272c18fb61..0d0b4dd55b04 100644
@@ -2650,10 +2650,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
 	if (!PageUptodate(page))
 		SetPageUptodate(page);
 
-	/* don't remain PG_checked flag which was set during GC */
-	if (is_cold_data(page))
-		clear_cold_data(page);
-
 	if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
 		if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
 			f2fs_register_inmem_page(inode, page);
Signature · 1 line
2.19.0.605.g01d371f741-goog
Reviewed-by
#8 lore raw
Quoted 18 lines · Jaegeuk Kim

This reverts commit 66110abc4c931f879d70e83e1281f891699364bf.

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( ...

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

Quoted 2 lines

Thanks,

Tested-by
#9 lore raw
In reply to Jaegeuk Kim

This does seem to fix the problem I've been having.

I was encountering all I/Os to be blocked on my Android device almost on a daily basis, but after this patch I'm rock solid for almost a week.

I'd appreciate it if you could add the following tags:

Also, a little additional note would be helpful
for those who are unfamiliar with f2fs:
This fixes a deadlock causing all I/Os to be blocked during heavy GC.

Thanks,

Quoted 49 lines · Jaegeuk Kim

This reverts commit 66110abc4c931f879d70e83e1281f891699364bf.

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( ...

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -5
index 3f272c18fb61..0d0b4dd55b04 100644
@@ -2650,10 +2650,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
        if (!PageUptodate(page))
                SetPageUptodate(page);
 
-       /* don't remain PG_checked flag which was set during GC */
-       if (is_cold_data(page))
-               clear_cold_data(page);
-
        if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
                if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
                        f2fs_register_inmem_page(inode, page);
--

2.19.0.605.g01d371f741-goog

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#10 lore raw
Quoted 5 lines · Ju Hyung Park

This does seem to fix the problem I've been having.

I was encountering all I/Os to be blocked on my Android device almost on a daily basis, but after this patch I'm rock solid for almost a week.

Quoted 7 lines

I'd appreciate it if you could add the following tags:

Also, a little additional note would be helpful
for those who are unfamiliar with f2fs:
This fixes a deadlock causing all I/Os to be blocked during heavy GC.

Cool. Please check the below. :P

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev&id=b921ec4e7fb5df13f805bc04375ed529faa095ae

Thanks,

Quoted 52 lines

Thanks,

Quoted 49 lines · Jaegeuk Kim

This reverts commit 66110abc4c931f879d70e83e1281f891699364bf.

If we clear the cold data flag out of the writeback flow, we can miscount -1 by end_io.

Balancing F2FS Async:
- IO (CP: 1, Data: -1, Flush: ( 0 0 1), Discard: ( ...

GC thread: IRQ
- move_data_page()
- set_page_dirty()
- clear_cold_data()
- f2fs_write_end_io()
- type = WB_DATA_TYPE(page); here, we get wrong type
- dec_page_count(sbi, type);
- f2fs_wait_on_page_writeback()

---
 fs/f2fs/data.c | 4 ----
 1 file changed, 4 deletions(-)
fs/f2fs/data.c +0 -5
index 3f272c18fb61..0d0b4dd55b04 100644
@@ -2650,10 +2650,6 @@ static int f2fs_set_data_page_dirty(struct page *page)
        if (!PageUptodate(page))
                SetPageUptodate(page);
 
-       /* don't remain PG_checked flag which was set during GC */
-       if (is_cold_data(page))
-               clear_cold_data(page);
-
        if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
                if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
                        f2fs_register_inmem_page(inode, page);
--

2.19.0.605.g01d371f741-goog

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel