skills/computer-architecture/memory-hierarchy-and-caches/SKILL.md
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 skillsauth add mohitmishra786/low-level-dev-skills memory-hierarchy-and-cachesInstall 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.
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).
getconf LEVEL1_DCACHE_LINESIZE)/* 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]);
}
#endif
Hardware 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 |
skills/low-level-programming/cpu-cache-opt — practical optimizationskills/computer-architecture/cpu-pipelines-and-hazards — load-use stallsskills/computer-architecture/virtual-memory-paging-and-tlb — TLB missesskills/allocators/numa-programming — remote memory latencyskills/profilers/hardware-counters — perf counter eventsdevelopment
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.