compactsnoop(8)
β¨ compactsnoop(8) β¨
okay bestie, welcome to your new fave little tool β it lives in the System Manager's Manual and its whole name is compactsnoop, section 8. Let's get into it π
π NAME π
compactsnoop β traces compact zone events. uses Linux eBPF/bcc, no cap.
π¦ SYNOPSIS π¦
compactsnoop [-h] [-T] [-p PID] [-d DURATION] [-K] [-e]
πΈ DESCRIPTION πΈ
so basically compactsnoop traces the compact zone events and shows you which processes are allocing pages with memory compaction. it's genuinely so useful for figuring out when compact_stall (in /proc/vmstat) just keeps going up β and whether some critical process is the one causing it or not. iykyk.
the way it works: it traces the compact zone events using raw_tracepoints and one kretprobe. iconic.
for Centos 7.6 (3.10.x kernel), there's a version under tools/old β that one uses an older memory compaction mechanism. different vibe, same energy.
π real talk though: since this uses BPF, only the root user can use this tool. no exceptions, bestie.
π«Ά REQUIREMENTS π«Ά
CONFIG_BPFbcc
that's it. that's the list.
β¨ OPTIONS β¨
-hβ prints the usage message. the classic cry-for-help flag π₯Ί-Tβ adds a timestamp column. time is real.-pPIDβ trace this process ID only (and yes, it's filtered in-kernel, so it's giving efficient).-dDURATIONβ total duration of the trace, in seconds. clock it.-Kβ outputs the kernel stack trace. spicy.-eβ shows the extended fields. more data, more fun.
π₯ EXAMPLES π₯
trace all compact zone events:
# compactsnoop
trace all compact zone events, but for 10 seconds only:
# compactsnoop -d 10
π FIELDS π
TIME(s)β time of the call, in seconds.COMMβ process name.PIDβ process ID.NODEβ memory node.ZONEβ zone of the node (such asDMA,DMA32,NORMALeg).ORDERβ shows which order alloc caused memory compaction;-1means all orders (eg: write to/proc/sys/vm/compact_memory).MODEβSYNCorASYNC.FRAGIDX(extra column) β short for fragmentation index, which only makes sense if an allocation of a requested size would fail. if that's true, the fragmentation index tells you whether external fragmentation or a lack of memory was the problem. you can use the value to determine if page reclaim or compaction should be used. index is between 0 and 1 so it returns within 3 decimal places:0=> allocation would fail due to lack of memory1=> 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) β thenr_free_pagesof the zone.LAT(ms)β compact zone's latency.STATUSβ the compaction's result. and ooh, this one's got layers:
for (CentOS 7.6's kernel), the status includes:
"skipped"(COMPACT_SKIPPED): compaction didn't start as it was not possible or direct reclaim was more suitable"continue"(COMPACT_CONTINUE): compaction should continue 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):
"not_suitable_zone"(COMPACT_NOT_SUITABLE_ZONE): for more detailed tracepoint output - internal to compaction"skipped"(COMPACT_SKIPPED): compaction didn't start as it was not possible or direct reclaim was more suitable"deferred"(COMPACT_DEFERRED): compaction didn't start as it was deferred due to past failures"no_suitable_page"(COMPACT_NOT_SUITABLE_PAGE): for more detailed tracepoint output - internal to compaction"continue"(COMPACT_CONTINUE): compaction should continue to another pageblock"complete"(COMPACT_COMPLETE): the full zone was compacted scanned but wasn't successful to compact suitable pages"partial_skipped"(COMPACT_PARTIAL_SKIPPED): direct compaction has scanned part of the zone but wasn't successful to compact suitable pages"contended"(COMPACT_CONTENDED): compaction terminated prematurely due to lock contentions"success"(COMPACT_SUCCESS): direct compaction terminated after concluding that the allocation should now succeed
π§ OVERHEAD π§
this traces the kernel compact zone kprobe/kretprobe or raw_tracepoints and prints output for each event. and because the rate of this is generally expected to be low (< 1000/s), the overhead is also expected to be negligible. so yeah, it's lightweight, it's not gonna eat your CPU, we love a low-maintenance queen π
β SOURCE β
this is from bcc.
https://github.com/iovisor/bcc
also likeβ¦ look in the bcc distribution for a companion _examples.txt file β it's got example usage, output, and commentary for this tool. free bonus content, obsessed.
π OS π
Linux (obviously, bestie)
π STABILITY π
Unstable - in development. she's still growing, be nice to her π₯Ί
π AUTHOR π
Wenbo Zhang
and that's the whole page, mwah π β this cutie came out of USER COMMANDS, dated 2019-11-1, and she answers to the name compactsnoop(8). go forth and trace, bestie π
π¦ where this page comes from
- centos-stream 10: bcc-tools 0.36.1-1.el10 Β· Apache-2.0
- centos-stream 9: bcc-tools 0.36.1-1.el9 Β· ASL 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms