K12 — Memory Fragmentation and Compaction: Why Large Memory Allocations Fail

dean
K12 — Memory Fragmentation and Compaction: Why Large Memory Allocations Fail Key Insight: Fragmentation is the chronic disease of memory — it doesn’t hurt normally, but when it flares up, it can be fatal. What Is Memory Fragmentation Memory fragmentation refers to the presence of many “small holes” in memory that make it impossible to... » read more

A09 — Memory Barriers and Cache Coherence: Out-of-Order Access on Multi-Core

dean
A09 — Memory Barriers and Cache Coherence: Out-of-Order Access on Multi-Core Key Insight: In a multi-core CPU, the memory order you observe is not necessarily the true order. Out-of-Order Memory Access on Multi-Core CPUs Modern CPUs reorder memory access instructions for performance optimization. In multi-core programs, this reordering can cause serious problems. 内存访问乱序的例子: 线程 A:... » read more

Writing an OS Kernel from Scratch | Clocksource Framework — How Linux Picks the Best Clock Source Among TSC, HPET, and LAPIC

dean
Writing an OS Kernel from Scratch | Clocksource Framework — How Linux Picks the Best Clock Source Among TSC, HPET, and LAPIC Have you ever encountered this strange phenomenon: On a multi-core machine, calling clock_gettime(CLOCK_MONOTONIC) twice in succession actually returns time that went backwards? Or in a virtual machine, the system time suddenly “jumps” and... » read more

B11 — Modern Computer Memory Layout: Complete Virtual to Physical Address Mapping

dean
B11 — Modern Computer Memory Layout: Complete Virtual to Physical Address Mapping Key Insight: Understanding memory layout is the key to understanding system design. Evolution from Physical to Virtual Addressing Early computers (before the 80286) had no MMU. They directly used physical addresses. Later, segmentation was introduced, then paging, making memory layouts increasingly complex. 内存布局的演进:... » read more

A02 — Internal Structure of the Heap: Arena, Bin, and Chunk

dean
A02 — Internal Structure of the Heap: Arena, Bin, and Chunk Key Insight: The heap managed by malloc is a precision system of bins and chunks. Structure of malloc_chunk malloc 把内存分成 chunk(块)来管理: struct malloc_chunk { INTERNAL_SIZE_T prev_size; // 前一个 chunk 的大小(如果前一个空闲) INTERNAL_SIZE_T size; // 本 chunk 大小 + 标志位 malloc_chunk *fd; // 同 bin 的下一个... » read more