K09 — Memory Leaks: Why malloc Without free Causes Unrecoverable Memory

dean
K09 — Memory Leaks: Why malloc Without free Causes Unrecoverable Memory Key Insight: After a program ends, the system reclaims its memory — but while running, leaked memory is truly leaked. What Is a Memory Leak A memory leak occurs when a program dynamically allocates memory but fails to release it, making that memory permanently... » read more

A10 — Memory Analysis Tools: malloc_stats, Valgrind Massif, pmap

dean
A10 — Memory Analysis Tools: malloc_stats, Valgrind Massif, pmap Key Insight: The first step to optimizing memory is knowing where it is being used. malloc_stats: glibc Allocation Statistics malloc_stats() 输出所有 arena 的统计信息: #include <malloc.h> malloc_stats(); 输出示例: Arena 0: system bytes = 1048576 memory bytes = 1048576 96 malloc-chunks in use (12345 bytes) Arena 1: system... » read more

Writing an OS Kernel from Scratch — Part 1: More Than Just “Hello World”

dean
从零开始写一个操作系统kernel-Part 1: 不只是”Hello World” 🌱 从零开始写一个操作系统kernel-Part 1: 不只是”Hello World”! 你是否曾好奇: ✅ Windows, Linux, macOS 这些操作系统是怎么”从无到有”启动的? ✅ kernel到底长什么样? 能不能自己写一个? ✅ 为什么kernel代码不能用 printf , 却能直接显示文字? 🛠️ 第一步: 准备开发环境 我们要构建一个 32位 x86 kernel , 通过 GRUB 引导 , 并在 QEMU 中运行 — 这样既安全又快捷! 你需要安装: ⚠️ 为了规范编译, 推荐使用 交叉编译器 i686-elf-gcc (避免宿主系统库干扰) . 教程可Reference: OSDev Wiki – GCC Cross-Compiler 🚀... » read more

B04 — From Real Mode to Protected Mode: GDT and CR0 Setup

dean
B04 — From Real Mode to Protected Mode: GDT and CR0 Setup Key Insight: Protected mode doesn’t “protect” memory. It allows the CPU to manage more complex memory access rules. Limitations of Real Mode After reset, the CPU defaults to Real Mode, the operating mode from the 8086 era. Real Mode has two severe limitations:... » read more

B08 — Memory Layout of Kernel Space and User Space: vmalloc vs kmalloc

dean
B08 — Memory Layout of Kernel Space and User Space: vmalloc vs kmalloc Key Insight: The division of virtual address space is one of the most important OS design decisions. x86-64 Virtual Address Space Layout Modern Linux uses a 48-bit virtual address space. User space and kernel space each have separate regions: x86-64 虚拟地址空间布局: 0x0000000000000000... » read more

[Writing an OS Kernel from Scratch] 337 – DRAM Training: From Principles to Debugging

dean
title: [Writing an OS Kernel from Scratch] 337 – DRAM Training: From Principles to Debugging category: os tag: [dram, ddr, embedded, signal-integrity] source: https://github.com/golang12306/os-kernel-from-scratch [Writing an OS Kernel from Scratch] 337 – DRAM Training: From Principles to Debugging 1. What Is DRAM Training? DRAM Training is the process where the DDR controller automatically adjusts signal... » read more

H01 — How Memory Modules Plug Into the Motherboard: DIMM Structure and Socket Design

dean
H01 — How Memory Modules Plug Into the Motherboard: DIMM Structure and Socket Design Key Insight: Behind every visible interface lie countless electrical conventions. DIMM Full Name and Basic Concepts DIMM = Dual Inline Memory Module. DIMM vs SIMM: SIMM(Single Inline Memory Module): - 单面引脚(只能接触一侧的触点) - 72-pin 或 30-pin(早期) - 只能提供 32-bit 或 16-bit 数据宽度... » read more

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