Skip to contentSkip to conversation

f2fs: Avoid deadlock between writeback and checkpoint

PATCH In review [email protected] 3 participants 14 messages Nov 9, 2021 – Dec 18, 2021 1 message not in the archive F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: Avoid deadlock between writeback and checkpoint

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

        loop {
        queue_io
        progress=__writeback_inodes_wb
                __writeback_single_inode
                        do_writepages
                                f2fs_write_data_pages
                                wbc->pages_skipped +=get_dirty_pages
                        inode->i_state &= ~dirty
                wrote++
                requeue_inode
        }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

    wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
 fs/f2fs/data.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/data.c +3 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
 	return ret;
 
 skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?
+		get_dirty_pages(inode) : 0;
 	trace_f2fs_writepages(mapping->host, wbc, DATA);
 	return 0;
 }
Signature · 1 line
2.28.0
maintainer
#1 lore raw
Quoted 65 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

        loop {
        queue_io
        progress=__writeback_inodes_wb
                __writeback_single_inode
                        do_writepages
                                f2fs_write_data_pages
                                wbc->pages_skipped +=get_dirty_pages
                        inode->i_state &= ~dirty
                wrote++
                requeue_inode
        }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

    wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
 fs/f2fs/data.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/data.c +0 -0
index f4fd6c246c9a..e98628e3868c 100644

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3241

Quoted 6 lines
fs/f2fs/data.c +2 -1
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
 	return ret;
 
 skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

Quoted 6 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
 	trace_f2fs_writepages(mapping->host, wbc, DATA);
 	return 0;
 }
Signature · 1 line
2.28.0
maintainer
#2 lore raw
Quoted 68 lines · Jaegeuk Kim
Quoted 67 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

         loop {
         queue_io
         progress=__writeback_inodes_wb
                 __writeback_single_inode
                         do_writepages
                                 f2fs_write_data_pages
                                 wbc->pages_skipped +=get_dirty_pages
                         inode->i_state &= ~dirty
                 wrote++
                 requeue_inode
         }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

     wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
  fs/f2fs/data.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/data.c +0 -0
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
  	return ret;
 
Quoted 6 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3241

Quoted 4 lines
fs/f2fs/data.c +2 -1
  skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]
- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages
bio contains NodeA was plugged in writeback threads
- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 2 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 			/* give a priority to WB_SYNC threads */
 			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
 					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
 				done = 1;
 				break;
 			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
 			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
 					wbc->sync_mode == WB_SYNC_NONE) {
 				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
 				break;
 			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
  	trace_f2fs_writepages(mapping->host, wbc, DATA);
  	return 0;
  }
Signature · 1 line
2.28.0
maintainer
#3 lore raw
Quoted 76 lines · Chao Yu
Quoted 68 lines · Jaegeuk Kim
Quoted 67 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

          loop {
          queue_io
          progress=__writeback_inodes_wb
                  __writeback_single_inode
                          do_writepages
                                  f2fs_write_data_pages
                                  wbc->pages_skipped +=get_dirty_pages
                          inode->i_state &= ~dirty
                  wrote++
                  requeue_inode
          }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

      wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
   fs/f2fs/data.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/data.c +0 -0
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
   	return ret;
 
Quoted 6 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3241

Quoted 4 lines
fs/f2fs/data.c +2 -1
   skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 11 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 44 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 2 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
   			/* give a priority to WB_SYNC threads */
   			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
   					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
   				done = 1;
   				break;
   			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
   			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
   					wbc->sync_mode == WB_SYNC_NONE) {
   				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
   				break;
   			}
 

Thanks,

Quoted 1 line
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
   	trace_f2fs_writepages(mapping->host, wbc, DATA);
   	return 0;
   }
Signature · 1 line
2.28.0

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

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

maintainer
#4 lore raw
Quoted 97 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

          loop {
          queue_io
          progress=__writeback_inodes_wb
                  __writeback_single_inode
                          do_writepages
                                  f2fs_write_data_pages
                                  wbc->pages_skipped +=get_dirty_pages
                          inode->i_state &= ~dirty
                  wrote++
                  requeue_inode
          }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

      wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
   fs/f2fs/data.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
   	return ret;
   skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 10 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 12 lines
Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

