* [PATCH] tools/mm: add script to display /proc/buddyinfo from vmcore
@ 2026-10-23 21:23 Aaron Tomlin
0 siblings, 0 replies; only message in thread
From: Aaron Tomlin @ 2026-10-23 21:23 UTC (permalink / raw)
To: akpm; +Cc: osandov, sean, linux-mm, linux-kernel
When analysing crash dumps (vmcores), inspecting the buddy allocator's free
page distribution across memory zones can be useful for diagnosing
allocation failures, fragmentation, and watermark exhaustion.
Introduce tools/mm/show_buddyinfo.py, a drgn-based script that traverses
online NUMA nodes and populated memory zones to inspect free_area[].nr_free
and reconstruct the standard /proc/buddyinfo output.
For example:
❯ sudo drgn --no-default-symbols -c /proc/kcore -s vmlinux tools/mm/show_buddyinfo.py
Node 0, zone DMA 0 0 0 0 0 0 0 0 1 2 2
Node 0, zone DMA32 907 831 581 423 214 85 3 1 2 2 0
Node 0, zone Normal 1 1 143 731 552 182 32 0 0 0 0
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
tools/mm/show_buddyinfo.py | 48 ++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100755 tools/mm/show_buddyinfo.py
diff --git a/tools/mm/show_buddyinfo.py b/tools/mm/show_buddyinfo.py
new file mode 100755
index 000000000000..70372329e7c1
--- /dev/null
+++ b/tools/mm/show_buddyinfo.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env drgn
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright (C) 2026 Aaron Tomlin <atomlin@atomlin.com>
+
+from collections.abc import Iterator
+
+from drgn import Object, Program, get_default_prog
+from drgn.helpers.linux.nodemask import for_each_online_node
+
+DESC = """
+This is a drgn-based Python script that displays /proc/buddyinfo from a
+vmcore. For further information on drgn, please refer to
+https://github.com/osandov/drgn.
+"""
+
+
+def buddyinfo():
+ """Display the buddyinfo."""
+
+ def walk_zones_in_node(prog: Program) -> Iterator[tuple[Object, Object]]:
+ for node_nr in for_each_online_node(prog):
+ try:
+ pgdat = prog["node_data"][node_nr]
+ except (KeyError, Exception):
+ pgdat = prog["contig_page_data"].address_of_()
+ for zone in pgdat.node_zones:
+ yield pgdat, zone
+
+ def populated_zone(zone: Object) -> bool:
+ """Determine if the specified zone is populated."""
+ return zone.present_pages.value_() > 0
+
+ prog = get_default_prog()
+ for pgdat, zone in walk_zones_in_node(prog):
+ if populated_zone(zone):
+ print(
+ f"Node {pgdat.node_id.value_()}, zone "
+ f"{zone.name.string_().decode('utf-8'):8s} ",
+ end="",
+ )
+ for order in range(len(zone.free_area)):
+ print(f"{zone.free_area[order].nr_free.value_():6} ", end="")
+ print()
+
+
+if __name__ == "__main__":
+ buddyinfo()
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 21:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 21:23 [PATCH] tools/mm: add script to display /proc/buddyinfo from vmcore Aaron Tomlin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.