From: Aaron Tomlin <atomlin@atomlin.com>
To: akpm@linux-foundation.org
Cc: osandov@osandov.com, sean@ashe.io, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] tools/mm: add script to display /proc/buddyinfo from vmcore
Date: Fri, 23 Oct 2026 17:23:56 -0400 [thread overview]
Message-ID: <20261023212356.215922-1-atomlin@atomlin.com> (raw)
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
reply other threads:[~2026-10-23 21:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261023212356.215922-1-atomlin@atomlin.com \
--to=atomlin@atomlin.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osandov@osandov.com \
--cc=sean@ashe.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®