`free` fails to reclaim memory

tomas@tuxteam.de tomas@tuxteam.de
Sun Dec 13 11:57:24 GMT 2020


On Sun, Dec 13, 2020 at 02:41:06PM +0300, Konstantin Kharlamov wrote:
> Hello, while researching Emacs "leaking memory"¹, we may have actually stumbled upon glibc problem: glibc may not return freed memory to the OS, and by "memory" I mean here not a few kilobytes or megabytes for the sake of cache, but megabytes or even gigabytes. Having researched for a bit, I got the following testcase:

See also [1], especially glibc.malloc.mmap_threshold (default: start
with 128 KB and then adjust dynamically), which decides when to use
mmap (which can be returned to the OS on free) for a chunk, and
glibc.malloc.trim_threshold, which decides the minimum size of frees
(from sbrk) to return to the os (which is set by default at 128 KB)

So libc's malloc seems to try to do things, perhaps the chunks you
are using in your test program are too small to trigger what you
are expecting.

Note that if you mix malloc and free, the freed memory is reused,
so your experiment doesn't necessarily explain the "leaking
memory" thing.

Cheers

[1] https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-Tunables.html
 - t
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://sourceware.org/pipermail/libc-help/attachments/20201213/207076c2/attachment-0001.sig>


More information about the Libc-help mailing list