custom-allocators
Custom allocator skill for memory allocation strategies. Use when implementing…
Memory hierarchy skill for caches, coherence, and locality. Use when explaining cache levels, associativity, false sharing, prefetching, or MESI coherence. Activates on queries about cache hierarchy, L1 L2 L3, false sharing, cache line, prefetch, or cache coherence.
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill memory-hierarchy-and-caches --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/memory-hierarchy-and-cachesContext preview
The summary Claude sees to decide when to auto-load this skill.
Memory hierarchy skill for caches, coherence, and locality. Use when explaining cache levels, associativity, false sharing, prefetching, or MESI coherence. Activates on queries about cache hierarchy, L1 L2 L3, false sharing, cache line, prefetch, or cache coherence.
name: memory-hierarchy-and-caches description: Memory hierarchy skill for caches, coherence, and locality. Use when explaining cache levels, associativity, false sharing, prefetching, or MESI coherence. Activates on queries about cache hierarchy, L1 L2 L3, false sharing, cache line, prefetch, or cache coherence.
Teach CPU memory hierarchy: cache levels, associativity, line size, coherence protocols, false sharing, and prefetch behavior — architectural depth complementing optimization practice in `skills/low-level-programming/cpu-cache-opt`.
Registers ├── L1d / L1i (per core, ~32 KiB, ~4 cycles) ├── L2 (per core, ~256 KiB – 1 MiB) ├── L3 (shared last-level, MiB – tens of MiB) ├── DRAM (hundreds of cycles) └── Storage / NUMA remote (much slower)
Embedded MCUs may have only tightly-coupled memory (no L2/L3).
/* Bad — two atomics on same cache line */
struct {
atomic_int counter_a;
atomic_int counter_b;
} stats;
/* Good — pad to cache line */
struct alignas(64) {
atomic_int counter_a;
char pad[64 - sizeof(atomic_int)];
atomic_int counter_b;
} stats;MESI states: Modified, Exclusive, Shared, Invalid. Writes invalidate other cores' copies of the line — why atomics and locks ping cache lines.
#ifdef __builtin_prefetch
for (int i = 0; i < n; i++) {
__builtin_prefetch(&data[i + 8], 0, 3);
process(data[i]);
}
#endifHardware stride prefetchers detect sequential access; random access misses.
perf stat -e cache-references,cache-misses,L1-dcache-load-misses ./app
/memory-hierarchy-and-caches Diagnose false sharing in this per-thread stats array
| Symptom | Cause | Fix | |---------|-------|-----| | Scaling collapses | False sharing | Line-align per-thread data | | High LLC misses | Working set > cache | Block algorithms; NUMA pin | | DMA incoherence | CPU cache vs device | Flush/invalidate on MCU; dma_sync on Linux | | Prefetch hurt | irregular access | Remove manual prefetch | | Huge struct copies | AoS cold lines | SoA layout — see cpu-cache-opt |
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
Custom allocator skill for memory allocation strategies. Use when implementing…
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology,…
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring…
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers,…
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing,…
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC,…