|
67 | 67 | u64 lwb_ts; |
68 | 68 | u64 io_ts; |
69 | 69 | int sync; |
70 | | - int alloc_count; |
71 | 70 | } zil_tid_info_t; |
72 | 71 |
|
73 | 72 | BPF_HASH(zil_info_map, u32, zil_tid_info_t); |
|
83 | 82 | HIST_KEY(zil_hist_key_t, zil_key_t); |
84 | 83 |
|
85 | 84 | BPF_HASH(average_latency, zil_key_t, average_t); |
86 | | -BPF_HASH(average_allocs, zil_key_t, average_t); |
| 85 | +BPF_HASH(call_counts, zil_key_t, u64); |
87 | 86 | BPF_HASH(zil_latency, zil_hist_key_t, u64); |
88 | 87 |
|
89 | 88 | static inline bool equal_to_pool(char *str) |
|
111 | 110 | avg->sum += delta; |
112 | 111 | hist_key.slot = bpf_log2l(delta); |
113 | 112 | zil_latency.increment(hist_key); |
| 113 | + call_counts.increment(key); |
114 | 114 |
|
115 | 115 | return 0; |
116 | 116 | } |
117 | 117 |
|
| 118 | +static int count_call(char *name) { |
| 119 | + zil_key_t key = {}; |
| 120 | + __builtin_memcpy(&key.name, name, NAME_LENGTH); |
| 121 | + key.t = 1; |
| 122 | + key.cpuid = bpf_get_smp_processor_id(); |
| 123 | + call_counts.increment(key); |
| 124 | + return 0; |
| 125 | +} |
| 126 | +
|
| 127 | +
|
118 | 128 | int zfs_write_entry(struct pt_regs *ctx, struct znode *zn, |
119 | 129 | void *uio, int ioflag) |
120 | 130 | { |
|
128 | 138 | if (!equal_to_pool(spa->spa_name)) |
129 | 139 | return 0; |
130 | 140 |
|
131 | | - info.alloc_count = 0; |
132 | 141 | info.sync = ioflag & (O_SYNC | O_DSYNC) || |
133 | 142 | zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS; |
134 | 143 | zil_info_map.update(&tid, &info); |
|
154 | 163 | return 0; |
155 | 164 | } |
156 | 165 |
|
| 166 | +int zfs_fsync_entry(struct pt_regs *ctx, struct znode *zn) |
| 167 | +{ |
| 168 | + u32 tid = bpf_get_current_pid_tgid(); |
| 169 | + zil_tid_info_t info = {}; |
| 170 | +
|
| 171 | + info.write_ts = bpf_ktime_get_ns(); |
| 172 | + zfsvfs_t *zfsvfs = zn->z_inode.i_sb->s_fs_info; |
| 173 | + objset_t *z_os = zfsvfs->z_os; |
| 174 | + spa_t *spa = z_os->os_spa; |
| 175 | + if (!equal_to_pool(spa->spa_name)) |
| 176 | + return 0; |
| 177 | +
|
| 178 | + zil_info_map.update(&tid, &info); |
| 179 | + return 0; |
| 180 | +} |
| 181 | +
|
| 182 | +int zfs_fsync_return(struct pt_regs *cts) |
| 183 | +{ |
| 184 | + u32 tid = bpf_get_current_pid_tgid(); |
| 185 | + zil_tid_info_t *info = zil_info_map.lookup(&tid); |
| 186 | + if (info == NULL) { |
| 187 | + return 0; |
| 188 | + } |
| 189 | +
|
| 190 | + // Record if called zil_commit |
| 191 | + if (info->commit_ts != 0) { |
| 192 | + latency_average_and_histogram("zfs_fysnc", |
| 193 | + (bpf_ktime_get_ns() - info->write_ts) / 1000); |
| 194 | + } |
| 195 | +
|
| 196 | + zil_info_map.delete(&tid); |
| 197 | + return 0; |
| 198 | +} |
| 199 | +
|
| 200 | +
|
157 | 201 |
|
158 | 202 | int zil_commit_entry(struct pt_regs *ctx) |
159 | 203 | { |
160 | 204 | u32 tid = bpf_get_current_pid_tgid(); |
161 | 205 | zil_tid_info_t *info = zil_info_map.lookup(&tid); |
162 | | - if (info == NULL) |
| 206 | + if (info == NULL) { |
163 | 207 | return 0; |
| 208 | + } |
| 209 | +
|
164 | 210 | info->commit_ts = bpf_ktime_get_ns(); |
165 | 211 | return 0; |
166 | 212 | } |
|
176 | 222 | latency_average_and_histogram("zil_commit", |
177 | 223 | (bpf_ktime_get_ns() - info->commit_ts) / 1000); |
178 | 224 |
|
179 | | - zil_key_t key = {}; |
180 | | - key.t = 1; |
181 | | - key.cpuid = bpf_get_smp_processor_id(); |
182 | | - __builtin_memcpy(&key.name, "Allocations", NAME_LENGTH); |
183 | | - average_t zero_avg = ZERO_AVERAGE; |
184 | | - average_t *avg = average_allocs.lookup_or_init(&key, &zero_avg); |
185 | | - avg->count++; |
186 | | - avg->sum += 10; //info->alloc_count; |
187 | 225 | return 0; |
188 | 226 | } |
189 | 227 |
|
190 | 228 | // First major call in zil_commit_writer() |
191 | 229 | int zil_get_commit_list_entry(struct pt_regs *ctx) |
192 | 230 | { |
193 | 231 | u32 tid = bpf_get_current_pid_tgid(); |
194 | | - u64 ts = bpf_ktime_get_ns(); |
195 | 232 | zil_tid_info_t *info = zil_info_map.lookup(&tid); |
196 | 233 | if (info == NULL) |
197 | 234 | return 0; |
198 | | - info->lwb_ts = ts; |
| 235 | + info->lwb_ts = bpf_ktime_get_ns(); |
199 | 236 | return 0; |
200 | 237 | } |
201 | 238 |
|
|
207 | 244 | if (info == NULL) { |
208 | 245 | return 0; |
209 | 246 | } |
210 | | -
|
| 247 | + if (info->lwb_ts == 0) { |
| 248 | + return 0; |
| 249 | + } |
211 | 250 |
|
212 | 251 | return latency_average_and_histogram("allocation", |
213 | 252 | (bpf_ktime_get_ns() - info->lwb_ts) / 1000); |
|
243 | 282 | if (info == NULL) { |
244 | 283 | return 0; |
245 | 284 | } |
246 | | - info->alloc_count++; |
| 285 | + count_call("block allocations"); |
| 286 | + return 0; |
| 287 | +} |
| 288 | +
|
| 289 | +int zil_commit_waiter_skip_entry(struct pt_regs *cts) |
| 290 | +{ |
| 291 | + u32 tid = bpf_get_current_pid_tgid(); |
| 292 | + zil_tid_info_t *info = zil_info_map.lookup(&tid); |
| 293 | + if (info == NULL) { |
| 294 | + return 0; |
| 295 | + } |
| 296 | +
|
| 297 | + count_call("waiter skip"); |
247 | 298 | return 0; |
248 | 299 | } |
249 | 300 |
|
| 301 | +int zil_commit_writer_stall_entry(struct pt_regs *cts) |
| 302 | +{ |
| 303 | + u32 tid = bpf_get_current_pid_tgid(); |
| 304 | + zil_tid_info_t *info = zil_info_map.lookup(&tid); |
| 305 | + if (info == NULL) { |
| 306 | + return 0; |
| 307 | + } |
| 308 | +
|
| 309 | + count_call("writer stall"); |
| 310 | + return 0; |
| 311 | +} |
250 | 312 | """ |
251 | 313 |
|
252 | 314 | # load BPF program |
|
261 | 323 |
|
262 | 324 | b.attach_kprobe(event="zfs_write", fn_name="zfs_write_entry") |
263 | 325 | b.attach_kretprobe(event="zfs_write", fn_name="zfs_write_return") |
| 326 | +b.attach_kprobe(event="zfs_fsync", fn_name="zfs_fsync_entry") |
| 327 | +b.attach_kretprobe(event="zfs_fsync", fn_name="zfs_fsync_return") |
264 | 328 | b.attach_kprobe(event="zil_commit", fn_name="zil_commit_entry") |
265 | 329 | b.attach_kretprobe(event="zil_commit", fn_name="zil_commit_return") |
266 | 330 | b.attach_kretprobe(event="zil_process_commit_list", |
|
271 | 335 | fn_name="zil_commit_waiter_entry") |
272 | 336 | b.attach_kretprobe(event="zil_commit_waiter", |
273 | 337 | fn_name="zil_commit_waiter_return") |
274 | | -b.attach_kretprobe(event="zio_alloc_zil", fn_name="zio_alloc_zil_return") |
| 338 | +b.attach_kretprobe(event="zio_alloc_zil", |
| 339 | + fn_name="zio_alloc_zil_return") |
| 340 | +b.attach_kprobe(event="zil_commit_waiter_skip", |
| 341 | + fn_name="zil_commit_waiter_skip_entry") |
| 342 | +b.attach_kprobe(event="zil_commit_writer_stall", |
| 343 | + fn_name="zil_commit_writer_stall_entry") |
275 | 344 |
|
276 | 345 | latency_helper = BCCHelper(b, BCCHelper.ESTAT_PRINT_MODE) |
277 | 346 | latency_helper.add_aggregation("average_latency", |
278 | | - BCCHelper.AVERAGE_AGGREGATION, "avg") |
| 347 | + BCCHelper.AVERAGE_AGGREGATION, "avg latency") |
279 | 348 | latency_helper.add_aggregation("zil_latency", |
280 | 349 | BCCHelper.LOG_HISTOGRAM_AGGREGATION, "latency") |
281 | 350 | latency_helper.add_key_type("name") |
282 | 351 |
|
283 | | -alloc_helper = BCCHelper(b, BCCHelper.ESTAT_PRINT_MODE) |
284 | | -alloc_helper.add_aggregation("average_allocs", |
285 | | - BCCHelper.AVERAGE_AGGREGATION, "avg") |
286 | | -alloc_helper.add_key_type("name") |
| 352 | +call_count_helper = BCCHelper(b, BCCHelper.ESTAT_PRINT_MODE) |
| 353 | +call_count_helper.add_aggregation("call_counts", |
| 354 | + BCCHelper.COUNT_AGGREGATION, "count") |
| 355 | +call_count_helper.add_key_type("name") |
287 | 356 |
|
288 | 357 | if (not args.collection_sec): |
289 | 358 | print(" Tracing enabled... Hit Ctrl-C to end.") |
|
294 | 363 | try: |
295 | 364 | print("%-16s\n" % strftime("%D - %H:%M:%S %Z")) |
296 | 365 | latency_helper.printall() |
297 | | - alloc_helper.printall() |
| 366 | + call_count_helper.printall() |
298 | 367 | exit(0) |
299 | 368 | except Exception as e: |
300 | 369 | print(str(e)) |
|
307 | 376 | except KeyboardInterrupt: |
308 | 377 | print("%-16s\n" % strftime("%D - %H:%M:%S %Z")) |
309 | 378 | latency_helper.printall() |
310 | | - alloc_helper.printall() |
| 379 | + call_count_helper.printall() |
311 | 380 | break |
312 | 381 | try: |
313 | 382 | print("%-16s\n" % strftime("%D - %H:%M:%S %Z")) |
314 | 383 | latency_helper.printall() |
315 | | - alloc_helper.printall() |
| 384 | + call_count_helper.printall() |
316 | 385 | except Exception as e: |
317 | 386 | print(str(e)) |
318 | 387 | break |
0 commit comments