malloc_trim.3: Update trimming information

Since glibc 2.8, commit 68631c8eb92, the malloc_trim function has
iterated over all arenas and free'd back to the OS all page runs
that were free.  This allows an application to call malloc_trim to
consolidate fragmented chunks and free back any pages it can to
potentially reduce RSS usage.

This correctness of the man page was recently brought to light by
an article [1] where Ruby developers discovered that malloc_trim
did not behave as the man page indicated.

This change makes it clear that the intent of malloc_trim is to
trim all space that is no longer needed, and any restrictions are
implementation details. In the notes we highlight the change in
behaviour for post glibc 2.8 and pre glibc 2.8.

[1] https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html#a-magic-trick-trimming

Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Carlos O'Donell 2019-03-28 14:01:28 -04:00 committed by Michael Kerrisk
parent 492a6a0d4a
commit 0deebbe524
1 changed files with 16 additions and 8 deletions

View File

@ -25,7 +25,7 @@
.\"
.TH MALLOC_TRIM 3 2017-09-15 "Linux" "Linux Programmer's Manual"
.SH NAME
malloc_trim \- release free memory from the top of the heap
malloc_trim \- release free memory from the heap
.SH SYNOPSIS
.B #include <malloc.h>
.PP
@ -33,10 +33,12 @@ malloc_trim \- release free memory from the top of the heap
.SH DESCRIPTION
The
.BR malloc_trim ()
function attempts to release free memory at the top of the heap
function attempts to release free memory from the heap
(by calling
.BR sbrk (2)
with a suitable argument).
or
.BR madvise (2)
with suitable arguments).
.PP
The
.I pad
@ -82,12 +84,18 @@ and
in
.BR mallopt (3).
.PP
This function cannot release free memory located at places
other than the top of the heap.
Only the main heap (using
.BR sbrk (2)
) honors the pad argument; thread heaps do not.
.PP
This function releases only memory in the main arena.
.\" malloc/malloc.c::mTRIm():
.\" return result | (av == &main_arena ? sYSTRIm (pad, av) : 0);
Since glibc 2.8 this function frees memory in all arenas and in all
chunks with whole free pages.
.\" See commit 68631c8eb92ff38d9da1ae34f6aa048539b199cc
.\" (dated 2007-12-16) which adds iteration over all
.\" arenas and frees all pages in chunks which are free.
.PP
Before glibc 2.8 this function only freed memory at the
top of the heap in the main arena.
.SH SEE ALSO
.BR sbrk (2),
.BR malloc (3),