So, my question was why this is the problem?

Quoted 51 lines
Quoted 51 lines
Quoted 3 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
   			/* give a priority to WB_SYNC threads */
   			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
   					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
   				done = 1;
   				break;
   			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
   			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
   					wbc->sync_mode == WB_SYNC_NONE) {
   				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
   				break;
   			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
   	trace_f2fs_writepages(mapping->host, wbc, DATA);
   	return 0;
   }
Signature · 1 line
2.28.0

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

maintainer
#5 lore raw
Quoted 104 lines · Jaegeuk Kim
Quoted 103 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

           loop {
           queue_io
           progress=__writeback_inodes_wb
                   __writeback_single_inode
                           do_writepages
                                   f2fs_write_data_pages
                                   wbc->pages_skipped +=get_dirty_pages
                           inode->i_state &= ~dirty
                   wrote++
                   requeue_inode
           }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

       wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
    fs/f2fs/data.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
    	return ret;
    skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 11 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

So, my question was why this is the problem?

kworker will loop writebacking this requeued inode.

Thanks,

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 4 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
    			/* give a priority to WB_SYNC threads */
    			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				done = 1;
    				break;
    			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
    			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
    				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				break;
    			}
 

Thanks,

Quoted 1 line
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
    	trace_f2fs_writepages(mapping->host, wbc, DATA);
    	return 0;
    }
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line

2.28.0

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

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

maintainer
#6 lore raw
Quoted 112 lines · Chao Yu
Quoted 111 lines · Jaegeuk Kim
Quoted 109 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

           loop {
           queue_io
           progress=__writeback_inodes_wb
                   __writeback_single_inode
                           do_writepages
                                   f2fs_write_data_pages
                                   wbc->pages_skipped +=get_dirty_pages
                           inode->i_state &= ~dirty
                   wrote++
                   requeue_inode
           }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

       wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
    fs/f2fs/data.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
    	return ret;
    skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 11 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 3 lines
Quoted 1 line

So, my question was why this is the problem?

kworker will loop writebacking this requeued inode.

Does it make a problem?

Quoted 55 lines

Thanks,

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 4 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
    			/* give a priority to WB_SYNC threads */
    			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				done = 1;
    				break;
    			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
    			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
    				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				break;
    			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
    	trace_f2fs_writepages(mapping->host, wbc, DATA);
    	return 0;
    }
Signature · 1 line
2.28.0

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

maintainer
#7 lore raw
Quoted 113 lines · Jaegeuk Kim
Quoted 112 lines · Chao Yu
Quoted 111 lines · Jaegeuk Kim
Quoted 109 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

            loop {
            queue_io
            progress=__writeback_inodes_wb
                    __writeback_single_inode
                            do_writepages
                                    f2fs_write_data_pages
                                    wbc->pages_skipped +=get_dirty_pages
                            inode->i_state &= ~dirty
                    wrote++
                    requeue_inode
            }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

        wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
     fs/f2fs/data.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
     	return ret;
     skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 11 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

So, my question was why this is the problem?

kworker will loop writebacking this requeued inode.

Does it make a problem?

The problem here is kworker will loop for ever.

Thanks,

Quoted 56 lines
Quoted 56 lines

Thanks,

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 4 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
     			/* give a priority to WB_SYNC threads */
     			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				done = 1;
     				break;
     			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
     			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
     				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				break;
     			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
     	trace_f2fs_writepages(mapping->host, wbc, DATA);
     	return 0;
     }
Signature · 1 line
2.28.0

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

maintainer
#8 lore raw
Quoted 114 lines · Chao Yu
Quoted 113 lines · Jaegeuk Kim
Quoted 112 lines · Chao Yu
Quoted 111 lines · Jaegeuk Kim
Quoted 109 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

            loop {
            queue_io
            progress=__writeback_inodes_wb
                    __writeback_single_inode
                            do_writepages
                                    f2fs_write_data_pages
                                    wbc->pages_skipped +=get_dirty_pages
                            inode->i_state &= ~dirty
                    wrote++
                    requeue_inode
            }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

        wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
     fs/f2fs/data.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
     	return ret;
     skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 11 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

