Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nilfs2: add a tracepoint for transaction events

This patch adds a tracepoint for transaction events of nilfs. With the
tracepoint, these events can be tracked: begin, abort, commit, trylock,
lock, and unlock. Basically, these events have corresponding functions
e.g. begin event corresponds nilfs_transaction_begin(). The unlock event
is an exception. It corresponds to the iteration in
nilfs_transaction_lock().

Only one tracepoint is introcued: nilfs2_transaction_transition. The
above events are distinguished with newly introduced enum. With this
tracepoint, we can analyse a critical section of segment constructoin.

Sample output by tpoint of perf-tools:
cp-4457 [000] ...1 63.266220: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800bf5ccc58 count = 1 flags = 9 state = BEGIN
cp-4457 [000] ...1 63.266221: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800bf5ccc58 count = 0 flags = 9 state = COMMIT
cp-4457 [000] ...1 63.266221: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800bf5ccc58 count = 0 flags = 9 state = COMMIT
segctord-4371 [001] ...1 68.261196: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 0 flags = 10 state = TRYLOCK
segctord-4371 [001] ...1 68.261280: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 0 flags = 10 state = LOCK
segctord-4371 [001] ...1 68.261877: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 1 flags = 10 state = BEGIN
segctord-4371 [001] ...1 68.262116: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 0 flags = 18 state = COMMIT
segctord-4371 [001] ...1 68.265032: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 0 flags = 18 state = UNLOCK
segctord-4371 [001] ...1 132.376847: nilfs2_transaction_transition: sb = ffff8802112b8800 ti = ffff8800b889bdf8 count = 0 flags = 10 state = TRYLOCK

This patch also does trivial cleaning of comma usage in collection stage
transition event for consistent coding style.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Hitoshi Mitake and committed by
Linus Torvalds
44fda114 58497703

+85 -1
+32 -1
fs/nilfs2/segment.c
··· 214 214 { 215 215 struct the_nilfs *nilfs; 216 216 int ret = nilfs_prepare_segment_lock(ti); 217 + struct nilfs_transaction_info *trace_ti; 217 218 218 219 if (unlikely(ret < 0)) 219 220 return ret; 220 - if (ret > 0) 221 + if (ret > 0) { 222 + trace_ti = current->journal_info; 223 + 224 + trace_nilfs2_transaction_transition(sb, trace_ti, 225 + trace_ti->ti_count, trace_ti->ti_flags, 226 + TRACE_NILFS2_TRANSACTION_BEGIN); 221 227 return 0; 228 + } 222 229 223 230 sb_start_intwrite(sb); 224 231 ··· 236 229 ret = -ENOSPC; 237 230 goto failed; 238 231 } 232 + 233 + trace_ti = current->journal_info; 234 + trace_nilfs2_transaction_transition(sb, trace_ti, trace_ti->ti_count, 235 + trace_ti->ti_flags, 236 + TRACE_NILFS2_TRANSACTION_BEGIN); 239 237 return 0; 240 238 241 239 failed: ··· 273 261 ti->ti_flags |= NILFS_TI_COMMIT; 274 262 if (ti->ti_count > 0) { 275 263 ti->ti_count--; 264 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 265 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_COMMIT); 276 266 return 0; 277 267 } 278 268 if (nilfs->ns_writer) { ··· 286 272 nilfs_segctor_do_flush(sci, 0); 287 273 } 288 274 up_read(&nilfs->ns_segctor_sem); 275 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 276 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_COMMIT); 277 + 289 278 current->journal_info = ti->ti_save; 290 279 291 280 if (ti->ti_flags & NILFS_TI_SYNC) ··· 307 290 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 308 291 if (ti->ti_count > 0) { 309 292 ti->ti_count--; 293 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 294 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_ABORT); 310 295 return; 311 296 } 312 297 up_read(&nilfs->ns_segctor_sem); 298 + 299 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 300 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_ABORT); 313 301 314 302 current->journal_info = ti->ti_save; 315 303 if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC) ··· 361 339 current->journal_info = ti; 362 340 363 341 for (;;) { 342 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 343 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_TRYLOCK); 344 + 364 345 down_write(&nilfs->ns_segctor_sem); 365 346 if (!test_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags)) 366 347 break; ··· 375 350 } 376 351 if (gcflag) 377 352 ti->ti_flags |= NILFS_TI_GC; 353 + 354 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 355 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_LOCK); 378 356 } 379 357 380 358 static void nilfs_transaction_unlock(struct super_block *sb) ··· 390 362 391 363 up_write(&nilfs->ns_segctor_sem); 392 364 current->journal_info = ti->ti_save; 365 + 366 + trace_nilfs2_transaction_transition(sb, ti, ti->ti_count, 367 + ti->ti_flags, TRACE_NILFS2_TRANSACTION_UNLOCK); 393 368 } 394 369 395 370 static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci,
+53
include/trace/events/nilfs2.h
··· 42 42 show_collection_stage(__entry->stage)) 43 43 ); 44 44 45 + #ifndef TRACE_HEADER_MULTI_READ 46 + enum nilfs2_transaction_transition_state { 47 + TRACE_NILFS2_TRANSACTION_BEGIN, 48 + TRACE_NILFS2_TRANSACTION_COMMIT, 49 + TRACE_NILFS2_TRANSACTION_ABORT, 50 + TRACE_NILFS2_TRANSACTION_TRYLOCK, 51 + TRACE_NILFS2_TRANSACTION_LOCK, 52 + TRACE_NILFS2_TRANSACTION_UNLOCK, 53 + }; 54 + #endif 55 + 56 + #define show_transaction_state(type) \ 57 + __print_symbolic(type, \ 58 + { TRACE_NILFS2_TRANSACTION_BEGIN, "BEGIN" }, \ 59 + { TRACE_NILFS2_TRANSACTION_COMMIT, "COMMIT" }, \ 60 + { TRACE_NILFS2_TRANSACTION_ABORT, "ABORT" }, \ 61 + { TRACE_NILFS2_TRANSACTION_TRYLOCK, "TRYLOCK" }, \ 62 + { TRACE_NILFS2_TRANSACTION_LOCK, "LOCK" }, \ 63 + { TRACE_NILFS2_TRANSACTION_UNLOCK, "UNLOCK" }) 64 + 65 + TRACE_EVENT(nilfs2_transaction_transition, 66 + TP_PROTO(struct super_block *sb, 67 + struct nilfs_transaction_info *ti, 68 + int count, 69 + unsigned int flags, 70 + enum nilfs2_transaction_transition_state state), 71 + 72 + TP_ARGS(sb, ti, count, flags, state), 73 + 74 + TP_STRUCT__entry( 75 + __field(void *, sb) 76 + __field(void *, ti) 77 + __field(int, count) 78 + __field(unsigned int, flags) 79 + __field(int, state) 80 + ), 81 + 82 + TP_fast_assign( 83 + __entry->sb = sb; 84 + __entry->ti = ti; 85 + __entry->count = count; 86 + __entry->flags = flags; 87 + __entry->state = state; 88 + ), 89 + 90 + TP_printk("sb = %p ti = %p count = %d flags = %x state = %s", 91 + __entry->sb, 92 + __entry->ti, 93 + __entry->count, 94 + __entry->flags, 95 + show_transaction_state(__entry->state)) 96 + ); 97 + 45 98 #endif /* _TRACE_NILFS2_H */ 46 99 47 100 /* This part must be outside protection */