Author

Writing an OS Kernel from Scratch – Part 6: First Look at Multitasking — From Single-Core Loops to Process Switching

dean
Writing an OS Kernel from Scratch – Part 6: First Look at Multitasking — From Single-Core Loops to Process Switching “A kernel that can only do one thing? That’s a bare-metal program. A real OS must be able to ‘simultaneously’ do multiple things!” In the previous five posts, we completed kernel boot, entering protected mode,... » read more

Writing an OS Kernel from Scratch – Part 15: Slab Allocator — Efficiently Managing Kernel Small Objects

dean
Writing an OS Kernel from Scratch – Part 15: Slab Allocator — Efficiently Managing Kernel Small Objects “The Buddy system is great at allocating large memory blocks, but what about the kernel’s frequent 32-byte, 128-byte small object allocations? Today, we implement the Slab allocator, making kernel memory allocation lightning fast!” In the previous post, we... » read more

A05 — Use-After-Free: The Problem of Accessing Freed Memory

dean
A05 — Use-After-Free: The Problem of Accessing Freed Memory Key insight: Continuing to use a freed memory block is like continuing to build a house on land you’ve already sold — sooner or later someone will come to tear it down. What is Use-After-Free Use-After-Free (UAF) refers to accessing memory that has already been freed... » read more

Long Article 104: Memory Management – Virtual Part I: In-Depth Page Table Operations and Virtual Memory Areas (VMA)

dean
Long Article 104: Memory Management – Virtual Part I: In-Depth Page Table Operations and Virtual Memory Areas (VMA) Analysis “Virtual memory is the cornerstone of modern operating systems, and VMA is the ‘map’ of the process address space. This article dives deep into x86 page table structures and VMA design principles, comparing Linux implementation details... » read more

A01 — The Internals of malloc: How brk and mmap Work Together

dean
A01 — The Internals of malloc: How brk and mmap Work Together Key Insight: Every block of memory you allocate with malloc is backed by the system making allocation decisions on your behalf. malloc is Not a System Call malloc is a glibc (ptmalloc) library function, not a system call. Two paths for malloc: 1.... » read more

Long Article 106: Memory Management — Advanced: Deep Dive into Copy-on-Write, Swapping, and NUMA Optimization

dean
# Long Article 106: Memory Management — Advanced: Deep Dive into Copy-on-Write, Swapping, and NUMA Optimization “When physical memory is insufficient, how does the OS handle it gracefully? This article covers CoW, Swapping, and NUMA optimization.” Introduction Three advanced features for memory pressure: CoW: Share pages on fork, copy only on write Swapping: Move inactive... » read more

Writing an OS Kernel from Scratch | VFS — The Virtual File System: How Linux’s “Everything is a File” Works

dean
Writing an OS Kernel from Scratch | VFS — The Virtual File System: How Linux’s “Everything is a File” Works You use cat /proc/cpuinfo, ls /dev/null, echo "hello" > /tmp/a.txt — three different operations, all using the same open/read/write system calls. Why? The answer is VFS (Virtual File System Switch) — an abstraction layer that... » read more

K10 — NUMA Systems: Memory Nodes and Local Allocation

dean
K10 — NUMA Systems: Memory Nodes and Local Allocation Key Insight: On multi-socket servers, “local memory” and “remote memory” access latency can differ by up to 3x — NUMA is the source of this difference. The Concept of NUMA NUMA (Non-Uniform Memory Access) means each CPU core has local memory. Local access is fast, remote... » read more

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