f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the other
Subsystems (2)
RFC PATCH 1/1 f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the other
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)
fs/f2fs/gc.c +9 -2
@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;
@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;
fs/f2fs/segment.c +18 -3
@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }
@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );
@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;
@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */
@@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);
fs/f2fs/segment.h +6 -0
@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };
@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; } +static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
Signature · 1 line
2.10.1
A critical case is using the free segments as data segments which are previously node segments to the old checkpoint. With fault injecting of the newer CP pack, fsck can find errors when checking the sanity of nid.
Quoted 141 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +6
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; } +static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
Hi Weichao,
Quoted 3 lines · guoweichao
A critical case is using the free segments as data segments which are previously node segments to the old checkpoint. With fault injecting of the newer CP pack, fsck can find errors when checking the sanity of nid.
Sorry to interrupt because I'm just curious about this scenario and the detail.
As far as I know, if the whole blocks in a segment become invalid,
the segment will become PREFREE, and then if a checkpoint is followed, we can reuse this segment or discard the whole segment safely after this checkpoint was done
(I think It makes sure that this segment is certainly FREE and not reused in this checkpoint).
If the segment in the old checkpoint is a node segment, and node blocks in the segment are all invalid until the new checkpoint. It seems no danger to reuse the FREE node segment as a data segment in the next checkpoint?
or something related to SPOR? In my mind f2fs-tools ignores POR node chain...
Thanks,
Quoted 133 lines · Weichao Guo
Quoted 132 lines
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Hi Weichao,
Quoted 4 lines · guoweichao
Hi Xiang,
it's not related to SPOR. Just consider the case given by Chao Yu.
(It seems this email was not sent successfully, I resend it just for reference only) Oh I see, I have considered the scenario what Chao said before.
1. write data into segment x;
2. write checkpoint A;
3. remove data in segment x;
4. write checkpoint B;
5. issue discard or write data into segment x;
6. sudden power-cut
Since f2fs is designed for double backup, 5) and 6), I think, actually belongs to checkpoint C. and when we are in checkpoint C, checkpoint A becomes unsafe because the latest checkpoint is B. and I think in that case we cannot prevent data writeback or something to pollute checkpoint A.
However, node segments (another metadata) would be special,
but I have no idea whether introducing PRE2 would make all cases safe or not.
In addition, if some data segments change between checkpoint A and C,
some weird data that it didn't have (new data or data from other files) would be gotten when switching back to checkpoint A.
Thanks,
Quoted 182 lines
Thanks,
*From:*Gao Xiang
*To:*guoweichao,
*Cc:*[email protected],heyunlei,
*Date:*2018-01-20 11:49:22
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 3 lines · guoweichao
A critical case is using the free segments as data segments which are previously node segments to the old checkpoint. With fault injecting of the newer CP pack, fsck can find errors when checking the sanity
of nid.
Sorry to interrupt because I'm just curious about this scenario and the detail.As far as I know, if the whole blocks in a segment become invalid, the segment will become PREFREE, and then if a checkpoint is followed, we can reuse this segment or
discard the whole segment safely after this checkpoint was done (I think It makes sure that this segment is certainly FREE and not reused in this checkpoint).If the segment in the old checkpoint is a node segment, and node blocks in the segment are all invalid until the new checkpoint.
It seems no danger to reuse the FREE node segment as a data segment in the next checkpoint?or something related to SPOR? In my mind f2fs-tools ignores POR node chain...
Thanks,
Quoted 21 lines · Weichao Guo
Quoted 20 lines
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>---
fs/f2fs/gc.c | 11 +++++++++--
fs/f2fs/segment.c| 21 ++++++++++++++++++---
fs/f2fs/segment.h| 6 ++++++3 files changed, 33 insertions(+), 5 deletions(-)Quoted 6 lines
fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, · line 1030
Quoted 6 lines
fs/f2fs/gc.c +0
-0@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, * threshold, we can make them free by checkpoint.Then, we
Quoted 9 lines
fs/f2fs/gc.c int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
Quoted 9 lines
fs/f2fs/gc.c +6
-1* secure free segments which doesn't need fggc any more. */ - if (prefree_segments(sbi)) { + if (prefree_segments(sbi) || prefree2_segments(sbi)) { + ret = write_checkpoint(sbi, &cpc); + if (ret) + goto stop; + } + if (has_not_enough_free_secs(sbi, 0, 0) &&
prefree2_segments(sbi)) {Quoted 7 lines
Quoted 7 lines
fs/f2fs/gc.c +0
-0ret = write_checkpoint(sbi, &cpc); if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; }Quoted 13 lines
fs/f2fs/segment.c static void
Quoted 13 lines
fs/f2fs/gc.c +3
-1- if (gc_type == FG_GC) + if (gc_type == FG_GC) { + ret = write_checkpoint(sbi, &cpc); ret = write_checkpoint(sbi, &cpc); + } }stop:
SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;fs/f2fs/segment.c +0
-0@@ -1606,7 +1606,7 @@ static void
set_prefree_as_free_segments(struct f2fs_sb_info *sbi)Quoted 4 lines
fs/f2fs/segment.c static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)
Quoted 4 lines
fs/f2fs/segment.c +0
-1unsigned int segno; mutex_lock(&dirty_i->seglist_lock); - for_each_set_bit(segno, dirty_i->dirty_segmap[PRE],
MAIN_SEGS(sbi))Quoted 1 line
fs/f2fs/segment.c static void · line 1609
Quoted 1 line
fs/f2fs/segment.c +1
-0+ for_each_set_bit(segno, dirty_i->dirty_segmap[PRE2],
MAIN_SEGS(sbi))Quoted 4 lines
fs/f2fs/segment.c void clear_prefree_segments(struct
Quoted 4 lines
fs/f2fs/segment.c +0
-0__set_test_and_free(sbi, segno); mutex_unlock(&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct
f2fs_sb_info*sbi, structcp_control*cpc)Quoted 11 lines
Quoted 11 lines
fs/f2fs/segment.c +3
-1struct list_head *head = &dcc->entry_list; struct discard_entry *entry, *this; struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); - unsigned long *prefree_map = dirty_i->dirty_segmap[PRE]; + unsigned long *prefree_map; unsigned int start = 0, end = -1; unsigned int secno, start_segno; bool force = (cpc->reason & CP_DISCARD); + int phase = 0; + enum dirty_type dirty_type = PRE2;Quoted 7 lines
fs/f2fs/segment.c void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
Quoted 7 lines
fs/f2fs/segment.c +2
-0mutex_lock(&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type]; while (1) { int i; start = find_next_bit(prefree_map, MAIN_SEGS(sbi),end + 1);
Quoted 1 line
fs/f2fs/segment.c void clear_prefree_segments(struct
Quoted 1 line
fs/f2fs/segment.c +0
-0@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct
f2fs_sb_info*sbi, structcp_control*cpc)Quoted 9 lines
fs/f2fs/segment.c void clear_prefree_segments(struct
Quoted 9 lines
fs/f2fs/segment.c +1
-1for (i = start; i < end; i++) clear_bit(i, prefree_map); - dirty_i->nr_dirty[PRE] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start; if (!test_opt(sbi, DISCARD)) continue;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct
f2fs_sb_info*sbi, structcp_control*cpc)Quoted 6 lines
Quoted 6 lines
else
end = start - 1;
}
+ if (phase == 0) {
+ /* status change: PRE -> PRE2 */
+ for_each_set_bit(segno, dirty_i->dirty_segmap[PRE],
MAIN_SEGS(sbi))Quoted 11 lines
fs/f2fs/segment.c static void change_curseg(struct f2fs_sb_info
Quoted 11 lines
+ if (!test_and_set_bit(segno,
prefree_map))
+ dirty_i->nr_dirty[PRE2]++;
+
+ phase = 1;
+dirty_type= PRE;
+ gotonext_step;
+ }
mutex_unlock(&dirty_i->seglist_lock);/* send small discards */
fs/f2fs/segment.c +0
-0@@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info*sbi, int type)
Quoted 7 lines
Quoted 7 lines
fs/f2fs/segment.c +1
-0mutex_lock(&dirty_i->seglist_lock); __remove_dirty_segment(sbi, new_segno, PRE); + __remove_dirty_segment(sbi, new_segno, PRE2); __remove_dirty_segment(sbi, new_segno, DIRTY); mutex_unlock(&dirty_i->seglist_lock);Quoted 6 lines
Quoted 6 lines
fs/f2fs/segment.h +0
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE, /* dirty segments assigned as cold
node logs */
Quoted 2 lines
Quoted 2 lines
DIRTY, /* to count # of dirty segments */ PRE, /* to count # of entirely obsolete
segments */
Quoted 1 line
Quoted 1 line
+ PRE2, /* to count # of the segments free to
one checkpoint but obsolete to the other checkpoint */
Quoted 4 lines
fs/f2fs/segment.h static inline unsigned int
Quoted 4 lines
NR_DIRTY_TYPE
};fs/f2fs/segment.h +0
-0@@ -477,6 +478,11 @@ static inline unsigned int
prefree_segments(struct f2fs_sb_info *sbi)Quoted 3 lines
Quoted 3 lines
fs/f2fs/segment.h +0
-0return DIRTY_I(sbi)->nr_dirty[PRE]; }
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ + return DIRTY_I(sbi)->nr_dirty[PRE2]; +} + static inline unsigned int dirty_segments(struct f2fs_sb_info *sbi) {return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Hi Xiang,
Quoted 19 lines · Gao Xiang
Hi Weichao,
Quoted 4 lines · guoweichao
Hi Xiang,
it's not related to SPOR. Just consider the case given by Chao Yu.
(It seems this email was not sent successfully, I resend it just for reference only) Oh I see, I have considered the scenario what Chao said before.
1. write data into segment x;
2. write checkpoint A;
3. remove data in segment x;
4. write checkpoint B;
5. issue discard or write data into segment x;
6. sudden power-cut
Quoted 3 lines
Since f2fs is designed for double backup, 5) and 6), I think, actually belongs to checkpoint C. and when we are in checkpoint C, checkpoint A becomes unsafe because the latest checkpoint is B. and I think in that case we cannot prevent data writeback or something to pollute checkpoint A.
We do not have to prevent data writeback, we could just delay to reuse the invalid blocks which are valid to the older checkpoint.
Quoted 3 lines
However, node segments (another metadata) would be special,
but I have no idea whether introducing PRE2 would make all cases safe or not.
By adding a PRE2 status, we could set prefree node segments in two steps: PRE->PRE2->FREE, and therefore make sure using free segments are safe to both chepoints. I forgot to consider SSR at first, but the main idea is similar: avoiding to use invalid blocks that are not invalid to the older checkpoint, writing a new checkpoint if there is no other invalid blocks.
Quoted 3 lines
In addition, if some data segments change between checkpoint A and C,
some weird data that it didn't have (new data or data from other files) would be gotten when switching back to checkpoint A.
Data blocks damage do not affect file system consistency.
Anyway, this is a hardware related problem. We could just keep unchanged and try to exposure hardware issues.
Thanks,
Quoted 184 lines
Thanks,
Quoted 166 lines
Thanks,
*From:*Gao Xiang
*To:*guoweichao,
*Cc:*[email protected],heyunlei,
*Date:*2018-01-20 11:49:22
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 3 lines · guoweichao
A critical case is using the free segments as data segments which are previously node segments to the old checkpoint. With fault injecting of the newer CP pack, fsck can find errors when checking the sanity of nid.
Sorry to interrupt because I'm just curious about this scenario and the detail.
As far as I know, if the whole blocks in a segment become invalid, the segment will become PREFREE, and then if a checkpoint is followed, we can reuse this segment or
discard the whole segment safely after this checkpoint was done (I think It makes sure that this segment is certainly FREE and not reused in this checkpoint).If the segment in the old checkpoint is a node segment, and node blocks in the segment are all invalid until the new checkpoint.
It seems no danger to reuse the FREE node segment as a data segment in the next checkpoint?or something related to SPOR? In my mind f2fs-tools ignores POR node chain...
Thanks,
Quoted 133 lines · Weichao Guo
Quoted 132 lines
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 10 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
Hi Weichao,
Quoted 22 lines · guoweichao
Hi Xiang,
Quoted 19 lines · Gao Xiang
Hi Weichao,
Quoted 4 lines · guoweichao
Hi Xiang,
it's not related to SPOR. Just consider the case given by Chao Yu.
(It seems this email was not sent successfully, I resend it just for reference only) Oh I see, I have considered the scenario what Chao said before.
1. write data into segment x;
2. write checkpoint A;
3. remove data in segment x;
4. write checkpoint B;
5. issue discard or write data into segment x;
6. sudden power-cut
Quoted 5 lines
Quoted 3 lines
Since f2fs is designed for double backup, 5) and 6), I think, actually belongs to checkpoint C. and when we are in checkpoint C, checkpoint A becomes unsafe because the latest checkpoint is B. and I think in that case we cannot prevent data writeback or something to pollute checkpoint A.
We do not have to prevent data writeback, we could just delay to reuse the invalid blocks which are valid to the older checkpoint.
Yes, your patch misses SSR reuse case, however, an even worse case is that when we are writing checkpoint C, partially flush METADATA(I mean SIT/NAT), but still not write the cp pack of checkpoint C, and suddenly power-off, timing as follows:
1. write checkpoint A
2. write checkpoint B
3. begin to write checkpoint C
4. successful to flush NAT/SIT entries
5. suddenly power-off
x 6. write checkpoint C cp pack x
We could not simply recover checkpoint A in the above case and months ago I finally agreed all double-backup (or double buffer, whatever) designs ensure *only one backup valid* --- no exception for f2fs.
By the way, It seems currently f2fs only pollutes(flushes) the SIT/NAT
when writing checkpoint,
it has benefits -- *avoid the original checkpoint from being polluted as much as it can*, but I also think that flushing SIT/NATs periodically rather
than flushing them all in writing chechpoint could reduce the total time of writing checkpoint further.
As I said before, In my opinion, A better idea is to implement "snapshot",
1) when we snapshot the older checkpoint, we can re-check all metadata of the older checkpoint and makes a more reliable and stable snapshot. -- for example, we are in checkpoint C and snapshot checkpoint B, we need re-check all metadata of checkpoint B when we make the snapshot.
2) we can control the size of snapshot (if the difference between the current checkpoint and the snapshot is larger than xxGB, we could discard the oldest and build a new snapshot)
or build the snapshot periodically (per-hour, per-day, etc..).
Thanks,
Quoted 200 lines
Quoted 3 lines
However, node segments (another metadata) would be special,
but I have no idea whether introducing PRE2 would make all cases safe or not.By adding a PRE2 status, we could set prefree node segments in two steps:
PRE->PRE2->FREE, and therefore make sure using free segments are safe to both chepoints. I forgot to consider SSR at first, but the main idea is similar: avoiding to use invalid blocks that are not invalid to the older checkpoint, writing a new checkpoint if there is no other invalid blocks.Quoted 3 lines
In addition, if some data segments change between checkpoint A and C,
some weird data that it didn't have (new data or data from other files) would be gotten when switching back to checkpoint A.Data blocks damage do not affect file system consistency.
Anyway, this is a hardware related problem. We could just keep unchanged and try to exposure hardware issues.
Thanks,
Quoted 184 lines
Thanks,
Quoted 166 lines
Thanks,
*From:*Gao Xiang
*To:*guoweichao,
*Cc:*[email protected],heyunlei,
*Date:*2018-01-20 11:49:22
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 3 lines · guoweichao
A critical case is using the free segments as data segments which are previously node segments to the old checkpoint. With fault injecting of the newer CP pack, fsck can find errors when checking the sanity of nid.
Sorry to interrupt because I'm just curious about this scenario and the detail.
As far as I know, if the whole blocks in a segment become invalid, the segment will become PREFREE, and then if a checkpoint is followed, we can reuse this segment or
discard the whole segment safely after this checkpoint was done (I think It makes sure that this segment is certainly FREE and not reused in this checkpoint).If the segment in the old checkpoint is a node segment, and node blocks in the segment are all invalid until the new checkpoint.
It seems no danger to reuse the FREE node segment as a data segment in the next checkpoint?or something related to SPOR? In my mind f2fs-tools ignores POR node chain...
Thanks,
Quoted 133 lines · Weichao Guo
Quoted 132 lines
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 10 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
Chao Yu
maintainerHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cut
But after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 135 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +6
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; } +static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
Chao Yu
maintainerHi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustness
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Thanks,
Quoted 171 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 135 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>---
fs/f2fs/gc.c | 11 +++++++++--
fs/f2fs/segment.c | 21 ++++++++++++++++++---
fs/f2fs/segment.h | 6 ++++++3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +6
-1@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret = write_checkpoint(sbi, &cpc); if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; }
- if (gc_type==FG_GC)
+ if (gc_type==FG_GC) {
+ ret =write_checkpoint(sbi, &cpc);
ret =write_checkpoint(sbi, &cpc);
+ }
}
stop:
SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;fs/f2fs/segment.c +0
-0@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi) unsigned int segno;
mutex_lock(&dirty_i->seglist_lock);
-for_each_set_bit(segno, dirty_i->dirty_segmap[PRE], MAIN_SEGS(sbi))
+for_each_set_bit(segno, dirty_i->dirty_segmap[PRE2], MAIN_SEGS(sbi))__set_test_and_free(sbi, segno);mutex_unlock(&dirty_i->seglist_lock);
}fs/f2fs/segment.c +3
-1@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) struct list_head *head = &dcc->entry_list; struct discard_entry *entry, *this; struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map; unsigned int start = 0, end = -1; unsigned int secno, start_segno; bool force = (cpc->reason & CP_DISCARD); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;
mutex_lock(&dirty_i->seglist_lock);
+next_step:
+prefree_map= dirty_i->dirty_segmap[dirty_type]; while (1) {
int i;
start =find_next_bit(prefree_map, MAIN_SEGS(sbi), end + 1);fs/f2fs/segment.c +0
-0@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) for (i = start; i < end; i++) clear_bit(i, prefree_map);
- dirty_i->nr_dirty[PRE] -= end - start;
+ dirty_i->nr_dirty[dirty_type] -= end - start;
if (!test_opt(sbi, DISCARD))
continue;fs/f2fs/segment.c +0
-0@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else
end = start - 1;
}
+ if (phase == 0) {
+ /* status change: PRE -> PRE2 */
+for_each_set_bit(segno, dirty_i->dirty_segmap[PRE], MAIN_SEGS(sbi))
+ if (!test_and_set_bit(segno,prefree_map))
+ dirty_i->nr_dirty[PRE2]++;
+
+ phase = 1;
+dirty_type= PRE;
+ gotonext_step;
+ }
mutex_unlock(&dirty_i->seglist_lock);
/* send small discards */fs/f2fs/segment.c +0
-0@@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)
mutex_lock(&dirty_i->seglist_lock);
__remove_dirty_segment(sbi, new_segno, PRE);
+__remove_dirty_segment(sbi, new_segno, PRE2);
__remove_dirty_segment(sbi, new_segno, DIRTY);
mutex_unlock(&dirty_i->seglist_lock);fs/f2fs/segment.h +0
-0@@ -263,6 +263,7 @@ enum dirty_type {
DIRTY_COLD_NODE, /* dirty segments assigned as cold node logs */
DIRTY, /* to count # of dirty segments */
PRE, /* to count # of entirely obsolete segments */
+ PRE2, /* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */NR_DIRTY_TYPE
};fs/f2fs/segment.h +0
-0@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) return DIRTY_I(sbi)->nr_dirty[PRE]; }fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int
dirty_segments(struct f2fs_sb_info *sbi){
return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +
Hi Chao and Weichao,
Quoted 12 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustness
Quoted 4 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
*nod*, triple-like-backups would not solve all hardware issues in a even worse case,
and in order to make all backups available we need to find more extra area to leave all modification among 3 checkpoints.
In my opinion, introducing "snapshot" feature could be something more useful for phone (yet it is a big feature :( ) and if fsck found something is unrecoverable
we could roll back to a stable and reliable (via re-checking metadata) snapshot (maybe hours ago or days ago, and remind users when rollback in fsck or somewhere).
Sorry to bother all,
Thanks,
Quoted 174 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Thanks,
Quoted 160 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 125 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret = write_checkpoint(sbi, &cpc); if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret = write_checkpoint(sbi, &cpc); + } } stop: SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi) unsigned int segno; mutex_lock(&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi)) __set_test_and_free(sbi, segno); mutex_unlock(&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) struct list_head *head = &dcc->entry_list; struct discard_entry *entry, *this; struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map; unsigned int start = 0, end = -1; unsigned int secno, start_segno; bool force = (cpc->reason & CP_DISCARD); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ; mutex_lock(&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type]; while (1) { int i; start = find_next_bit(prefree_map, MAIN_SEGS(sbi), end + 1);@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) for (i = start; i < end; i++) clear_bit(i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start; if (!test_opt(sbi, DISCARD)) continue;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) else end = start - 1; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + } mutex_unlock(&dirty_i->seglist_lock); /* send small discards */@@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type) mutex_lock(&dirty_i->seglist_lock); __remove_dirty_segment(sbi, new_segno, PRE); +__remove_dirty_segment (sbi, new_segno,PRE2 ); __remove_dirty_segment(sbi, new_segno, DIRTY); mutex_unlock(&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type { DIRTY_COLD_NODE, /* dirty segments assigned as cold node logs */ DIRTY, /* to count # of dirty segments */ PRE, /* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) return DIRTY_I(sbi)->nr_dirty[PRE]; }
Quoted 16 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} + static inline unsigned int dirty_segments(struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +------------------------------------------------------------------------------
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
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Hi Xiang,
Quoted 20 lines · On 2018/1/21 11:12, Gao Xiang via Linux-f2fs-devel wrote:
Hi Chao and Weichao,
Quoted 12 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustnessQuoted 4 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
Quoted 7 lines
*nod*, triple-like-backups would not solve all hardware issues in a even worse case,
and in order to make all backups available we need to find more extra area to leave all modification among 3 checkpoints.In my opinion, introducing "snapshot" feature could be something more useful for phone (yet it is a big feature :( )
Yes, I think we could use that way, but now, I guess Weichao wants a quick and simple solution in production, snapshot will cause heavy overhead in current scenario, if there are other usage scenario in userspace for snapshot, we can add it more reasonably, right? ;)
Thanks,
Quoted 210 lines
and if fsck found something is unrecoverable
we could roll back to a stable and reliable (via re-checking metadata) snapshot (maybe hours ago or days ago,
and remind users when rollback in fsck or somewhere).Sorry to bother all,
Thanks,
Quoted 174 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Thanks,
Quoted 160 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 125 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret = write_checkpoint(sbi, &cpc); if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret = write_checkpoint(sbi, &cpc); + } } stop: SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi) unsigned int segno; mutex_lock(&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi)) __set_test_and_free(sbi, segno); mutex_unlock(&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) struct list_head *head = &dcc->entry_list; struct discard_entry *entry, *this; struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map; unsigned int start = 0, end = -1; unsigned int secno, start_segno; bool force = (cpc->reason & CP_DISCARD); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ; mutex_lock(&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type]; while (1) { int i; start = find_next_bit(prefree_map, MAIN_SEGS(sbi), end + 1);@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) for (i = start; i < end; i++) clear_bit(i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start; if (!test_opt(sbi, DISCARD)) continue;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc) else end = start - 1; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + } mutex_unlock(&dirty_i->seglist_lock); /* send small discards */@@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type) mutex_lock(&dirty_i->seglist_lock); __remove_dirty_segment(sbi, new_segno, PRE); +__remove_dirty_segment (sbi, new_segno,PRE2 ); __remove_dirty_segment(sbi, new_segno, DIRTY); mutex_unlock(&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type { DIRTY_COLD_NODE, /* dirty segments assigned as cold node logs */ DIRTY, /* to count # of dirty segments */ PRE, /* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) return DIRTY_I(sbi)->nr_dirty[PRE]; }Quoted 16 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} + static inline unsigned int dirty_segments(struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +------------------------------------------------------------------------------
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------------------------------------------------------------------------------
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.
Hi Chao,
Quoted 13 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustness
Quoted 5 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
Nope, I do not intent to add another checkpoint. My main idea is reusing the invalid blocks after two checkpoints are recorded them as invalid. We could mark or record the blocks that are free to one checkpoint and valid to the other one as PARTIAL_FREE. And when set prefree segments as free or use invalid blocks in SSR mode, just igore PARTIAL_FREE blocks. If there is no other blocks can be used, just write a new checkpoint.
Quoted 11 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Yes, I agree. Adding a backup for the latest checkpoint in debug version is OK. Sometimes, hardware issues are hard to uncover. We should try to separate them from F2FS.
Thanks,
Quoted 176 lines
Thanks,
Quoted 162 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 126 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
Quoted 21 lines · guoweichao
Hi Chao,
Quoted 13 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustnessQuoted 5 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
Quoted 5 lines
Nope, I do not intent to add another checkpoint. My main idea is reusing the invalid blocks after two checkpoints are recorded them as invalid. We could mark or record the blocks that are free to one checkpoint and valid to the other one as
PARTIAL_FREE. And when set prefree segments as free or use invalid blocks in SSR mode, just igorePARTIAL_FREEblocks. If there is no other blocks can be used, just write a new checkpoint.
Actually, your implementation looks like a variant of A/B/C upgrade system (or A/B upgrade system), as checkpoint C (or inflight A/B) uses main area separated from checkpoint A/B, and its inflight dirty metadata will persist into checkpoint A or B since we haven't actually allocated checkpoint C area during mkfs.
Anyway, I don't think we have a strong reason to implement this one.
Quoted 6 lines
Quoted 6 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
Quoted 7 lines
Quoted 6 lines
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Yes, I agree. Adding a backup for the latest checkpoint in debug version is OK. Sometimes,
Parity will be better due to light overhead?
Thanks,
Quoted 184 lines
hardware issues are hard to uncover. We should try to separate them from F2FS.
Thanks,
Quoted 164 lines
Thanks,
Quoted 162 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 126 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 12 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
.
Quoted 48 lines · Chao Yu
Quoted 21 lines · guoweichao
Hi Chao,
Quoted 13 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustnessQuoted 5 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
Quoted 5 lines
Nope, I do not intent to add another checkpoint. My main idea is reusing the invalid blocks after two checkpoints are recorded them as invalid. We could mark or record the blocks that are free to one checkpoint and valid to the other one as
PARTIAL_FREE. And when set prefree segments as free or use invalid blocks in SSR mode, just igorePARTIAL_FREEblocks. If there is no other blocks can be used, just write a new checkpoint.Actually, your implementation looks like a variant of A/B/C upgrade system (or A/B upgrade system), as checkpoint C (or inflight A/B) uses main area separated from checkpoint A/B, and its inflight dirty metadata will persist into checkpoint A or B since we haven't actually allocated checkpoint C area during mkfs.
Anyway, I don't think we have a strong reason to implement this one.
Quoted 12 lines
Quoted 12 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Quoted 3 lines
Quoted 1 line
Yes, I agree. Adding a backup for the latest checkpoint in debug version is OK. Sometimes,
Parity will be better due to light overhead?
Yes, backup may also cause disk layout changes. How about adding a parity block for the blocks in a checkpoint similar to RAID-5 or other erasure code methods?
Thanks,
Quoted 191 lines
Thanks,
Quoted 182 lines
hardware issues are hard to uncover. We should try to separate them from F2FS.
Thanks,
Quoted 164 lines
Thanks,
Quoted 162 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 126 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 12 lines
Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
Quoted 2 lines
.
.
Quoted 51 lines · guoweichao
Quoted 48 lines · Chao Yu
Quoted 21 lines · guoweichao
Hi Chao,
Quoted 13 lines · Chao Yu
Hi Weichao,
Quoted 9 lines · guoweichao
Hi Chao,
Yes, it is exactly what I mean.
It seems that F2FS has no responsibility to cover hardware problems. However, file systems usually choose redundancy for super block fault tolerance. So I think we actually have considered some external errors when designing a file system. Our dual checkpoint mechanism is mainly designed to keep at least one stable CP pack while creating a new one in case of SPO. And it has fault tolerant effects. As CP pack is also very critical to F2FS, why not make checkpoint more robustnessQuoted 5 lines
I think you're trying to change basic design of A/B upgrade system to A/B/C one, which can keep always two checkpoint valid. There will be no simple modification to implement that one, in where we should cover not only prefree case but also SSR case.
Quoted 5 lines
Nope, I do not intent to add another checkpoint. My main idea is reusing the invalid blocks after two checkpoints are recorded them as invalid. We could mark or record the blocks that are free to one checkpoint and valid to the other one as
PARTIAL_FREE. And when set prefree segments as free or use invalid blocks in SSR mode, just igorePARTIAL_FREEblocks. If there is no other blocks can be used, just write a new checkpoint.Actually, your implementation looks like a variant of A/B/C upgrade system (or A/B upgrade system), as checkpoint C (or inflight A/B) uses main area separated from checkpoint A/B, and its inflight dirty metadata will persist into checkpoint A or B since we haven't actually allocated checkpoint C area during mkfs.
Anyway, I don't think we have a strong reason to implement this one.
Quoted 12 lines
Quoted 12 lines
IMO, the biggest problem there is available space, since in checkpoint C, we can only use invalid blocks in both checkpoint A and B, so in some cases there will almost be no valid space we can use during allocation, result in frequently checkpoint.
IMO, what we can do is trying to keep last valid checkpoint being integrity as possible as we can. One way is that we can add mirror or parity for the checkpoint which can help to do recovery once checkpoint is corrupted. At least, I hope that with it in debug version we can help hardware staff to fix their issue instead of wasting much time to troubleshoot filesystem issue.
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Yes, I agree. Adding a backup for the latest checkpoint in debug version is OK. Sometimes,
Parity will be better due to light overhead?
Yes, backup may also cause disk layout changes. How about adding a parity block for the blocks
Right,
Quoted 1 line
in a checkpoint similar to RAID-5 or other erasure code methods?
Yes, I think we can.
Thanks,
Quoted 198 lines
Thanks,
Quoted 185 lines
Thanks,
Quoted 182 lines
hardware issues are hard to uncover. We should try to separate them from F2FS.
Thanks,
Quoted 176 lines
Thanks,
Quoted 162 lines
with simple modification in current design and little overhead except for
FG_GC. Of cause, keep unchanged is OK. I just want to discuss this proposal. :)Thanks,
*From:*Chao Yu
*To:*guoweichao,[email protected], *Cc:*[email protected],[email protected],heyunlei, *Date:*2018-01-20 15:43:23
*Subject:*Re: [PATCH RFC] f2fs: add PRE2 to mark segments free to one checkpoint but obsolete to the otherHi Weichao,
Quoted 6 lines · Weichao Guo
Currently, we set prefree segments as free ones after writing a checkpoint, then believe the segments could be used safely. However, if a sudden power-off coming and the newer checkpoint corrupted due to hardware issues at the same time, we will try to use the old checkpoint and may face an inconsistent file system status.
IIUC, you mean:
1. write nodes into segment x;
2. write checkpoint A;
3. remove nodes in segment x;
4. write checkpoint B;
5. issue discard or write datas into segment x;
6. sudden power-cutBut after reboot, we found checkpoint B is corrupted due to hardware, and then start to use checkpoint A, but nodes in segment x recorded as valid data in checkpoint A has been overcovered in step 5), so we will encounter inconsistent meta data, right?
Thanks,
Quoted 126 lines
How about add an PRE2 status for prefree segments, and make sure the segments could be used safely to both checkpoints? Or any better solutions? Or this is not a problem?
Look forward to your comments!
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/gc.c | 11 +++++++++-- fs/f2fs/segment.c | 21 ++++++++++++++++++--- fs/f2fs/segment.h | 6 ++++++ 3 files changed, 33 insertions(+), 5 deletions(-)fs/f2fs/gc.c +9
-2@@ -1030,7 +1030,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,* threshold, we can make them free by checkpoint. Then, we * secure free segments which doesn't need fggc any more. */ -if (prefree_segments (sbi)) { +if (prefree_segments (sbi) ||prefree2_segments (sbi)) { + ret =write_checkpoint (sbi, &cpc); +if (ret) + goto stop; + } +if (has_not_enough_free_secs (sbi,0 ,0 ) &&prefree2_segments (sbi)) { ret =write_checkpoint (sbi, &cpc);if (ret) goto stop;@@ -1063,8 +1068,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, goto gc_more; } -if (gc_type ==FG_GC ) +if (gc_type ==FG_GC ) { + ret =write_checkpoint (sbi, &cpc); ret =write_checkpoint (sbi, &cpc); + } } stop:SIT_I (sbi)->last_victim[ALLOC_NEXT ] =0 ;fs/f2fs/segment.c +18
-3@@ -1606,7 +1606,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)unsigned int segno;mutex_lock (&dirty_i->seglist_lock); -for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE2 ],MAIN_SEGS (sbi))__set_test_and_free (sbi, segno);mutex_unlock (&dirty_i->seglist_lock); }@@ -1617,13 +1617,17 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct list_head *head = &dcc->entry_list;struct discard_entry *entry, *this;struct dirty_seglist_info *dirty_i =DIRTY_I (sbi); -unsigned long *prefree_map = dirty_i->dirty_segmap[PRE ]; +unsigned long *prefree_map;unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); +int phase =0 ; +enum dirty_type dirty_type =PRE2 ;mutex_lock (&dirty_i->seglist_lock); +next_step: + prefree_map = dirty_i->dirty_segmap[dirty_type];while (1 ) {int i; start =find_next_bit (prefree_map,MAIN_SEGS (sbi), end +1 );@@ -1635,7 +1639,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)for (i = start; i < end; i++)clear_bit (i, prefree_map); - dirty_i->nr_dirty[PRE ] -= end - start; + dirty_i->nr_dirty[dirty_type] -= end - start;if (!test_opt (sbi,DISCARD ))continue ;@@ -1663,6 +1667,16 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)else end = start -1 ; } +if (phase ==0 ) { +/* status change: PRE -> PRE2 */ +for_each_set_bit (segno, dirty_i->dirty_segmap[PRE ],MAIN_SEGS (sbi)) +if (!test_and_set_bit (segno, prefree_map)) + dirty_i->nr_dirty[PRE2 ]++; + + phase =1 ; + dirty_type =PRE ; + goto next_step; + }mutex_unlock (&dirty_i->seglist_lock);/* send small discards */ @@ -2245,6 +2259,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)mutex_lock (&dirty_i->seglist_lock);__remove_dirty_segment (sbi, new_segno,PRE ); +__remove_dirty_segment (sbi, new_segno,PRE2 );__remove_dirty_segment (sbi, new_segno,DIRTY );mutex_unlock (&dirty_i->seglist_lock);fs/f2fs/segment.h +1
-0@@ -263,6 +263,7 @@ enum dirty_type {DIRTY_COLD_NODE ,/* dirty segments assigned as cold node logs */ DIRTY ,/* to count # of dirty segments */ PRE ,/* to count # of entirely obsolete segments */ +PRE2 ,/* to count # of the segments free to one checkpoint but obsolete to the other checkpoint */ NR_DIRTY_TYPE };@@ -477,6 +478,11 @@ static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi)return DIRTY_I (sbi)->nr_dirty[PRE ]; }Quoted 9 lines
fs/f2fs/segment.h static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) · line 488
Quoted 9 lines
fs/f2fs/segment.h +5
-0+static inline unsigned int prefree2_segments (struct f2fs_sb_info *sbi) +{ +return DIRTY_I (sbi)->nr_dirty[PRE2 ]; +} +static inline unsigned int dirty_segments (struct f2fs_sb_info *sbi) { return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] +.
Quoted 6 lines
Quoted 2 lines
.
.
.