사용 방법
- 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
- 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
- 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
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
kmallocvsvmallocvsget_free_pages - Debugging kernel OOM or slab corruption
- DMA buffer allocation requirements
- Understanding
/proc/meminfoand 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.
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 oomKernel 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 contextCommon 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 killerskills/kernel/device-drivers—dma_alloc_coherentskills/allocators/custom-allocators— userspace allocator designskills/allocators/numa-programming— NUMA-aware allocationskills/runtimes/sanitizers— KASAN overlap




