Skip to content

Commit c5d0278

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: inherit mtime of original block during GC
Don't let f2fs inner GC ruins original aging degree of segment. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 6f3a01a commit c5d0278

4 files changed

Lines changed: 50 additions & 17 deletions

File tree

‎fs/f2fs/data.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
14161416
set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
14171417
old_blkaddr = dn->data_blkaddr;
14181418
f2fs_allocate_data_block(sbi, NULL, old_blkaddr, &dn->data_blkaddr,
1419-
&sum, seg_type, NULL);
1419+
&sum, seg_type, NULL, false);
14201420
if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
14211421
invalidate_mapping_pages(META_MAPPING(sbi),
14221422
old_blkaddr, old_blkaddr);

‎fs/f2fs/f2fs.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,15 +3357,16 @@ void f2fs_outplace_write_data(struct dnode_of_data *dn,
33573357
int f2fs_inplace_write_data(struct f2fs_io_info *fio);
33583358
void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
33593359
block_t old_blkaddr, block_t new_blkaddr,
3360-
bool recover_curseg, bool recover_newaddr);
3360+
bool recover_curseg, bool recover_newaddr,
3361+
bool from_gc);
33613362
void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
33623363
block_t old_addr, block_t new_addr,
33633364
unsigned char version, bool recover_curseg,
33643365
bool recover_newaddr);
33653366
void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
33663367
block_t old_blkaddr, block_t *new_blkaddr,
33673368
struct f2fs_summary *sum, int type,
3368-
struct f2fs_io_info *fio);
3369+
struct f2fs_io_info *fio, bool from_gc);
33693370
void f2fs_wait_on_page_writeback(struct page *page,
33703371
enum page_type type, bool ordered, bool locked);
33713372
void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr);

‎fs/f2fs/gc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
879879
}
880880

881881
f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
882-
&sum, CURSEG_COLD_DATA, NULL);
882+
&sum, CURSEG_COLD_DATA, NULL, true);
883883

884884
fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(fio.sbi),
885885
newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS);
@@ -929,7 +929,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
929929
recover_block:
930930
if (err)
931931
f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr,
932-
true, true);
932+
true, true, true);
933933
up_out:
934934
if (lfs_mode)
935935
up_write(&fio.sbi->io_order_lock);

‎fs/f2fs/segment.c‎

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,20 +2154,37 @@ static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type,
21542154
__mark_sit_entry_dirty(sbi, segno);
21552155
}
21562156

2157-
static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr)
2157+
static inline unsigned long long get_segment_mtime(struct f2fs_sb_info *sbi,
2158+
block_t blkaddr)
21582159
{
21592160
unsigned int segno = GET_SEGNO(sbi, blkaddr);
2160-
struct seg_entry *se = get_seg_entry(sbi, segno);
2161-
unsigned long long mtime = get_mtime(sbi, false);
2161+
2162+
if (segno == NULL_SEGNO)
2163+
return 0;
2164+
return get_seg_entry(sbi, segno)->mtime;
2165+
}
2166+
2167+
static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr,
2168+
unsigned long long old_mtime)
2169+
{
2170+
struct seg_entry *se;
2171+
unsigned int segno = GET_SEGNO(sbi, blkaddr);
2172+
unsigned long long ctime = get_mtime(sbi, false);
2173+
unsigned long long mtime = old_mtime ? old_mtime : ctime;
2174+
2175+
if (segno == NULL_SEGNO)
2176+
return;
2177+
2178+
se = get_seg_entry(sbi, segno);
21622179

21632180
if (!se->mtime)
21642181
se->mtime = mtime;
21652182
else
21662183
se->mtime = div_u64(se->mtime * se->valid_blocks + mtime,
21672184
se->valid_blocks + 1);
21682185

2169-
if (mtime > SIT_I(sbi)->max_mtime)
2170-
SIT_I(sbi)->max_mtime = mtime;
2186+
if (ctime > SIT_I(sbi)->max_mtime)
2187+
SIT_I(sbi)->max_mtime = ctime;
21712188
}
21722189

