Skip to content

Commit e605302

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: trace elapsed time for gc_lock lock
Use f2fs_{down,up}_write_trace for gc_lock to trace lock elapsed time. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent bb28b66 commit e605302

7 files changed

Lines changed: 54 additions & 42 deletions

File tree

fs/f2fs/checkpoint.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,11 +1930,12 @@ void f2fs_destroy_checkpoint_caches(void)
19301930
static int __write_checkpoint_sync(struct f2fs_sb_info *sbi)
19311931
{
19321932
struct cp_control cpc = { .reason = CP_SYNC, };
1933+
struct f2fs_lock_context lc;
19331934
int err;
19341935

1935-
f2fs_down_write(&sbi->gc_lock);
1936+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
19361937
err = f2fs_write_checkpoint(sbi, &cpc);
1937-
f2fs_up_write(&sbi->gc_lock);
1938+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
19381939

19391940
return err;
19401941
}
@@ -2022,11 +2023,12 @@ int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi)
20222023
cpc.reason = __get_cp_reason(sbi);
20232024
if (!test_opt(sbi, MERGE_CHECKPOINT) || cpc.reason != CP_SYNC ||
20242025
sbi->umount_lock_holder == current) {
2026+
struct f2fs_lock_context lc;
20252027
int ret;
20262028

2027-
f2fs_down_write(&sbi->gc_lock);
2029+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
20282030
ret = f2fs_write_checkpoint(sbi, &cpc);
2029-
f2fs_up_write(&sbi->gc_lock);
2031+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
20302032

20312033
return ret;
20322034
}

fs/f2fs/f2fs.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ enum f2fs_lock_name {
178178
LOCK_NAME_CP_RWSEM,
179179
LOCK_NAME_NODE_CHANGE,
180180
LOCK_NAME_NODE_WRITE,
181+
LOCK_NAME_GC_LOCK,
181182
};
182183

183184
/*
@@ -1408,16 +1409,6 @@ struct atgc_management {
14081409
unsigned long long age_threshold; /* age threshold */
14091410
};
14101411

