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