/kernel-memory-management
Kernel memory management skill for Linux mm subsystem. Use when using kmalloc, vmalloc, page allocator, SLUB, or debugging OOM and memory zones. Activates on queries about buddy allocator, kmalloc sizes, vmalloc vs kmalloc, SLUB, memory zones, or kernel OOM.
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill kernel-memory-management --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/kernel-memory-management
Context preview
The summary Claude sees to decide when to auto-load this skill.
Kernel memory management skill for Linux mm subsystem. Use when using kmalloc, vmalloc, page allocator, SLUB, or debugging OOM and memory zones. Activates on queries about buddy allocator, kmalloc sizes, vmalloc vs kmalloc, SLUB, memory zones, or kernel OOM.
SKILL.md
kernel-memory-management.SKILL.mdname: kernel-memory-management
description: Kernel memory management skill for Linux mm subsystem. Use when using kmalloc, vmalloc, page allocator, SLUB, or debugging OOM and memory zones. Activates on queries about buddy allocator, kmalloc sizes, vmalloc vs kmalloc, SLUB, memory zones, or kernel OOM.
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](https://docs.kernel.org/core-api/memory-allocation.html)); the legacy SLAB allocator was removed in Linux 6.12.
void *buf = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
/* ... */
kfree(buf);| GFP flag | Context | |----------|---------| | `GFP_KERNEL` | Process context, may sleep | | `GFP_ATOMIC` | IRQ / holding spinlock — smaller pools | | `GFP_DMA` | DMA zone (legacy 32-bit devices) |
Check `/proc/slabinfo` and `cat /sys/kernel/slab/*/object_size`.
3. vmalloc
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
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
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
| Symptom | Cause | Fix | |---------|-------|-----| | `kmalloc` fails large | Exceeds kmalloc limit | Use `vmalloc` or pages | | DMA buffer wrong | Used `vmalloc` for HW DMA | `dma_alloc_coherent` | | OOM killer | Unbounded cache growth | Limit pools; use shrinker | | Slab corruption | Use-after-free | KASAN; audit `kfree` pairing | | `GFP_KERNEL` in IRQ | Sleeping allocator in atomic | `GFP_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
Read more
name: kernel-memory-management description: Kernel memory management skill for Linux mm subsystem. Use when using kmalloc, vmalloc, page allocator, SLUB, or debugging OOM and memory zones. Activates on queries about buddy allocator, kmalloc sizes, vmalloc vs kmalloc, SLUB, memory zones, or kernel OOM.
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](https://docs.kernel.org/core-api/memory-allocation.html)); the legacy SLAB allocator was removed in Linux 6.12.
void *buf = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
/* ... */
kfree(buf);| GFP flag | Context | |----------|---------| | `GFP_KERNEL` | Process context, may sleep | | `GFP_ATOMIC` | IRQ / holding spinlock — smaller pools | | `GFP_DMA` | DMA zone (legacy 32-bit devices) |
Check `/proc/slabinfo` and `cat /sys/kernel/slab/*/object_size`.
3. vmalloc
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
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
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
| Symptom | Cause | Fix | |---------|-------|-----| | `kmalloc` fails large | Exceeds kmalloc limit | Use `vmalloc` or pages | | DMA buffer wrong | Used `vmalloc` for HW DMA | `dma_alloc_coherent` | | OOM killer | Unbounded cache growth | Limit pools; use shrinker | | Slab corruption | Use-after-free | KASAN; audit `kfree` pairing | | `GFP_KERNEL` in IRQ | Sleeping allocator in atomic | `GFP_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
A curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /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,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