So, my question was why this is the problem?

kworker will loop writebacking this requeued inode.

Does it make a problem?

The problem here is kworker will loop for ever.

Could you point out where it goes in the loop?

Quoted 59 lines

Thanks,

Quoted 56 lines
Quoted 56 lines

Thanks,

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 4 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
     			/* give a priority to WB_SYNC threads */
     			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				done = 1;
     				break;
     			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
     			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
     				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				break;
     			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
     	trace_f2fs_writepages(mapping->host, wbc, DATA);
     	return 0;
     }
Signature · 1 line
2.28.0

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

maintainer
#9 lore raw
Quoted 117 lines · Jaegeuk Kim
Quoted 116 lines · Chao Yu
Quoted 115 lines · Jaegeuk Kim
Quoted 114 lines · Chao Yu
Quoted 112 lines · Jaegeuk Kim
Quoted 97 lines · Chao Yu
Quoted 75 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

            loop {
            queue_io
            progress=__writeback_inodes_wb
                    __writeback_single_inode
                            do_writepages
                                    f2fs_write_data_pages
                                    wbc->pages_skipped +=get_dirty_pages
                            inode->i_state &= ~dirty
                    wrote++
                    requeue_inode
            }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

        wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
     fs/f2fs/data.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
     	return ret;
     skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted 3 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 10 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here
- inode_dec_dirty_pages

Quoted 12 lines
Quoted 1 line

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

So, my question was why this is the problem?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

kworker will loop writebacking this requeued inode.

Does it make a problem?

The problem here is kworker will loop for ever.

Could you point out where it goes in the loop?

How can we have NodeA IO being stuck in the plug forever? I think f2fs_write_node_pages() should have flushed it before.

Quoted 66 lines
Quoted 60 lines

Thanks,

Quoted 56 lines
Quoted 56 lines

Thanks,

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 4 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
     			/* give a priority to WB_SYNC threads */
     			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				done = 1;
     				break;
     			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
     			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
     				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				break;
     			}
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
     	trace_f2fs_writepages(mapping->host, wbc, DATA);
     	return 0;
     }
Signature · 1 line
2.28.0

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

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

A message that is not in the archive (sent off-list or not yet received): CAHJ8P3KwWXAgRQRD5N6Ut6uEQX8ap368Pm9HOz3gapVS4ymHmA@mail.gmail.com

maintainer
#11 lore raw
Quoted 20 lines · Zhiguo Niu

Hi Jaegeuk,

As f2fs_write_node_pages codes:

2060 <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/fs/f2fs/node.c#2060>
blk_start_plug
<http://172.29.60.15:8083/s?defs=blk_start_plug&project=sprdroidr_trunk>(&plug
<http://172.29.60.15:8083/s?defs=plug&project=sprdroidr_trunk>);2061
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/fs/f2fs/node.c#2061>
f2fs_sync_node_pages
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/fs/f2fs/node.c#f2fs_sync_node_pages>(sbi
<http://172.29.60.15:8083/s?defs=sbi&project=sprdroidr_trunk>, wbc
<http://172.29.60.15:8083/s?defs=wbc&project=sprdroidr_trunk>, *true*, FS_NODE_IO <http://172.29.60.15:8083/s?defs=FS_NODE_IO&project=sprdroidr_trunk>);2062
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/fs/f2fs/node.c#2062>
blk_finish_plug
<http://172.29.60.15:8083/s?defs=blk_finish_plug&project=sprdroidr_trunk>(&plug
<http://172.29.60.15:8083/s?defs=plug&project=sprdroidr_trunk>);

Quoted 1 line

if writeback to sync node pages, blk_statr_plug in line 2060 just do nothing

Isn't it a different task's plug, yes?

Quoted 268 lines

