compactsnoop(8)

πŸ“¦
version 0.35.0 Β· 2 versions
  • 0.35.0 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.18.0 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

compactsnoop(8) from the System Manager's Manual πŸ’…

compactsnoop β€” Trace compact zone events. Uses Linux eBPF/bcc. πŸ¦‹

🌸 SYNOPSIS 🌸

compactsnoop [-h] [-T] [-p PID] [-d DURATION] [-K] [-e]

πŸ’– DESCRIPTION πŸ’–

okay so compactsnoop traces the compact zone events and shows you which processes are allocing pages with memory compaction πŸ‘€ this is lowkey so useful for figuring out when compact_stall (/proc/vmstat) keeps climbing, and whether some critical processes are the ones causing it 😭

it works by tracing the compact zone events using raw_tracepoints and one kretprobe ✨

πŸ’€ for the CentOS 7.6 (3.10.x kernel), check the version under tools/old, which uses an older memory compaction mechanism. different vibes, different code!

and since this uses BPF, only the root user can run this tool πŸ”

🧚 REQUIREMENTS 🧚

you need CONFIG_BPF and bcc πŸŽ€

✨ OPTIONS ✨

  • -h β€” print the usage message πŸ™ˆ
  • -T β€” add a timestamp column πŸ•°οΈ
  • -p PID β€” only trace this process ID (filtered in-kernel) 🎯
  • -d DURATION β€” how long the trace runs in total, in seconds ⏳
  • -K β€” output a kernel stack trace 🧱
  • -e β€” show the extended fields πŸ”

πŸ“ EXAMPLES πŸ“

trace all compact zone events:

# compactsnoop

trace all compact zone events, but only for 10 seconds:

# compactsnoop -d 10

πŸ”₯ FIELDS πŸ”₯

  • TIME(s) β€” when the call happened, in seconds ⏰
  • COMM β€” the process name πŸ§‘β€πŸ’»
  • PID β€” the process ID πŸͺͺ
  • NODE β€” the memory node 🧠
  • ZONE β€” the zone of the node (like DMA, DMA32, NORMAL, etc) πŸ—ΊοΈ
  • ORDER β€” shows which order of allocation caused the memory compaction. -1 means all orders (for example, a write to /proc/sys/vm/compact_memory) πŸ“¦
  • MODE β€” SYNC or ASYNC πŸ”„
  • FRAGIDX (extra column) β€” short for fragmentation index, and it only makes sense if an allocation of the requested size would fail. if that's the case, the fragmentation index tells you whether external fragmentation or a lack of memory was the problem 🧩 you can use it to decide if page reclaim or compaction should be used πŸ€”

the index comes back between 0 and 1, to 3 decimal places:

  • 0 => the allocation would fail due to lack of memory 🫠
  • 1 => the allocation would fail due to fragmentation πŸ§ƒ
  • MIN (extra column) β€” the min watermark of the zone πŸ’§
  • LOW (extra column) β€” the low watermark of the zone 🌊
  • HIGH (extra column) β€” the high watermark of the zone 🏊
  • FREE (extra column) β€” the nr_free_pages of the zone πŸ†“
  • LAT(ms) β€” the compact zone's latency, in milliseconds ⚑
  • STATUS β€” the result of the compaction πŸ“‹

for the CentOS 7.6 kernel, the statuses are:

  • "skipped" (COMPACT_SKIPPED): compaction didn't start, because it wasn't possible or direct reclaim was the better choice πŸ™…
  • "continue" (COMPACT_CONTINUE): compaction should keep going to another pageblock ➑️
  • "partial" (COMPACT_PARTIAL): direct compaction partially compacted a zone and there are suitable pages 🧩
  • "complete" (COMPACT_COMPLETE): the full zone was compacted 🏁

for kernel 4.7 and above, the statuses are:

  • "not_suitable_zone" (COMPACT_NOT_SUITABLE_ZONE): more detailed tracepoint output, internal to compaction πŸ”§
  • "skipped" (COMPACT_SKIPPED): compaction didn't start, because it wasn't possible or direct reclaim was the better choice πŸ™…
  • "deferred" (COMPACT_DEFERRED): compaction didn't start because it got deferred due to past failures πŸ˜΅β€πŸ’«
  • "no_suitable_page" (COMPACT_NOT_SUITABLE_PAGE): more detailed tracepoint output, internal to compaction πŸ”§
  • "continue" (COMPACT_CONTINUE): compaction should keep going to another pageblock ➑️
  • "complete" (COMPACT_COMPLETE): the full zone was scanned, but it wasn't successful at compacting suitable pages 😀
  • "partial_skipped" (COMPACT_PARTIAL_SKIPPED): direct compaction scanned part of the zone but wasn't successful at compacting suitable pages πŸ₯²
  • "contended" (COMPACT_CONTENDED): compaction ended early due to lock contention πŸ”’
  • "success" (COMPACT_SUCCESS): direct compaction ended after deciding the allocation should now succeed πŸŽ‰

🌈 OVERHEAD 🌈

this traces the kernel compact zone kprobe/kretprobe or raw_tracepoints and prints output for each event. the rate of events is generally expected to be low (< 1000/s), so the overhead is also expected to be negligible 🫢

πŸ¦‹ SOURCE πŸ¦‹

this is from bcc πŸ’œ

https://github.com/iovisor/bcc

also check the bcc distribution for a companion _examples.txt file, which has example usage, output, and commentary for this tool πŸ“š

πŸ’» OS πŸ’»

Linux 🐧

🚧 STABILITY 🚧

⚠️ Unstable β€” still in development, so don't be shocked if things shift πŸ™ˆ

πŸ‘‘ AUTHOR πŸ‘‘

Wenbo Zhang 🫑


okay bestie that's the whole tea β˜•πŸ’– this page is from the USER COMMANDS section, dated 2019-11-1, and it's all about compactsnoop(8) πŸŽ€βœ¨ stay iconic πŸ’…πŸŒΈ