21732190
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
@@ -2189,8 +2206,6 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
21892206
f2fs_bug_on(sbi, (new_vblocks < 0 ||
21902207
(new_vblocks > f2fs_usable_blks_in_seg(sbi, segno))));
21912208

2192-
update_segment_mtime(sbi, blkaddr);
2193-
21942209
se->valid_blocks = new_vblocks;
21952210

21962211
/* Update valid block bitmap */
@@ -2284,6 +2299,7 @@ void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
22842299
/* add it into sit main buffer */
22852300
down_write(&sit_i->sentry_lock);
22862301

2302+
update_segment_mtime(sbi, addr, 0);
22872303
update_sit_entry(sbi, addr, -1);
22882304

22892305
/* add it into dirty seglist */
@@ -3192,10 +3208,11 @@ static int __get_segment_type(struct f2fs_io_info *fio)
31923208
void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
31933209
block_t old_blkaddr, block_t *new_blkaddr,
31943210
struct f2fs_summary *sum, int type,
3195-
struct f2fs_io_info *fio)
3211+
struct f2fs_io_info *fio, bool from_gc)
31963212
{
31973213
struct sit_info *sit_i = SIT_I(sbi);
31983214
struct curseg_info *curseg = CURSEG_I(sbi, type);
3215+
unsigned long long old_mtime;
31993216

32003217
down_read(&SM_I(sbi)->curseg_lock);
32013218

@@ -3217,6 +3234,14 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
32173234

32183235
stat_inc_block_count(sbi, curseg);
32193236

3237+
if (from_gc) {
3238+
old_mtime = get_segment_mtime(sbi, old_blkaddr);
3239+
} else {
3240+
update_segment_mtime(sbi, old_blkaddr, 0);
3241+
old_mtime = 0;
3242+
}
3243+
update_segment_mtime(sbi, *new_blkaddr, old_mtime);
3244+
32203245
/*
32213246
* SIT information should be updated before segment allocation,
32223247
* since SSR needs latest valid block information.
@@ -3293,7 +3318,8 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
32933318
down_read(&fio->sbi->io_order_lock);
32943319
reallocate:
32953320
f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr,
3296-
&fio->new_blkaddr, sum, type, fio);
3321+
&fio->new_blkaddr, sum, type, fio,
3322+
is_cold_data(fio->page));
32973323
if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO)
32983324
invalidate_mapping_pages(META_MAPPING(fio->sbi),
32993325
fio->old_blkaddr, fio->old_blkaddr);
@@ -3409,7 +3435,8 @@ static inline int __f2fs_get_curseg(struct f2fs_sb_info *sbi,
34093435

34103436
void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
34113437
block_t old_blkaddr, block_t new_blkaddr,
3412-
bool recover_curseg, bool recover_newaddr)
3438+
bool recover_curseg, bool recover_newaddr,
3439+
bool from_gc)
34133440
{
34143441
struct sit_info *sit_i = SIT_I(sbi);
34153442
struct curseg_info *curseg;
@@ -3460,11 +3487,16 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
34603487
curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, new_blkaddr);
34613488
__add_sum_entry(sbi, type, sum);
34623489

3463-
if (!recover_curseg || recover_newaddr)
3490+
if (!recover_curseg || recover_newaddr) {
3491+
if (!from_gc)
3492+
update_segment_mtime(sbi, new_blkaddr, 0);
34643493
update_sit_entry(sbi, new_blkaddr, 1);
3494+
}
34653495
if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) {
34663496
invalidate_mapping_pages(META_MAPPING(sbi),
34673497
old_blkaddr, old_blkaddr);
3498+
if (!from_gc)
3499+
update_segment_mtime(sbi, old_blkaddr, 0);
34683500
update_sit_entry(sbi, old_blkaddr, -1);
34693501
}
34703502

@@ -3496,7 +3528,7 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
34963528
set_summary(&sum, dn->nid, dn->ofs_in_node, version);
34973529

34983530
f2fs_do_replace_block(sbi, &sum, old_addr, new_addr,
3499-
recover_curseg, recover_newaddr);
3531+
recover_curseg, recover_newaddr, false);
35003532

35013533
f2fs_update_data_blkaddr(dn, new_addr);
35023534
}

0 commit comments

Comments
 (0)