1411-
struct f2fs_gc_control {
1412-
unsigned int victim_segno; /* target victim segment number */
1413-
int init_gc_type; /* FG_GC or BG_GC */
1414-
bool no_bg_gc; /* check the space and stop bg_gc */
1415-
bool should_migrate_blocks; /* should migrate blocks */
1416-
bool err_gc_skipped; /* return EAGAIN if GC skipped */
1417-
bool one_time; /* require one time GC in one migration unit */
1418-
unsigned int nr_free_secs; /* # of free sections to do GC */
1419-
};
1420-
14211412
struct f2fs_time_stat {
14221413
unsigned long long total_time; /* total wall clock time */
14231414
#ifdef CONFIG_64BIT
@@ -1436,6 +1427,17 @@ struct f2fs_lock_context {
14361427
bool lock_trace;
14371428
};
14381429

1430+
struct f2fs_gc_control {
1431+
unsigned int victim_segno; /* target victim segment number */
1432+
int init_gc_type; /* FG_GC or BG_GC */
1433+
bool no_bg_gc; /* check the space and stop bg_gc */
1434+
bool should_migrate_blocks; /* should migrate blocks */
1435+
bool err_gc_skipped; /* return EAGAIN if GC skipped */
1436+
bool one_time; /* require one time GC in one migration unit */
1437+
unsigned int nr_free_secs; /* # of free sections to do GC */
1438+
struct f2fs_lock_context lc; /* lock context for gc_lock */
1439+
};
1440+
14391441
/*
14401442
* For s_flag in struct f2fs_sb_info
14411443
* Modification on enum should be synchronized with s_flag array

fs/f2fs/file.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
19281928

19291929
if (has_not_enough_free_secs(sbi, 0,
19301930
sbi->reserved_pin_section)) {
1931-
f2fs_down_write(&sbi->gc_lock);
1931+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
19321932
stat_inc_gc_call_count(sbi, FOREGROUND);
19331933
err = f2fs_gc(sbi, &gc_control);
19341934
if (err && err != -ENODATA) {
@@ -2779,12 +2779,13 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
27792779
return ret;
27802780

27812781
if (!sync) {
2782-
if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
2782+
if (!f2fs_down_write_trylock_trace(&sbi->gc_lock,
2783+
&gc_control.lc)) {
27832784
ret = -EBUSY;
27842785
goto out;
27852786
}
27862787
} else {
2787-
f2fs_down_write(&sbi->gc_lock);
2788+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
27882789
}
27892790

27902791
gc_control.init_gc_type = sync ? FG_GC : BG_GC;
@@ -2824,12 +2825,12 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range)
28242825

28252826
do_more:
28262827
if (!range->sync) {
2827-
if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
2828+
if (!f2fs_down_write_trylock_trace(&sbi->gc_lock, &gc_control.lc)) {
28282829
ret = -EBUSY;
28292830
goto out;
28302831
}
28312832
} else {
2832-
f2fs_down_write(&sbi->gc_lock);
2833+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
28332834
}
28342835

28352836
gc_control.victim_segno = GET_SEGNO(sbi, range->start);
@@ -3320,7 +3321,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
33203321
end_segno = min(start_segno + range.segments, dev_end_segno);
33213322

33223323
while (start_segno < end_segno) {
3323-
if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
3324+
if (!f2fs_down_write_trylock_trace(&sbi->gc_lock, &gc_control.lc)) {
33243325
ret = -EBUSY;
33253326
goto out;
33263327
}

fs/f2fs/gc.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ static int gc_thread_func(void *data)
102102
if (sbi->gc_mode == GC_URGENT_HIGH ||
103103
sbi->gc_mode == GC_URGENT_MID) {
104104
wait_ms = gc_th->urgent_sleep_time;
105-
f2fs_down_write(&sbi->gc_lock);
105+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
106106
goto do_gc;
107107
}
108108

109109
if (foreground) {
110-
f2fs_down_write(&sbi->gc_lock);
110+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
111111
goto do_gc;
112-
} else if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
112+
} else if (!f2fs_down_write_trylock_trace(&sbi->gc_lock,
113+
&gc_control.lc)) {
113114
stat_other_skip_bggc_count(sbi);
114115
goto next;
115116
}
116117

117118
if (!is_idle(sbi, GC_TIME)) {
118119
increase_sleep_time(gc_th, &wait_ms);
119-
f2fs_up_write(&sbi->gc_lock);
120+
f2fs_up_write_trace(&sbi->gc_lock, &gc_control.lc);
120121
stat_io_skip_bggc_count(sbi);
121122
goto next;
122123
}
@@ -125,7 +126,8 @@ static int gc_thread_func(void *data)
125126
if (has_enough_free_blocks(sbi,
126127
gc_th->no_zoned_gc_percent)) {
127128
wait_ms = gc_th->no_gc_sleep_time;
128-
f2fs_up_write(&sbi->gc_lock);
129+
f2fs_up_write_trace(&sbi->gc_lock,
130+
&gc_control.lc);
129131
goto next;
130132
}
131133
if (wait_ms == gc_th->no_gc_sleep_time)
@@ -2046,7 +2048,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
20462048
reserved_segments(sbi),
20472049
prefree_segments(sbi));
20482050

2049-
f2fs_up_write(&sbi->gc_lock);
2051+
f2fs_up_write_trace(&sbi->gc_lock, &gc_control->lc);
20502052

20512053
put_gc_inode(&gc_list);
20522054

@@ -2264,6 +2266,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
22642266
__u64 old_block_count, shrunk_blocks;
22652267
struct cp_control cpc = { CP_RESIZE, 0, 0, 0 };
22662268
struct f2fs_lock_context lc;
2269+
struct f2fs_lock_context glc;
22672270
unsigned int secs;
22682271
int err = 0;
22692272
__u32 rem;
@@ -2307,7 +2310,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
23072310
secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
23082311

23092312
/* stop other GC */
2310-
if (!f2fs_down_write_trylock(&sbi->gc_lock)) {
2313+
if (!f2fs_down_write_trylock_trace(&sbi->gc_lock, &glc)) {
23112314
err = -EAGAIN;
23122315
goto out_drop_write;
23132316
}
@@ -2329,7 +2332,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
23292332

23302333
out_unlock:
23312334
f2fs_unlock_op(sbi, &lc);
2332-
f2fs_up_write(&sbi->gc_lock);
2335+
f2fs_up_write_trace(&sbi->gc_lock, &glc);
23332336
out_drop_write:
23342337
mnt_drop_write_file(filp);
23352338
if (err)
@@ -2346,7 +2349,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
23462349
return -EROFS;
23472350
}
23482351

2349-
f2fs_down_write(&sbi->gc_lock);
2352+
f2fs_down_write_trace(&sbi->gc_lock, &glc);
23502353
f2fs_down_write(&sbi->cp_global_sem);
23512354

23522355
spin_lock(&sbi->stat_lock);
@@ -2396,7 +2399,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
23962399
}
23972400
out_err:
23982401
f2fs_up_write(&sbi->cp_global_sem);
2399-
f2fs_up_write(&sbi->gc_lock);
2402+
f2fs_up_write_trace(&sbi->gc_lock, &glc);
24002403
thaw_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
24012404
return err;
24022405
}

fs/f2fs/segment.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
462462
.should_migrate_blocks = false,
463463
.err_gc_skipped = false,
464464
.nr_free_secs = 1 };
465-
f2fs_down_write(&sbi->gc_lock);
465+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
466466
stat_inc_gc_call_count(sbi, FOREGROUND);
467467
f2fs_gc(sbi, &gc_control);
468468
}
@@ -3373,10 +3373,10 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi)
33733373
f2fs_unlock_op(sbi, &lc);
33743374

