f2fs: replace __get_victim by dirty_segments in FG_GC
PATCH 1/2 f2fs: replace __get_victim by dirty_segments in FG_GC
In FG_GC process, it will search victim section twice. This will cause some dirty section with less valid blocks skip garbage collection.
section # 26425 : valid blocks # 3
142.037567: get_victim_by_default: victim 26425 : valid blocks # 3
142.037585: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 244 142.039494: f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19022 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 24 142.070247: new_curseg: Debug: alloc new segment 26746
142.244341: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26054 ofs_unit = 1, pre_victim_secno = 26054, prefree = 0, free = 243 142.254475: do_garbage_collect: Debug: FG_GC, seg_freed = 1
142.293131: f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23466 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 244 142.319001: f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23467 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 244 142.368879: get_victim_by_default: victim 26425 : valid blocks # 3
142.368894: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 244 142.378127: f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19612 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 24 142.416917: new_curseg: Debug: alloc new segment 26054
142.656794: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 25404 ofs_unit = 1, pre_victim_secno = 25404, prefree = 0, free = 243 142.662139: do_garbage_collect: Debug: FG_GC, seg_freed = 1
142.684159: new_curseg: Debug: alloc new segment 25197
142.685059: get_victim_by_default: victim 26425 : valid blocks # 3
142.685079: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 243 142.701427: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26238 ofs_unit = 1, pre_victim_secno = 26238, prefree = 0, free = 243 142.707105: do_garbage_collect: Debug: FG_GC, seg_freed = 1
142.802444: f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23473 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 244 142.804422: get_victim_by_default: victim 26425 : valid blocks # 3
142.804443: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 244 142.851567: f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19092 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 24 142.865014: new_curseg: Debug: alloc new segment 26238
143.082245: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26307 ofs_unit = 1, pre_victim_secno = 26307, prefree = 0, free = 244 143.088252: do_garbage_collect: Debug: FG_GC, seg_freed = 1
143.128307: new_curseg: Debug: alloc new segment 25404
143.181846: get_victim_by_default: victim 26425 : valid blocks # 3
143.181872: f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425 ofs_unit = 1, pre_victim_secno = 26425, prefree = 0, free = 244
--- fs/f2fs/gc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/f2fs/gc.c +2 -4
@@ -943,12 +943,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)* enough free sections, we should flush dent/node blocks and do * garbage collections. */ -if (__get_victim (sbi, &segno, gc_type) || -prefree_segments (sbi)) { +if (dirty_segments (sbi) ||prefree_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop; - segno =NULL_SEGNO ; }else if (has_not_enough_free_secs (sbi,0 ,0 )) { ret =write_checkpoint (sbi, &cpc);if (ret)
@@ -959,7 +957,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) goto stop; } -if (segno ==NULL_SEGNO && !__get_victim (sbi, &segno, gc_type)) +if (!__get_victim (sbi, &segno, gc_type)) goto stop; ret =0 ;
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
PATCH 2/2 f2fs: remove unnecessary wait in write_begin
It has already waited page stable in grab_cache_page_write_begin, so we remove this unnecessary wait.
--- fs/f2fs/data.c | 2 -- 1 file changed, 2 deletions(-)
fs/f2fs/data.c +0 -2
@@ -1783,8 +1783,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, } } -f2fs_wait_on_page_writeback (page,DATA , false); -/* wait for GCed encrypted page writeback */ if (f2fs_encrypted_inode (inode) &&S_ISREG (inode->i_mode))f2fs_wait_on_encrypted_page_writeback (sbi, blkaddr);
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Jaegeuk Kim
maintainerRe: [PATCH 2/2] f2fs: remove unnecessary wait in write_begin
Quoted 2 lines · Yunlei He
It has already waited page stable in
grab_cache_page_write_begin, so we remove this unnecessary wait.
I also got a deadlock in my perf test, and I wrote another patch to resolve it by replacing grab_cache_page_write_begin() with pagecache_get_page().
Quoted 1 line
From
8baf724c638813ab8d2e9bad99f5b8683e788da3Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <[email protected]>
Date: Fri, 17 Feb 2017 09:55:55 -0800
Subject: [PATCH] f2fs: do not wait for writeback in write_begin
Otherwise we can get livelock like below.
[79880.428136] dbench D 0 18405 18404 0x00000000 [79880.428139] Call Trace: [79880.428142] __schedule+0x219/0x6b0 [79880.428144] schedule+0x36/0x80 [79880.428147] schedule_timeout+0x243/0x2e0 [79880.428152] ? update_sd_lb_stats+0x16b/0x5f0 [79880.428155] ? ktime_get+0x3c/0xb0 [79880.428157] io_schedule_timeout+0xa6/0x110 [79880.428161] __lock_page+0xf7/0x130 [79880.428164] ? unlock_page+0x30/0x30 [79880.428167] pagecache_get_page+0x16b/0x250 [79880.428171] grab_cache_page_write_begin+0x20/0x40 [79880.428182] f2fs_write_begin+0xa2/0xdb0 [f2fs] [79880.428192] ? f2fs_mark_inode_dirty_sync+0x16/0x30 [f2fs] [79880.428197] ? kmem_cache_free+0x79/0x200 [79880.428203] ? __mark_inode_dirty+0x17f/0x360 [79880.428206] generic_perform_write+0xbb/0x190 [79880.428213] ? file_update_time+0xa4/0xf0 [79880.428217] __generic_file_write_iter+0x19b/0x1e0 [79880.428226] f2fs_file_write_iter+0x9c/0x180 [f2fs] [79880.428231] __vfs_write+0xc5/0x140 [79880.428235] vfs_write+0xb2/0x1b0 [79880.428238] SyS_write+0x46/0xa0 [79880.428242] entry_SYSCALL_64_fastpath+0x1e/0xad
--- fs/f2fs/data.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/data.c +6 -1
@@ -1759,7 +1759,12 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, goto fail; } repeat: - page =grab_cache_page_write_begin (mapping, index, flags); +/* +* Do not use grab_cache_page_write_begin() to avoid deadlock due to +* wait_for_stable_page. Will wait that below with our IO control. +*/ + page =pagecache_get_page (mapping, index, +FGP_LOCK |FGP_WRITE |FGP_CREAT ,GFP_NOFS );if (!page) { err = -ENOMEM ; goto fail;
Signature · 6 lines
2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Chao Yu
Reviewed-byRe: [PATCH 2/2] f2fs: remove unnecessary wait in write_begin
Quoted 39 lines · Jaegeuk Kim
Quoted 2 lines · Yunlei He
It has already waited page stable in
grab_cache_page_write_begin, so we remove this unnecessary wait.I also got a deadlock in my perf test, and I wrote another patch to resolve it by replacing
grab_cache_page_write_begin()withpagecache_get_page().Quoted 1 line
From
8baf724c638813ab8d2e9bad99f5b8683e788da3Mon Sep 17 00:00:00 2001From: Jaegeuk Kim <[email protected]>
Date: Fri, 17 Feb 2017 09:55:55 -0800
Subject: [PATCH] f2fs: do not wait for writeback inwrite_beginOtherwise we can get livelock like below.
[79880.428136] dbench D 0 18405 18404 0x00000000 [79880.428139] Call Trace: [79880.428142] __schedule+0x219/0x6b0 [79880.428144] schedule+0x36/0x80 [79880.428147] schedule_timeout+0x243/0x2e0 [79880.428152] ? update_sd_lb_stats+0x16b/0x5f0 [79880.428155] ? ktime_get+0x3c/0xb0 [79880.428157] io_schedule_timeout+0xa6/0x110 [79880.428161] __lock_page+0xf7/0x130 [79880.428164] ? unlock_page+0x30/0x30 [79880.428167] pagecache_get_page+0x16b/0x250 [79880.428171] grab_cache_page_write_begin+0x20/0x40 [79880.428182] f2fs_write_begin+0xa2/0xdb0 [f2fs] [79880.428192] ? f2fs_mark_inode_dirty_sync+0x16/0x30 [f2fs] [79880.428197] ? kmem_cache_free+0x79/0x200 [79880.428203] ? __mark_inode_dirty+0x17f/0x360 [79880.428206] generic_perform_write+0xbb/0x190 [79880.428213] ? file_update_time+0xa4/0xf0 [79880.428217] __generic_file_write_iter+0x19b/0x1e0 [79880.428226] f2fs_file_write_iter+0x9c/0x180 [f2fs] [79880.428231] __vfs_write+0xc5/0x140 [79880.428235] vfs_write+0xb2/0x1b0 [79880.428238] SyS_write+0x46/0xa0 [79880.428242] entry_SYSCALL_64_fastpath+0x1e/0xad
Quoted 2 lines
Fixes cae96a5c8ab6 ("f2fs: check io submission more precisely")Signed-off-by Jaegeuk Kim <[email protected]>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Jaegeuk Kim
maintainerHi Yunlei,
I also removed "segno = NULL_SEGNO;" in the beginning part near gc_more.
Thanks,
Quoted 69 lines · Yunlei He
In
FG_GCprocess, it will search victim section twice. This will cause some dirty section with less valid blocks skip garbage collection.section # 26425 : valid blocks # 3
142.037567:get_victim_by_default: victim 26425 : valid blocks # 3
142.037585:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.039494:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19022ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.070247:new_curseg: Debug: alloc new segment 26746
142.244341:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26054ofs_unit= 1,pre_victim_secno= 26054, prefree = 0, free = 243 142.254475:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.293131:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23466ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.319001:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23467ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.368879:get_victim_by_default: victim 26425 : valid blocks # 3
142.368894:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.378127:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19612ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.416917:new_curseg: Debug: alloc new segment 26054
142.656794:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 25404ofs_unit= 1,pre_victim_secno= 25404, prefree = 0, free = 243 142.662139:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.684159:new_curseg: Debug: alloc new segment 25197
142.685059:get_victim_by_default: victim 26425 : valid blocks # 3
142.685079:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 243 142.701427:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26238ofs_unit= 1,pre_victim_secno= 26238, prefree = 0, free = 243 142.707105:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.802444:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23473ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.804422:get_victim_by_default: victim 26425 : valid blocks # 3
142.804443:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.851567:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19092ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.865014:new_curseg: Debug: alloc new segment 26238
143.082245:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26307ofs_unit= 1,pre_victim_secno= 26307, prefree = 0, free = 244 143.088252:do_garbage_collect: Debug:FG_GC,seg_freed= 1
143.128307:new_curseg: Debug: alloc new segment 25404
143.181846:get_victim_by_default: victim 26425 : valid blocks # 3
143.181872:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/gc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/f2fs/gc.c +2
-4@@ -943,12 +943,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)* enough free sections, we should flush dent/node blocks and do * garbage collections. */ -if (__get_victim (sbi, &segno, gc_type) || -prefree_segments (sbi)) { +if (dirty_segments (sbi) ||prefree_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop; - segno =NULL_SEGNO ; }else if (has_not_enough_free_secs (sbi,0 ,0 )) { ret =write_checkpoint (sbi, &cpc);if (ret)@@ -959,7 +957,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) goto stop; } -if (segno ==NULL_SEGNO && !__get_victim (sbi, &segno, gc_type)) +if (!__get_victim (sbi, &segno, gc_type)) goto stop; ret =0 ;Signature · 1 line
2.10.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Chao Yu
Reviewed-byQuoted 43 lines · Jaegeuk Kim
Hi Yunlei,
I also removed "segno =
NULL_SEGNO;" in the beginning part neargc_more.Thanks,
Quoted 36 lines · Yunlei He
In
FG_GCprocess, it will search victim section twice. This will cause some dirty section with less valid blocks skip garbage collection.section # 26425 : valid blocks # 3
142.037567:get_victim_by_default: victim 26425 : valid blocks # 3
142.037585:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.039494:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19022ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.070247:new_curseg: Debug: alloc new segment 26746
142.244341:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26054ofs_unit= 1,pre_victim_secno= 26054, prefree = 0, free = 243 142.254475:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.293131:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23466ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.319001:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23467ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.368879:get_victim_by_default: victim 26425 : valid blocks # 3
142.368894:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.378127:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19612ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.416917:new_curseg: Debug: alloc new segment 26054
142.656794:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 25404ofs_unit= 1,pre_victim_secno= 25404, prefree = 0, free = 243 142.662139:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.684159:new_curseg: Debug: alloc new segment 25197
142.685059:get_victim_by_default: victim 26425 : valid blocks # 3
142.685079:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 243 142.701427:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26238ofs_unit= 1,pre_victim_secno= 26238, prefree = 0, free = 243 142.707105:do_garbage_collect: Debug:FG_GC,seg_freed= 1
142.802444:f2fs_get_victim: dev = (259,30), type = Warm DATA, policy = (Background GC, SSR-mode, Greedy), victim = 23473ofs_unit= 1,pre_victim_secno= -1, prefree = 0, free = 244 142.804422:get_victim_by_default: victim 26425 : valid blocks # 3
142.804443:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244 142.851567:f2fs_get_victim: dev = (259,30), type = Hot DATA, policy = (Background GC, SSR-mode, Greedy), victim = 19092ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 24 142.865014:new_curseg: Debug: alloc new segment 26238
143.082245:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26307ofs_unit= 1,pre_victim_secno= 26307, prefree = 0, free = 244 143.088252:do_garbage_collect: Debug:FG_GC,seg_freed= 1
143.128307:new_curseg: Debug: alloc new segment 25404
143.181846:get_victim_by_default: victim 26425 : valid blocks # 3
143.181872:f2fs_get_victim: dev = (259,30), type = No TYPE, policy = (Foreground GC, LFS-mode, Greedy), victim = 26425ofs_unit= 1,pre_victim_secno= 26425, prefree = 0, free = 244Signed-off-by Yunlei He <[email protected]>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot