tools/mm/thpmaps
Source file repositories/reference/linux-study-clean/tools/mm/thpmaps
File Facts
- System
- Linux kernel
- Corpus path
tools/mm/thpmaps- Extension
[no extension]- Size
- 25261 bytes
- Lines
- 676
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- 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.
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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2024 ARM Ltd.
#
# Utility providing smaps-like output detailing transparent hugepage usage.
# For more info, run:
# ./thpmaps --help
#
# Requires numpy:
# pip3 install numpy
import argparse
import collections
import math
import os
import re
import resource
import shutil
import sys
import textwrap
import time
import numpy as np
with open('/sys/kernel/mm/transparent_hugepage/hpage_pmd_size') as f:
PAGE_SIZE = resource.getpagesize()
PAGE_SHIFT = int(math.log2(PAGE_SIZE))
PMD_SIZE = int(f.read())
PMD_ORDER = int(math.log2(PMD_SIZE / PAGE_SIZE))
def align_forward(v, a):
return (v + (a - 1)) & ~(a - 1)
def align_offset(v, a):
return v & (a - 1)
def kbnr(kb):
# Convert KB to number of pages.
return (kb << 10) >> PAGE_SHIFT
def nrkb(nr):
# Convert number of pages to KB.
return (nr << PAGE_SHIFT) >> 10
def odkb(order):
# Convert page order to KB.
return (PAGE_SIZE << order) >> 10
def cont_ranges_all(search, index):
# Given a list of arrays, find the ranges for which values are monotonically
# incrementing in all arrays. all arrays in search and index must be the
# same size.
sz = len(search[0])
r = np.full(sz, 2)
d = np.diff(search[0]) == 1
for dd in [np.diff(arr) == 1 for arr in search[1:]]:
d &= dd
r[1:] -= d
r[:-1] -= d
return [np.repeat(arr, r).reshape(-1, 2) for arr in index]
class ArgException(Exception):
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- 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.