scripts/gdb/linux/page_owner.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/page_owner.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/page_owner.py- Extension
.py- Size
- 6997 bytes
- Lines
- 183
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2023 MediaTek Inc.
#
# Authors:
# Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
#
import gdb
from linux import utils, stackdepot, constants, mm
if constants.LX_CONFIG_PAGE_OWNER:
page_ext_t = utils.CachedType('struct page_ext')
page_owner_t = utils.CachedType('struct page_owner')
PAGE_OWNER_STACK_DEPTH = 16
PAGE_EXT_OWNER = constants.LX_PAGE_EXT_OWNER
PAGE_EXT_INVALID = 0x1
PAGE_EXT_OWNER_ALLOCATED = constants.LX_PAGE_EXT_OWNER_ALLOCATED
def help():
t = """Usage: lx-dump-page-owner [Option]
Option:
--pfn [Decimal pfn]
Example:
lx-dump-page-owner --pfn 655360\n"""
gdb.write("Unrecognized command\n")
raise gdb.GdbError(t)
class DumpPageOwner(gdb.Command):
"""Dump page owner"""
min_pfn = None
max_pfn = None
p_ops = None
migrate_reason_names = None
def __init__(self):
super(DumpPageOwner, self).__init__("lx-dump-page-owner", gdb.COMMAND_SUPPORT)
def invoke(self, args, from_tty):
if not constants.LX_CONFIG_PAGE_OWNER:
raise gdb.GdbError('CONFIG_PAGE_OWNER does not enable')
page_owner_inited = gdb.parse_and_eval('page_owner_inited')
if page_owner_inited['key']['enabled']['counter'] != 0x1:
raise gdb.GdbError('page_owner_inited is not enabled')
self.p_ops = mm.page_ops().ops
self.get_page_owner_info()
argv = gdb.string_to_argv(args)
if len(argv) == 0:
self.read_page_owner()
elif len(argv) == 2:
if argv[0] == "--pfn":
pfn = int(argv[1])
self.read_page_owner_by_addr(self.p_ops.pfn_to_page(pfn))
else:
help()
else:
help()
def get_page_owner_info(self):
self.min_pfn = int(gdb.parse_and_eval("min_low_pfn"))
self.max_pfn = int(gdb.parse_and_eval("max_pfn"))
self.page_ext_size = int(gdb.parse_and_eval("page_ext_size"))
self.migrate_reason_names = gdb.parse_and_eval('migrate_reason_names')
def page_ext_invalid(self, page_ext):
if page_ext == gdb.Value(0):
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.