3449 <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3449>
*void* blk_start_plug
<http://172.29.60.15:8083/s?refs=blk_start_plug&project=sprdroidr_trunk>(*struct*
blk_plug <http://172.29.60.15:8083/s?defs=blk_plug&project=sprdroidr_trunk>
*plug <http://172.29.60.15:8083/s?refs=plug&project=sprdroidr_trunk>)3450
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3450>
{3451 <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3451>
*struct* task_struct
<http://172.29.60.15:8083/s?defs=task_struct&project=sprdroidr_trunk>
*tsk <http://172.29.60.15:8083/s?refs=tsk&project=sprdroidr_trunk> =
current <http://172.29.60.15:8083/s?defs=current&project=sprdroidr_trunk>;3452
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3452>
3453 <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3453>

	/*3454  <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3454>
	 * If this is a nested plug, don't actually assign it.3455
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3455>
	 */3456  <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3456>
	*if* (tsk <http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#tsk>->plug
<http://172.29.60.15:8083/s?defs=plug&project=sprdroidr_trunk>)3457
<http://172.29.60.15:8083/xref/sprdroidr_trunk/bsp/kernel/kernel4.14/block/blk-core.c#3457>
		*return*;

so the NodeA IO is pulged in writeback and stuck.

thanks

Quoted 236 lines · Jaegeuk Kim <[email protected]> 于2021年12月17日周五 07:22写道:
Quoted 6 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu
Quoted 4 lines · Jaegeuk Kim
Quoted 3 lines · Chao Yu
Quoted 2 lines · Jaegeuk Kim
Quoted 1 line · Chao Yu

On 2021/11/18 14:46, Chao Yu wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Jaegeuk Kim
Quoted 7 lines · On 11/09, [email protected] wrote:
Quoted 6 lines

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the

node page

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

of inodeB cached into inodeA

writeback:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

wb_workfn
wb_writeback
blk_start_plug

            loop {
            queue_io
            progress=__writeback_inodes_wb
                    __writeback_single_inode
                            do_writepages
                                    f2fs_write_data_pages
                                    wbc->pages_skipped
+=get_dirty_pages
> > > > > > > > >                             inode->i_state &= ~dirty
> > > > > > > > >                     wrote++
> > > > > > > > >                     requeue_inode
> > > > > > > > >             }
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

blk_finish_plug

checkpoint:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data

f2fs_update_data_blkaddr

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

f2fs_wait_on_page_writeback

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio

request in task's plug;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

2. Checkpoint thread writes inodeB's dirty page, and

then wait its node

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

page writeback cached into inodeA which is in

writeback task's plug

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

3. Writeback thread flush inodeB and skip writing the

dirty page as

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
        wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as

PAGECACHE_TAG_DIRTY, writeback

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of

pages_skipped > 0

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

as checkpoint thread is stuck before dec

dirty_pages.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This patch collect correct pages_skipped according to

the tag state in

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

page tree of inode

---
     fs/f2fs/data.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fs/f2fs/data.c static int

Quoted 5 lines
fs/f2fs/data.c +0 -0
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int

__f2fs_write_data_pages(struct address_space *mapping,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fs/f2fs/data.c static int · line 3240

Quoted 5 lines
fs/f2fs/data.c +2 -1
      return ret;
     skip_write:
-     wbc->pages_skipped += get_dirty_pages(inode);
+     wbc->pages_skipped +=
+             mapping_tagged(inode->i_mapping,

PAGECACHE_TAG_DIRTY) ?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Is there any race condition to get 0, if there's any dirty

page? IOWs, it

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Quoted from Jing Xia's explanation:

[T:writeback] [T:checkpoint]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 1 line

- do_writepages -- sync

write inodeB, inc wb_sync_req[DATA]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- f2fs_write_data_pages -

f2fs_write_single_data_page -- write last dirty page

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                     -

f2fs_do_write_data_page

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- set_page_writeback

-- clear page dirty flag and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

PAGECACHE_TAG_DIRTY

tag in radix tree

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                      -

f2fs_outplace_write_data

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                       -

f2fs_update_data_blkaddr

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                        -

f2fs_wait_on_page_writeback -- wait NodeA to writeback here

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

- inode_dec_dirty_pages

bio contains NodeA was plugged in writeback threads

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[1]

Thanks,

Quoted 4 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to

wb_sync_req[DATA]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- wbc->pages_skipped += get_dirty_pages() --

PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- requeue_inode -- requeue inode to wb->b_dirty queue

due to non-zero.pages_skipped

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

So, my question was why this is the problem?

kworker will loop writebacking this requeued inode.

Does it make a problem?

The problem here is kworker will loop for ever.

Could you point out where it goes in the loop?

How can we have NodeA IO being stuck in the plug forever? I think f2fs_write_node_pages() should have flushed it before.

Quoted 11 lines
Quoted 11 lines

Thanks,

Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

seems the current condition is just requeuing the inode as

dirty, but next

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flushing time will remove it from dirty list. Is this

giving too much overheads?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I prefer to let writeback thread call blk_flush_plug() after

skipping

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

writepages() due to wb_sync_req[DATA/NODE] check condition,

thoughts?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

fs/f2fs/data.c static int

Quoted 6 lines
fs/f2fs/data.c +0 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int

f2fs_write_cache_pages(struct address_space *mapping,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fs/f2fs/data.c static int · line 3087

Quoted 1 line
fs/f2fs/data.c +0 -0
                          /* give a priority to WB_SYNC

threads */

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fs/f2fs/data.c static int · line 3088

Quoted 1 line
fs/f2fs/data.c +0 -0
                          if

(atomic_read(&sbi->wb_sync_req[DATA]) &&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fs/f2fs/data.c static int · line 3089

Quoted 1 line
fs/f2fs/data.c +0 -0
                                          wbc->sync_mode ==

WB_SYNC_NONE) {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

fs/f2fs/data.c static int · line 3091

Quoted 2 lines
fs/f2fs/data.c +2 -0
+                         if (current->plug)
+

blk_flush_plug(current->plug, false);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/node.c int f2fs_sync_node_pages(struct

Quoted 8 lines
fs/f2fs/data.c +0 -0
                                  done = 1;
                                  break;
                          }
fs/f2fs/node.c +0 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct

f2fs_sb_info *sbi,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fs/f2fs/node.c int f2fs_sync_node_pages(struct · line 1946

Quoted 1 line
fs/f2fs/node.c +0 -0
                          if

(atomic_read(&sbi->wb_sync_req[NODE]) &&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fs/f2fs/node.c int f2fs_sync_node_pages(struct · line 1947

Quoted 1 line
fs/f2fs/node.c +0 -0
                                          wbc->sync_mode ==

WB_SYNC_NONE) {

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

fs/f2fs/node.c int f2fs_sync_node_pages(struct · line 1950

Quoted 3 lines
fs/f2fs/node.c +2 -0
                                  done = 1;
+                         if (current->plug)
+

blk_flush_plug(current->plug, false);

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
fs/f2fs/node.c +0 -0
                                  break;
                          }
 

Thanks,

Quoted 7 lines
Quoted 7 lines
fs/f2fs/data.c +1 -1
+             get_dirty_pages(inode) : 0;
      trace_f2fs_writepages(mapping->host, wbc, DATA);
      return 0;
     }
--

2.28.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]

https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

maintainer
#12 lore raw
In reply to Chao Yu
Quoted 79 lines · Chao Yu
Quoted 78 lines · Chao Yu
Quoted 68 lines · Jaegeuk Kim
Quoted 67 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

           loop {
           queue_io
           progress=__writeback_inodes_wb
                   __writeback_single_inode
                           do_writepages
                                   f2fs_write_data_pages
                                   wbc->pages_skipped +=get_dirty_pages
                           inode->i_state &= ~dirty
                   wrote++
                   requeue_inode
           }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

       wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
    fs/f2fs/data.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/data.c +0 -0
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
    	return ret;
 
Quoted 6 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3241

Quoted 4 lines
fs/f2fs/data.c +2 -1
    skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted from Jing Xia's explanation:

Quoted 17 lines
Quoted 1 line

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 9 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here

Jaegeuk,

checkpoint() will stuck on waiting NodeA to writeback.

Quoted 14 lines
Quoted 3 lines

- inode_dec_dirty_pages

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Meanwhile, kworker plugged NodeA, and then loop writebacking inode due to inode will be requeued all the time.

Thanks,

Quoted 57 lines
Quoted 38 lines
Quoted 3 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
    			/* give a priority to WB_SYNC threads */
    			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				done = 1;
    				break;
    			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
    			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
    				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				break;
    			}
 

Thanks,

Quoted 1 line
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
    	trace_f2fs_writepages(mapping->host, wbc, DATA);
    	return 0;
    }
Signature · 1 line
2.28.0

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

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

maintainer
#13 lore raw
Quoted 116 lines · Chao Yu
Quoted 78 lines · Chao Yu
Quoted 77 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

           loop {
           queue_io
           progress=__writeback_inodes_wb
                   __writeback_single_inode
                           do_writepages
                                   f2fs_write_data_pages
                                   wbc->pages_skipped +=get_dirty_pages
                           inode->i_state &= ~dirty
                   wrote++
                   requeue_inode
           }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

       wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
    fs/f2fs/data.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
    	return ret;
    skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted from Jing Xia's explanation:

Quoted 17 lines
Quoted 1 line

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 9 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here

Jaegeuk,

checkpoint() will stuck on waiting NodeA to writeback.

Quoted 14 lines
Quoted 3 lines

- inode_dec_dirty_pages

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 2 lines

Meanwhile, kworker plugged NodeA, and then loop writebacking inode due to inode will be requeued all the time.

I'm thinking that this will be released after finishing node writes in a different context. Then, this loop can happen in that time period which is NOT forever. But, if we want to avoid this temporary loop, we may be able to decrease the dirty count before f2fs_update_data_blkaddr().

Quoted 60 lines

Thanks,

Quoted 57 lines
Quoted 38 lines
Quoted 3 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
    			/* give a priority to WB_SYNC threads */
    			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				done = 1;
    				break;
    			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
    			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
    					wbc->sync_mode == WB_SYNC_NONE) {
    				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
    				break;
    			}
 

Thanks,

Quoted 1 line
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
    	trace_f2fs_writepages(mapping->host, wbc, DATA);
    	return 0;
    }
Signature · 1 line
2.28.0

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

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

maintainer
#14 lore raw
Quoted 117 lines · Jaegeuk Kim
Quoted 116 lines · Chao Yu
Quoted 78 lines · Chao Yu
Quoted 77 lines · Chao Yu
Quoted 61 lines · Jaegeuk Kim
Quoted 60 lines · On 11/09, [email protected] wrote:

From: Zhiguo Niu <[email protected]>

There could be a scenario as following:
The inodeA and inodeB are in b_io queue of writeback inodeA : f2fs's node inode
inodeB : a dir inode with only one dirty pages, and the node page of inodeB cached into inodeA

writeback:

wb_workfn
wb_writeback
blk_start_plug

            loop {
            queue_io
            progress=__writeback_inodes_wb
                    __writeback_single_inode
                            do_writepages
                                    f2fs_write_data_pages
                                    wbc->pages_skipped +=get_dirty_pages
                            inode->i_state &= ~dirty
                    wrote++
                    requeue_inode
            }

blk_finish_plug

checkpoint:

f2fs_write_checkpoint
f2fs_sync_dirty_inodes
filemap_fdatawrite
do_writepages
f2fs_write_data_pages
f2fs_write_single_data_page
f2fs_do_write_data_page
set_page_writeback f2fs_outplace_write_data
f2fs_update_data_blkaddr
f2fs_wait_on_page_writeback
inode_dec_dirty_pages

1. Writeback thread flush inodeA, and push it's bio request in task's plug;
2. Checkpoint thread writes inodeB's dirty page, and then wait its node page writeback cached into inodeA which is in writeback task's plug
3. Writeback thread flush inodeB and skip writing the dirty page as

        wb_sync_req[DATA] > 0.

4. As none of the inodeB's page is marked as PAGECACHE_TAG_DIRTY, writeback thread clear inodeB's dirty state.
5. Then inodeB is moved from b_io to b_dirty because of pages_skipped > 0 as checkpoint thread is stuck before dec dirty_pages.

This patch collect correct pages_skipped according to the tag state in page tree of inode

---
     fs/f2fs/data.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines

fs/f2fs/data.c static int __f2fs_write_data_pages(struct address_space *mapping, · line 3240

Quoted 10 lines
fs/f2fs/data.c +2 -1
index f4fd6c246c9a..e98628e3868c 100644
@@ -3237,7 +3237,9 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
     	return ret;
     skip_write:
-	wbc->pages_skipped += get_dirty_pages(inode);
+	wbc->pages_skipped +=
+		mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ?

Is there any race condition to get 0, if there's any dirty page? IOWs, it

Quoted from Jing Xia's explanation:

Quoted 17 lines
Quoted 1 line

[T:writeback] [T:checkpoint]

My bad, [1] should be here:

bio contains NodeA was plugged in writeback threads

Thanks,

Quoted 9 lines

- do_writepages -- sync write inodeB, inc wb_sync_req[DATA]
- f2fs_write_data_pages
- f2fs_write_single_data_page -- write last dirty page
- f2fs_do_write_data_page
- set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree
- f2fs_outplace_write_data
- f2fs_update_data_blkaddr
- f2fs_wait_on_page_writeback -- wait NodeA to writeback here

Jaegeuk,

checkpoint() will stuck on waiting NodeA to writeback.

Quoted 14 lines
Quoted 3 lines

- inode_dec_dirty_pages

bio contains NodeA was plugged in writeback threads

[1]

Thanks,

Quoted 6 lines

- writeback_sb_inodes
- writeback_single_inode
- do_writepages
- f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA]
- wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one
- requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped

Quoted 6 lines
Quoted 2 lines

Meanwhile, kworker plugged NodeA, and then loop writebacking inode due to inode will be requeued all the time.

I'm thinking that this will be released after finishing node writes in a different context. Then, this loop can happen in that time period which is NOT forever. But, if we want to avoid this temporary loop, we may be

I doubt it may break due to below condition in writeback_sb_inodes():

		if (need_resched()) {
			/*
			 * We're trying to balance between building up a nice
			 * long list of IOs to improve our merge rate, and
			 * getting those IOs out quickly for anyone throttling
			 * in balance_dirty_pages().  cond_resched() doesn't
			 * unplug, so get our IOs out the door before we
			 * give up the CPU.
			 */
			if (current->plug)
				blk_flush_plug(current->plug, false);
			cond_resched();
		}

But as Zhiguo Niu and Jing Xia reported, blk_flush_plug was not executed...

Quoted 1 line

able to decrease the dirty count before f2fs_update_data_blkaddr().

I guess there is one simple way, we can force flushing plugged bio via blk_flush_plug(current->plug, false) once we skip writeback in writepages() due to sbi->wb_sync_req[DATA/NODE] is valid.

Thoughts?

Thanks,

Quoted 61 lines
Quoted 61 lines

Thanks,

Quoted 57 lines
Quoted 38 lines
Quoted 3 lines

seems the current condition is just requeuing the inode as dirty, but next flushing time will remove it from dirty list. Is this giving too much overheads?

I prefer to let writeback thread call blk_flush_plug() after skipping writepages() due to wb_sync_req[DATA/NODE] check condition, thoughts?

fs/f2fs/data.c +2 -0
index 9f754aaef558..b6e1ed73f8f5 100644
@@ -3087,6 +3087,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
     			/* give a priority to WB_SYNC threads */
     			if (atomic_read(&sbi->wb_sync_req[DATA]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				done = 1;
     				break;
     			}
fs/f2fs/node.c +2 -0
index 556fcd8457f3..dd9a817d8dab 100644
@@ -1946,6 +1946,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
     			if (atomic_read(&sbi->wb_sync_req[NODE]) &&
     					wbc->sync_mode == WB_SYNC_NONE) {
     				done = 1;
+				if (current->plug)
+					blk_flush_plug(current->plug, false);
     				break;
     			}
 

Thanks,

Quoted 1 line
Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/data.c +1 -0
+		get_dirty_pages(inode) : 0;
     	trace_f2fs_writepages(mapping->host, wbc, DATA);
     	return 0;
     }
Signature · 1 line
2.28.0

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

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