]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/malloc_trim.3
ctime.3: wfix
[thirdparty/man-pages.git] / man3 / malloc_trim.3
CommitLineData
a15b0e60
MK
1'\" t
2.\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
a15b0e60
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
a15b0e60 25.\"
2e3023c4 26.TH MALLOC_TRIM 3 2019-05-09 "Linux" "Linux Programmer's Manual"
a15b0e60 27.SH NAME
0deebbe5 28malloc_trim \- release free memory from the heap
a15b0e60
MK
29.SH SYNOPSIS
30.B #include <malloc.h>
dbfe9c70 31.PP
7b7fbe78 32.BI "int malloc_trim(size_t " pad );
a15b0e60
MK
33.SH DESCRIPTION
34The
35.BR malloc_trim ()
0deebbe5 36function attempts to release free memory from the heap
a15b0e60
MK
37(by calling
38.BR sbrk (2)
0deebbe5
CD
39or
40.BR madvise (2)
41with suitable arguments).
847e0d88 42.PP
a15b0e60
MK
43The
44.I pad
45argument specifies the amount of free space to leave untrimmed
46at the top of the heap.
47If this argument is 0, only the minimum amount of memory is maintained
48at the top of the heap (i.e., one page or less).
49A nonzero argument can be used to maintain some trailing space
50at the top of the heap in order to allow future allocations
51to be made without having to extend the heap with
52.BR sbrk (2).
53.SH RETURN VALUE
54The
55.BR malloc_trim ()
56function returns 1 if memory was actually released back to the system,
57or 0 if it was not possible to release any memory.
58.SH ERRORS
59No errors are defined.
60.\" .SH VERSIONS
61.\" Available already in glibc 2.0, possibly earlier
0cc0b5e4
ZL
62.SH ATTRIBUTES
63For an explanation of the terms used in this section, see
64.BR attributes (7).
65.TS
66allbox;
67lb lb lb
68l l l.
69Interface Attribute Value
70T{
71.BR malloc_trim ()
72T} Thread safety MT-Safe
73.TE
847e0d88 74.sp 1
a15b0e60
MK
75.SH CONFORMING TO
76This function is a GNU extension.
77.SH NOTES
78This function is automatically called by
79.BR free (3)
80in certain circumstances; see the discussion of
81.B M_TOP_PAD
82and
83.B M_TRIM_THRESHOLD
84in
85.BR mallopt (3).
847e0d88 86.PP
0deebbe5 87Only the main heap (using
09358e73
MK
88.BR sbrk (2))
89honors the
90.I pad
91argument; thread heaps do not.
0deebbe5
CD
92.PP
93Since glibc 2.8 this function frees memory in all arenas and in all
94chunks with whole free pages.
95.\" See commit 68631c8eb92ff38d9da1ae34f6aa048539b199cc
96.\" (dated 2007-12-16) which adds iteration over all
97.\" arenas and frees all pages in chunks which are free.
847e0d88 98.PP
0deebbe5
CD
99Before glibc 2.8 this function only freed memory at the
100top of the heap in the main arena.
a15b0e60
MK
101.SH SEE ALSO
102.BR sbrk (2),
103.BR malloc (3),
104.BR mallopt (3)