Mehdi Akiki

Posts tagged "c"

  • Published on

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

    What a System Call Costs, and Why Some Calls Skip the Kernel

    On a performance core of my laptop a function call costs 0.6 ns, getpid as a system call 81 ns, and clock_gettime 14 ns through the vDSO but 108 ns as a real system call. I measured both kinds of cores, counted the calls with strace and dumped the vDSO.
  • 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 15 of 20 · When the benchmark lies

    Does Code Alignment Change the Speed of the Same Code?

    I placed the same 11-instruction loop at all 64 positions of a cache line, two copies each, and measured them in shuffled order. At one position the loop was 16 to 21 percent slower, in three runs out of three. The same bytes, a different address, a different speed.
  • Published on

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

    When malloc Asks the Kernel for Memory: brk and mmap

    The usual rule says malloc uses brk below 128 KiB and mmap above. I traced seven allocations and a growing Rust Vec with strace: a 129 KiB block came from the heap, a freed 1 MiB block moved the limit, and Vec growth became a chain of mremap calls.
  • Published on

    Investigation · Part 14 of 20 · When the benchmark lies

    Can Environment Variables Change How Fast Your Code Runs?

    A bigger environment moves every variable on the stack, and a 2009 paper showed that small details of the setup can bias benchmarks. I scanned 256 environment sizes three times. The first scan found slow sizes; the shuffled scan showed that they came from the order of the runs.