scripts/gdb/linux/mm.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/mm.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/mm.py- Extension
.py- Size
- 20430 bytes
- Lines
- 575
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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
import math
from linux import utils, constants
def DIV_ROUND_UP(n,d):
return ((n) + (d) - 1) // (d)
def test_bit(nr, addr):
if addr.dereference() & (0x1 << nr):
return True
else:
return False
class page_ops():
ops = None
def __init__(self):
if not constants.LX_CONFIG_SPARSEMEM_VMEMMAP:
raise gdb.GdbError('Only support CONFIG_SPARSEMEM_VMEMMAP now')
if constants.LX_CONFIG_ARM64 and utils.is_target_arch('aarch64'):
self.ops = aarch64_page_ops()
elif utils.is_target_arch('x86_64') or utils.is_target_arch('x86-64'):
self.ops = x86_page_ops()
else:
raise gdb.GdbError('Only support aarch64 and x86_64 now')
class x86_page_ops():
def __init__(self):
self.struct_page_size = utils.get_page_type().sizeof
self.PAGE_SHIFT = constants.LX_CONFIG_PAGE_SHIFT
self.PAGE_SIZE = 1 << self.PAGE_SHIFT
self.PAGE_MASK = (~(self.PAGE_SIZE - 1)) & ((1 << 64) - 1)
self.PAGE_OFFSET = int(gdb.parse_and_eval("page_offset_base"))
self.VMEMMAP_START = int(gdb.parse_and_eval("vmemmap_base"))
self.PHYS_BASE = int(gdb.parse_and_eval("(unsigned long) phys_base"))
self.START_KERNEL_map = 0xffffffff80000000
self.KERNEL_START = gdb.parse_and_eval("(unsigned long) &_text")
self.KERNEL_END = gdb.parse_and_eval("(unsigned long) &_end")
self.VMALLOC_START = int(gdb.parse_and_eval("vmalloc_base"))
if self.VMALLOC_START == 0xffffc90000000000:
self.VMALLOC_END = self.VMALLOC_START + (32 * 1024 * 1024 * 1024 * 1024) - 1
elif self.VMALLOC_START == 0xffa0000000000000:
self.VMALLOC_END = self.VMALLOC_START + (12800 * 1024 * 1024 * 1024 * 1024) - 1
else:
self.VMALLOC_END = self.VMALLOC_START + (12800 * 1024 * 1024 * 1024 * 1024) - 1
self.MAX_PHYSMEM_BITS = 46
self.SECTION_SIZE_BITS = 27
self.MAX_ORDER = 10
self.SECTIONS_SHIFT = self.MAX_PHYSMEM_BITS - self.SECTION_SIZE_BITS
self.NR_MEM_SECTIONS = 1 << self.SECTIONS_SHIFT
self.PFN_SECTION_SHIFT = self.SECTION_SIZE_BITS - self.PAGE_SHIFT
self.PAGES_PER_SECTION = 1 << self.PFN_SECTION_SHIFT
self.PAGE_SECTION_MASK = (~(self.PAGES_PER_SECTION - 1)) & ((1 << 64) - 1)
if constants.LX_CONFIG_SPARSEMEM_EXTREME:
self.SECTIONS_PER_ROOT = self.PAGE_SIZE // gdb.lookup_type("struct mem_section").sizeof
else:
self.SECTIONS_PER_ROOT = 1
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.