When you try to extend your memory allocation with realloc(), does Linux arrange a part of memory, copy and destroy old one ? If so, the maximum size of realloc() is limited to less than half of total non-kernel memory.
Am I right on that, or what algorithm is currently applying ?
The glibc realloc implementation makes use of the kernel’s mremap interface to extend or relocate the allocated region in the process’s virtual address space without making an extra copy in physical memory. This behavior kicks in when glibc considers the allocation “large”, which was anything over 128K last time I checked. For smaller allocations it’ll make a copy.
mremap could fail if the process’s virtual memory map doesn’t have enough contiguous space available for the new allocation either at its current address or in any other unused region, but it doesn’t need enough space to hold the old and new allocations at the same time.