$ cd ../
buddy-watch — bash

user@devops:~$ cat README.md

buddy-watch

# Description

buddy-watch (cpp-buddy-watch) is a Linux memory fragmentation monitor written in C++23 with zero external dependencies. It reads the kernel's /proc/buddyinfo and analyzes the free-block distribution per order in the buddy allocator: the 11 orders (0-10) per node and zone (DMA, DMA32, Normal...). Per zone it computes total free memory (4 KiB pages), the maximum contiguous block (2^order x 4 KiB, up to 4 MiB at order 10), the external fragmentation index (frag% = 100 x (1 - pages in blocks of order >= 4 / total free)) and the order-9 (2 MiB) blocks ready for Transparent Huge Pages (THP). Watch mode (--watch N) with periodic refresh, free-memory delta, historical minimum and maximum fragmentation; --timeout T for automatic exit (ideal for cron/scripts). JSON output (--json) with a full snapshot: ts, total_free_pages, total_free_kib, fragmentation_pct, thp_blocks, max_contig_order and per-zone blocks, validated with python3 -m json.tool. --demo mode with a realistic synthetic snapshot for containers/VMs. --no-color with a mutable ANSI palette that is fully emptied (grep for the ESC byte returns 0). 26 self-tests (--selftest): parsing of synthetic and real /proc/buddyinfo lines, arithmetic consistency (each zone = sum of blocks x 2^order), fragmentation metrics (all in order >= 4 = 0%, only order 0 = 100%), human units, balanced-brace JSON, watch deltas and argument parsing. Zero dependencies: direct build with g++ -std=c++23.

# Key features

$ /proc/buddyinfo parsing: 11 free-block orders (0-10) per node and zone (DMA, DMA32, Normal), tolerant of malformed lines or extra/missing numbers

$ Per-zone external fragmentation index: frag% = 100 x (1 - pages in blocks >= order 4 / total free) — 0% = big blocks, 100% = only scattered 4 KiB blocks

$ THP readiness: order-9 (2 MiB) block count, the contiguous blocks Transparent Huge Pages needs to allocate large pages

$ Maximum contiguous block per zone and global (up to 4 MiB at order 10)

$ Watch mode (--watch N) with free-memory delta, historical minimum and maximum fragmentation; --timeout T for automatic exit (ideal for cron)

$ JSON output (--json) with a full snapshot validated with python3 -m json.tool

$ --demo with realistic synthetic data for containers/VMs and --no-color with a mutable ANSI palette (grep for the ESC byte = 0)

$ 26 self-tests (--selftest): parsing, arithmetic consistency, metrics, human units, JSON and watch deltas

# Gallery

Project terminal
buddy-watch - Project terminal
Mobile view
buddy-watch - Mobile view

# Technologies used

C++23