f2fs: avoid race between zero_range and background GC
PATCH 1/1 f2fs: avoid race between zero_range and background GC
Thread A Background GC
- f2fs_zero_range
- truncate_pagecache_range
- gc_data_segment
- get_read_data_page
- move_data_page
- set_page_dirty
- set_cold_data
- f2fs_do_zero_range
- dn->data_blkaddr = NEW_ADDR;
- f2fs_set_data_blkaddr
Actually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by zero_range().
Use i_gc_rwsem[WRITE] to avoid such race condition.
--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)
fs/f2fs/file.c +2 -0
@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)
@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }
Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerQuoted 12 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
Quoted 2 lines
Actually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().
But, it doesn't matter too much, right?
Quoted 1 line
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Quoted 28 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }Signature · 1 line
2.18.0.rc1
Chao Yu
maintainerQuoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
Quoted 4 lines
Quoted 2 lines
Actually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after f2fs_do_zero_range(), result of zero_range() should be wrong, as zeroed page contains valid user data.
Quoted 4 lines
Quoted 2 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 29 lines
Quoted 29 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerQuoted 14 lines · Chao Yu
Quoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Actually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.
How about truncating page caches after block address change or doing it twice before and after?
Quoted 35 lines
Quoted 5 lines
Quoted 3 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 25 lines
Quoted 25 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/file.c +0
-0return ret; }Signature · 1 line
2.18.0.rc1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Chao Yu
maintainerQuoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
- f2fs_zero_range
- truncate_pagecache_range
- gc_data_segment
- get_read_data_page
- move_data_page
- set_page_dirty
- set_cold_data
- f2fs_do_zero_range
- dn->data_blkaddr = NEW_ADDR;
- f2fs_set_data_blkaddr
bdi-flusher
- __write_data_page
- f2fs_update_data_blkaddr : data_blkaddr has been updated here.
- truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?
How about this case?
Thanks,
Quoted 40 lines
Quoted 40 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 29 lines
Quoted 29 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerQuoted 45 lines · Chao Yu
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
bdi-flusher
-__write_data_page
-f2fs_update_data_blkaddr:data_blkaddrhas been updated here.
-truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?
Quoted 1 line
How about this case?
So, truncating pages under dnode lock can address it?
Quoted 43 lines
Thanks,
Quoted 40 lines
Quoted 40 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 29 lines
Quoted 29 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }Signature · 1 line
2.18.0.rc1
Chao Yu
maintainerQuoted 46 lines · Jaegeuk Kim
Quoted 45 lines · Chao Yu
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
bdi-flusher
-__write_data_page
-f2fs_update_data_blkaddr:data_blkaddrhas been updated here.
-truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?
Quoted 3 lines
Quoted 1 line
How about this case?
So, truncating pages under dnode lock can address it?
Normally, our lock dependency is
->writepage()
lock data page -> lock dnode page
here
lock dnode page -> truncate_pagecache_range::lock data page
Will easily cause deadlock?
Thanks,
Quoted 44 lines
Quoted 44 lines
Thanks,
Quoted 40 lines
Quoted 40 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 29 lines
Quoted 29 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);return ret; }Signature · 1 line
2.18.0.rc1
Jaegeuk Kim
maintainerQuoted 53 lines · Chao Yu
Quoted 46 lines · Jaegeuk Kim
Quoted 45 lines · Chao Yu
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
bdi-flusher
-__write_data_page
-f2fs_update_data_blkaddr:data_blkaddrhas been updated here.
-truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?Quoted 3 lines
Quoted 1 line
How about this case?
So, truncating pages under dnode lock can address it?
Normally, our lock dependency is
Quoted 7 lines
->writepage()
lock data page -> lock dnode pagehere
lock dnode page ->truncate_pagecache_range::lockdata pageWill easily cause deadlock?
Yeah. Can we add an inode flag to bypass GC in this case, then?
Quoted 43 lines
Thanks,
Quoted 40 lines
Quoted 40 lines
Thanks,
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 25 lines
Quoted 25 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/file.c +0
-0return ret; }Signature · 1 line
2.18.0.rc1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jaegeuk Kim
maintainerQuoted 57 lines · Jaegeuk Kim
Quoted 56 lines · Chao Yu
Quoted 46 lines · Jaegeuk Kim
Quoted 45 lines · Chao Yu
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
bdi-flusher
-__write_data_page
-f2fs_update_data_blkaddr:data_blkaddrhas been updated here.
-truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?Quoted 3 lines
Quoted 1 line
How about this case?
So, truncating pages under dnode lock can address it?
Normally, our lock dependency is
->writepage()
lock data page -> lock dnode page
Quoted 6 lines
Quoted 4 lines
here
lock dnode page ->truncate_pagecache_range::lockdata pageWill easily cause deadlock?
Yeah. Can we add an inode flag to bypass GC in this case, then?
Hmm, BTW, how about using i_gc_rwsem[WRITE] in a very narrow scope?
for (index = pg_start; index < pg_end;) {
f2fs_lock_op();
down_write(i_gc_rwsem[WRITE]);
truncate_page_cache_range(index, index + 4k);
f2fs_do_zero_range(&dn, index, end);
up_write(i_gc_rwsem[WRITE]);
f2fs_unlock_op();
f2fs_balance_fs();
}Quoted 56 lines
Quoted 44 lines
Thanks,
Quoted 40 lines
Quoted 40 lines
Thanks,
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 25 lines
Quoted 25 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/file.c +0
-0return ret; }Signature · 1 line
2.18.0.rc1------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 58 lines · Jaegeuk Kim
Quoted 57 lines · Jaegeuk Kim
Quoted 56 lines · Chao Yu
Quoted 46 lines · Jaegeuk Kim
Quoted 45 lines · Chao Yu
Quoted 18 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Chao Yu
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddrActually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by
zero_range().Quoted 7 lines
Quoted 4 lines
Quoted 1 line
But, it doesn't matter too much, right?
No, if the dirtied page is writebacked after
f2fs_do_zero_range(), result ofzero_range()should be wrong, as zeroed page contains valid user data.How about truncating page caches after block address change or doing it twice before and after?
Thread A Background GC
-f2fs_zero_range
-truncate_pagecache_range
-gc_data_segment
-get_read_data_page
-move_data_page
-set_page_dirty
-set_cold_data
-f2fs_do_zero_range
-dn->data_blkaddr=NEW_ADDR;
-f2fs_set_data_blkaddr
bdi-flusher
-__write_data_page
-f2fs_update_data_blkaddr:data_blkaddrhas been updated here.
-truncate_pagecache_range
: data & dnode has been writebacked before page cache truncation?Quoted 3 lines
Quoted 1 line
How about this case?
So, truncating pages under dnode lock can address it?
Normally, our lock dependency is
->writepage()
lock data page -> lock dnode page
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
here
lock dnode page ->truncate_pagecache_range::lockdata pageWill easily cause deadlock?
Yeah. Can we add an inode flag to bypass GC in this case, then?
Hmm, BTW, how about using i_gc_rwsem[WRITE] in a very narrow scope?
Oh, I can see that you submitted a patch to change lock dependency to:
f2fs_lock_op() -> down_write(i_gc_rwsem[WRITE])
At a glance, I haven't see any place can cause deadlock now.
Quoted 10 lines
for (index = pg_start; index < pg_end;) {
f2fs_lock_op();
down_write(i_gc_rwsem[WRITE]);
truncate_page_cache_range(index, index + 4k);
f2fs_do_zero_range(&dn, index, end);
up_write(i_gc_rwsem[WRITE]);
f2fs_unlock_op();
f2fs_balance_fs();
}Let me update the patch as you suggested.
Thanks,
Quoted 60 lines
Quoted 45 lines
Quoted 45 lines
Thanks,
Quoted 40 lines
Quoted 40 lines
Thanks,
Quoted 36 lines
Quoted 36 lines
Quoted 6 lines
Quoted 4 lines
Use i_gc_rwsem[WRITE] to avoid such race condition.
Hope to avoid abusing i_gc_rwsem[] tho.
Agreed, let's try avoiding until we have to use it.
Thanks,
Quoted 25 lines
Quoted 25 lines
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/file.c | 2 ++ 1 file changed, 2 insertions(+)fs/f2fs/file.c +2
-0@@ -1309,6 +1309,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,if (ret)return ret; +down_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);down_write (&F2FS_I (inode)->i_mmap_sem); ret =filemap_write_and_wait_range (mapping, offset, offset + len -1 );if (ret)@@ -1389,6 +1390,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, } out_sem:up_write (&F2FS_I (inode)->i_mmap_sem); +up_write (&F2FS_I (inode)->i_gc_rwsem[WRITE ]);Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
fs/f2fs/file.c +0
-0return ret; }Signature · 1 line
2.18.0.rc1------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel.