What is malloc doing, anyway?
Not investment advice. Muhabbit scores how much a story may matter, not which way to trade.
GNU libc’s malloc satisfies 1,000 consecutive 16-byte allocations with just two brk syscalls, querying the program break and then expanding the heap by 132 KiB on the first call, with the remaining 999 requests served from that preallocated block. The demonstration highlights how allocator bookkeeping shields programs from syscall overhead, measured at roughly 575 ns for an empty call, by batching memory acquisition from the kernel. It also illustrates process address-space layout, with code, data, bss, heap, libc and stack regions at widely separated addresses; in the example run, the heap break and libc sat about 23.4 TiB apart, roughly 1,530 times the machine’s 15.6 GiB of RAM, though nearly all of that range is unmapped and consumes no physical memory. The distinction between brk, which sets the program break directly, and sbrk, a libc wrapper that adjusts it by a delta, matters for interpreting allocator traces. Next, watch how glibc’s allocator switches to mmap for larger requests and how those mappings are returned via munmap.
Muhabbit's AI wrote this summary in its own words from Hacker News's report. It can get details wrong, so check the source.
Named in this story
malloc, glibc, Linux