skills/kernel-dev/kernel-memory-management/SKILL.md
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 skillsauth add mohitmishra786/low-level-dev-skills kernel-memory-managementInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
kmalloc vs vmalloc vs get_free_pages/proc/meminfo and slab statsNeed 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()
SLUB is the default general-purpose kmalloc backend (per kernel memory allocation guide); 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.
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_*.
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).
On NUMA systems, kmalloc prefers local node; use alloc_pages_node() or mbind policies for HPC paths — see skills/allocators/numa-programming.
cat /proc/meminfo
cat /proc/slabinfo
dmesg | grep -i oom
Kernel config: CONFIG_SLUB_DEBUG, CONFIG_KASAN for use-after-free.
/kernel-memory-management Choose allocator for 2 MiB driver ring buffer in process context
| 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 |
skills/kernel/kernel-internals — page cache, OOM killerskills/kernel/device-drivers — dma_alloc_coherentskills/allocators/custom-allocators — userspace allocator designskills/allocators/numa-programming — NUMA-aware allocationskills/runtimes/sanitizers — KASAN overlapdevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.