mohitmishra786/low-level-dev-skills

kernel-memory-management

Kernel memory management skill for Linux mm subsystem.

ソースを見る

使い方

  1. インストールコマンドをコピーし、自分の環境へ導入する前にソースを確認します。
  2. 必要なツール、認証情報、対応環境を原文で確認します。
  3. 入力と成果物を指定し、出力を資料と照合します。
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill kernel-memory-management

開始前の確認

  • 導入にはモデル契約、API枠、ファイルへのアクセス許可は含まれません。
  • スター数や導入数は活動の指標であり、独立した品質・安全性試験ではありません。
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Kernel Memory Management

Purpose

Guide agents through Linux kernel memory allocation: physical page allocator (buddy), SLUB kmalloc caches, vmalloc virtual mappings, zones (DMA/Normal), and safe allocation patterns in drivers — extending skills/kernel/kernel-internals.

When to Use

  • Choosing kmalloc vs vmalloc vs get_free_pages
  • Debugging kernel OOM or slab corruption
  • DMA buffer allocation requirements
  • Understanding /proc/meminfo and slab stats

Workflow

1. Allocator decision tree

Need physically contiguous memory for DMA?
├── Yes → dma_alloc_coherent() or CMA pool
└── No
    ├── Size ≤ ~128K (arch-dependent) → kmalloc / kzalloc
    ├── Large or non-contiguous OK → vmalloc / vzalloc
    └── Whole pages → alloc_pages() / __get_free_pages()

2. kmalloc and SLUB

SLUB is the default general-purpose kmalloc backend (per kernel memory allocation guide); the legacy SLAB allocator was removed in Linux 6.12.

c
void *buf = kmalloc(size, GFP_KERNEL);
if (!buf)
    return -ENOMEM;
/* ... */
kfree(buf);
GFP flagContext
GFP_KERNELProcess context, may sleep
GFP_ATOMICIRQ / holding spinlock — smaller pools
GFP_DMADMA zone (legacy 32-bit devices)

Check /proc/slabinfo and cat /sys/kernel/slab/*/object_size.

3. vmalloc

c
void *v = vmalloc(size);  /* virtually contiguous, physically scattered */
vfree(v);

Use for large buffers where contiguous physical pages are unnecessary. Do not use for DMA without dma_map_*.

4. Buddy page allocator

c
struct page *page = alloc_pages(GFP_KERNEL, order);
void *addr = page_address(page);
__free_pages(page, order);

order n allocates 2^n pages. Zone selection: ZONE_DMA, ZONE_NORMAL, ZONE_MOVABLE (see include/linux/mmzone.h).

5. NUMA basics

On NUMA systems, kmalloc prefers local node; use alloc_pages_node() or mbind policies for HPC paths — see skills/allocators/numa-programming.

6. Debugging

bash
cat /proc/meminfo
cat /proc/slabinfo
dmesg | grep -i oom

Kernel config: CONFIG_SLUB_DEBUG, CONFIG_KASAN for use-after-free.

7. Agent usage

/kernel-memory-management Choose allocator for 2 MiB driver ring buffer in process context

Common Problems

SymptomCauseFix
kmalloc fails largeExceeds kmalloc limitUse vmalloc or pages
DMA buffer wrongUsed vmalloc for HW DMAdma_alloc_coherent
OOM killerUnbounded cache growthLimit pools; use shrinker
Slab corruptionUse-after-freeKASAN; audit kfree pairing
GFP_KERNEL in IRQSleeping allocator in atomicGFP_ATOMIC

Related Skills

  • skills/kernel/kernel-internals — page cache, OOM killer
  • skills/kernel/device-drivers — dma_alloc_coherent
  • skills/allocators/custom-allocators — userspace allocator design
  • skills/allocators/numa-programming — NUMA-aware allocation
  • skills/runtimes/sanitizers — KASAN overlap

タスクに関連する項目

同じリポジトリから

関連する Skills

すべての Skills
mohitmishra786
コミュニティ

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

導入数
2
GitHub Stars
267
更新日
6月27日
mohitmishra786
コミュニティ

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

導入数
2
GitHub Stars
267
更新日
6月27日
mohitmishra786
コミュニティ

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

導入数
2
GitHub Stars
267
更新日
6月27日
mohitmishra786
コミュニティ

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

導入数
2
GitHub Stars
267
更新日
6月27日