Skip to content

Commit 8d1cb17

Browse files
yhli-twJaegeuk Kim
authored andcommitted
f2fs: optimize trace_f2fs_write_checkpoint with enums
This patch optimizes the tracepoint by replacing these hardcoded strings with a new enumeration f2fs_cp_phase. 1.Defines enum f2fs_cp_phase with values for each checkpoint phase. 2.Updates trace_f2fs_write_checkpoint to accept a u16 phase argument instead of a string pointer. 3.Uses __print_symbolic in TP_printk to convert the enum values back to their corresponding strings for human-readable trace output. This change reduces the storage overhead for each trace event by replacing a variable-length string with a 2-byte integer, while maintaining the same readable output in ftrace. Signed-off-by: YH Lin <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 37345ea commit 8d1cb17

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

fs/f2fs/checkpoint.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,15 +1673,15 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
16731673
goto out;
16741674
}
16751675

1676-
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops");
1676+
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, CP_PHASE_START_BLOCK_OPS);
16771677

16781678
err = block_operations(sbi);
16791679
if (err)
16801680
goto out;
16811681

16821682
stat_cp_time(cpc, CP_TIME_OP_LOCK);
16831683

1684-
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops");
1684+
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, CP_PHASE_FINISH_BLOCK_OPS);
16851685

16861686
f2fs_flush_merged_writes(sbi);
16871687

@@ -1747,7 +1747,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
17471747

17481748
/* update CP_TIME to trigger checkpoint periodically */
17491749
f2fs_update_time(sbi, CP_TIME);
1750-
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint");
1750+
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, CP_PHASE_FINISH_CHECKPOINT);
17511751
out:
17521752
if (cpc->reason != CP_RESIZE)
17531753
f2fs_up_write(&sbi->cp_global_sem);

fs/f2fs/f2fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ struct cp_control {
319319
struct cp_stats stats;
320320
};
321321

322+
enum f2fs_cp_phase {
323+
CP_PHASE_START_BLOCK_OPS,
324+
CP_PHASE_FINISH_BLOCK_OPS,
325+
CP_PHASE_FINISH_CHECKPOINT,
326+
};
327+
322328
/*
323329
* indicate meta/data type
324330
*/

include/trace/events/f2fs.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ TRACE_DEFINE_ENUM(CP_PAUSE);
5050
TRACE_DEFINE_ENUM(CP_RESIZE);
5151
TRACE_DEFINE_ENUM(EX_READ);
5252
TRACE_DEFINE_ENUM(EX_BLOCK_AGE);
53+
TRACE_DEFINE_ENUM(CP_PHASE_START_BLOCK_OPS);
54+
TRACE_DEFINE_ENUM(CP_PHASE_FINISH_BLOCK_OPS);
55+
TRACE_DEFINE_ENUM(CP_PHASE_FINISH_CHECKPOINT);
5356

5457
#define show_block_type(type) \
5558
__print_symbolic(type, \
@@ -175,6 +178,12 @@ TRACE_DEFINE_ENUM(EX_BLOCK_AGE);
175178
#define S_ALL_PERM (S_ISUID | S_ISGID | S_ISVTX | \
176179
S_IRWXU | S_IRWXG | S_IRWXO)
177180

181+
#define show_cp_phase(phase) \
182+
__print_symbolic(phase, \
183+
{ CP_PHASE_START_BLOCK_OPS, "start block_ops" }, \
184+
{ CP_PHASE_FINISH_BLOCK_OPS, "finish block_ops" }, \
185+
{ CP_PHASE_FINISH_CHECKPOINT, "finish checkpoint" })
186+
178187
struct f2fs_sb_info;
179188
struct f2fs_io_info;
180189
struct extent_info;
@@ -1573,26 +1582,26 @@ TRACE_EVENT(f2fs_readpages,
15731582

15741583
TRACE_EVENT(f2fs_write_checkpoint,
15751584

1576-
TP_PROTO(struct super_block *sb, int reason, const char *msg),
1585+
TP_PROTO(struct super_block *sb, int reason, u16 phase),
15771586

1578-
TP_ARGS(sb, reason, msg),
1587+
TP_ARGS(sb, reason, phase),
15791588

15801589
TP_STRUCT__entry(
15811590
__field(dev_t, dev)
15821591
__field(int, reason)
1583-
__string(dest_msg, msg)
1592+
__field(u16, phase)
15841593
),
15851594

15861595
TP_fast_assign(
15871596
__entry->dev = sb->s_dev;
15881597
__entry->reason = reason;
1589-
__assign_str(dest_msg);
1598+
__entry->phase = phase;
15901599
),
15911600

15921601
TP_printk("dev = (%d,%d), checkpoint for %s, state = %s",
15931602
show_dev(__entry->dev),
15941603
show_cpreason(__entry->reason),
1595-
__get_str(dest_msg))
1604+
show_cp_phase(__entry->phase))
15961605
);
15971606

15981607
DECLARE_EVENT_CLASS(f2fs_discard,

0 commit comments

Comments
 (0)