Summary: | glibc fails to free memory | ||
---|---|---|---|
Product: | glibc | Reporter: | Hi-Angel <hi-angel> |
Component: | malloc | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED NOTABUG | ||
Severity: | normal | CC: | carlos |
Priority: | P2 | ||
Version: | 2.32 | ||
Target Milestone: | --- | ||
See Also: | https://sourceware.org/bugzilla/show_bug.cgi?id=14581 | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
Hi-Angel
2020-12-21 22:58:35 UTC
To add to the list of affected apps: Ruby¹, glib². And yeah, calling `malloc_trim(0);` next to each `free()` resolves the problem, but it is merely a workaround. Because it is glibc-specific function and one can't reasonably expect every developer of each existing app to be able to write code for each existing libc-implementation. Glibc `free()` should call `malloc_trime()` themselves whenever they deem appropriate. 1: https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html#investigating-fragmentation-at-the-memory-allocator-level 2: https://gitlab.gnome.org/GNOME/glib/-/issues/2057 (In reply to Hi-Angel from comment #1) > To add to the list of affected apps: Ruby¹, glib². > > And yeah, calling `malloc_trim(0);` next to each `free()` resolves the > problem, but it is merely a workaround. Because it is glibc-specific > function and one can't reasonably expect every developer of each existing > app to be able to write code for each existing libc-implementation. Glibc > `free()` should call `malloc_trime()` themselves whenever they deem > appropriate. > > 1: > https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory- > bloat.html#investigating-fragmentation-at-the-memory-allocator-level > 2: https://gitlab.gnome.org/GNOME/glib/-/issues/2057 The ruby case is a known issue with aligned allocations. https://sourceware.org/bugzilla/show_bug.cgi?id=14581 We have a patch to improve the ruby case significantly, but it needs more work. The gnome case is unrelated and is just about freeing back unused pages under memory pressure which is exactly what malloc_trim() will do when called. This particular issue is not a bug, the allocator is under no requirement to free back the 50MiB to the OS if it believes that the memory will be used again and that performance is improved by caching it in userspace. |