Mehdi Akiki

Posts tagged "memory management"

  • Published on

    Investigation · Part 18 of 20 · When the benchmark lies

    The Benchmark Measured the Allocator

    A small formatting function took 52 ns per call with a new String and 38 ns with a reused buffer. A 256 KiB buffer cost nothing extra after the first call. And the contention that I saw with four threads came from my own allocation counter, not from malloc.
  • Published on

    Investigation · Part 18 of 20 · From source to a running process

    How a Stack Overflow Is Detected: Guard Pages and Signals

    A C program that overflows its stack dies without a word, a Rust program prints a message. I overflowed both on purpose, in the main thread and in a new thread, and followed the limit, the guard page, the SIGSEGV, the alternate signal stack and the abort.
  • Published on

    Investigation · Part 17 of 20 · What survives a crash

    Writing Through mmap: Who Decides When Data Reaches the Disk

    I changed 64 MiB of a file without one write call, through a shared memory mapping. The pages became dirty like in the first part, kill -9 kept them, msync or fsync made them durable, and a truncated file killed my program with SIGBUS. The kernel decides the rest.
  • Published on

    Investigation · Part 16 of 20 · From source to a running process

    Why Freeing Memory Does Not Shrink Your Process

    I freed 999,000 of one million small blocks and the process did not become one kilobyte smaller. malloc_stats, strace and malloc_trim show why: the heap can only shrink from its top, glibc keeps the free pages, and threads multiply the arenas. Rust behaves the same.
  • Published on

    Investigation · Part 16 of 20 · When the benchmark lies

    When the Working Set No Longer Fits in Cache

    One step of i = a[i] costs 1.4 ns when the array fits in L1 and 114 ns when it is 128 MiB, the same instruction. I measured the steps on a P-core and an E-core, a sequential read of the same arrays, and why I could not show the effect of huge pages.