33753375
if (f2fs_sb_has_blkzoned(sbi) && err == -EAGAIN && gc_required) {
3376-
f2fs_down_write(&sbi->gc_lock);
3376+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
33773377
err = f2fs_gc_range(sbi, 0, sbi->first_seq_zone_segno - 1,
33783378
true, ZONED_PIN_SEC_REQUIRED_COUNT);
3379-
f2fs_up_write(&sbi->gc_lock);
3379+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
33803380

33813381
gc_required = false;
33823382
if (!err)
@@ -3496,6 +3496,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
34963496
block_t start_block, end_block;
34973497
struct cp_control cpc;
34983498
struct discard_policy dpolicy;
3499+
struct f2fs_lock_context lc;
34993500
unsigned long long trimmed = 0;
35003501
int err = 0;
35013502
bool need_align = f2fs_lfs_mode(sbi) && __is_large_section(sbi);
@@ -3528,10 +3529,10 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
35283529
if (sbi->discard_blks == 0)
35293530
goto out;
35303531

3531-
f2fs_down_write(&sbi->gc_lock);
3532+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
35323533
stat_inc_cp_call_count(sbi, TOTAL_CALL);
35333534
err = f2fs_write_checkpoint(sbi, &cpc);
3534-
f2fs_up_write(&sbi->gc_lock);
3535+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
35353536
if (err)
35363537
goto out;
35373538

fs/f2fs/super.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
25592559
{
25602560
unsigned int s_flags = sbi->sb->s_flags;
25612561
struct cp_control cpc;
2562+
struct f2fs_lock_context lc;
25622563
unsigned int gc_mode = sbi->gc_mode;
25632564
int err = 0;
25642565
int ret;
@@ -2588,7 +2589,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
25882589
.no_bg_gc = true,
25892590
.nr_free_secs = 1 };
25902591

2591-
f2fs_down_write(&sbi->gc_lock);
2592+
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
25922593
stat_inc_gc_call_count(sbi, FOREGROUND);
25932594
err = f2fs_gc(sbi, &gc_control);
25942595
if (err == -ENODATA) {
@@ -2612,7 +2613,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
26122613
}
26132614

26142615
skip_gc:
2615-
f2fs_down_write(&sbi->gc_lock);
2616+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
26162617
cpc.reason = CP_PAUSE;
26172618
set_sbi_flag(sbi, SBI_CP_DISABLED);
26182619
stat_inc_cp_call_count(sbi, TOTAL_CALL);
@@ -2625,7 +2626,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
26252626
spin_unlock(&sbi->stat_lock);
26262627

26272628
out_unlock:
2628-
f2fs_up_write(&sbi->gc_lock);
2629+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
26292630
restore_flag:
26302631
sbi->gc_mode = gc_mode;
26312632
sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
@@ -2638,6 +2639,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
26382639
unsigned int nr_pages = get_pages(sbi, F2FS_DIRTY_DATA) / 16;
26392640
long long start, writeback, lock, sync_inode, end;
26402641
int ret;
2642+
struct f2fs_lock_context lc;
26412643

26422644
f2fs_info(sbi, "%s start, meta: %lld, node: %lld, data: %lld",
26432645
__func__,
@@ -2672,12 +2674,12 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
26722674

26732675
sync_inode = ktime_get();
26742676

2675-
f2fs_down_write(&sbi->gc_lock);
2677+
f2fs_down_write_trace(&sbi->gc_lock, &lc);
26762678
f2fs_dirty_to_prefree(sbi);
26772679

26782680
clear_sbi_flag(sbi, SBI_CP_DISABLED);
26792681
set_sbi_flag(sbi, SBI_IS_DIRTY);
2680-
f2fs_up_write(&sbi->gc_lock);
2682+
f2fs_up_write_trace(&sbi->gc_lock, &lc);
26812683

26822684
f2fs_info(sbi, "%s sync_fs, meta: %lld, imeta: %lld, node: %lld, dents: %lld, qdata: %lld",
26832685
__func__,
@@ -4893,7 +4895,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
48934895
sbi->sb = sb;
48944896

48954897
/* initialize locks within allocated memory */
4896-
init_f2fs_rwsem(&sbi->gc_lock);
4898+
init_f2fs_rwsem_trace(&sbi->gc_lock, sbi, LOCK_NAME_GC_LOCK);
48974899
mutex_init(&sbi->writepages);
48984900
init_f2fs_rwsem(&sbi->cp_global_sem);
48994901
init_f2fs_rwsem_trace(&sbi->node_write, sbi, LOCK_NAME_NODE_WRITE);

include/trace/events/f2fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ TRACE_DEFINE_ENUM(CP_PHASE_FINISH_CHECKPOINT);
188188
__print_symbolic(lock, \
189189
{ LOCK_NAME_CP_RWSEM, "cp_rwsem" }, \
190190
{ LOCK_NAME_NODE_CHANGE, "node_change" }, \
191-
{ LOCK_NAME_NODE_WRITE, "node_write" })
191+
{ LOCK_NAME_NODE_WRITE, "node_write" }, \
192+
{ LOCK_NAME_GC_LOCK, "gc_lock" })
192193

193194
struct f2fs_sb_info;
194195
struct f2fs_io_info;

0 commit comments

Comments
 (0)