share/mk/: Fix includes
[man-pages.git] / man3 / malloc_trim.3
blob23677832b224011d04bb222d5f4e44fbfd280d4d
1 '\" t
2 .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH malloc_trim 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 malloc_trim \- release free memory from the heap
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <malloc.h>
16 .BI "int malloc_trim(size_t "  pad );
17 .fi
18 .SH DESCRIPTION
19 The
20 .BR malloc_trim ()
21 function attempts to release free memory from the heap
22 (by calling
23 .BR sbrk (2)
25 .BR madvise (2)
26 with suitable arguments).
28 The
29 .I pad
30 argument specifies the amount of free space to leave untrimmed
31 at the top of the heap.
32 If this argument is 0, only the minimum amount of memory is maintained
33 at the top of the heap (i.e., one page or less).
34 A nonzero argument can be used to maintain some trailing space
35 at the top of the heap in order to allow future allocations
36 to be made without having to extend the heap with
37 .BR sbrk (2).
38 .SH RETURN VALUE
39 The
40 .BR malloc_trim ()
41 function returns 1 if memory was actually released back to the system,
42 or 0 if it was not possible to release any memory.
43 .SH ERRORS
44 No errors are defined.
45 .SH ATTRIBUTES
46 For an explanation of the terms used in this section, see
47 .BR attributes (7).
48 .TS
49 allbox;
50 lbx lb lb
51 l l l.
52 Interface       Attribute       Value
54 .na
55 .nh
56 .BR malloc_trim ()
57 T}      Thread safety   MT-Safe
58 .TE
59 .SH STANDARDS
60 GNU.
61 .SH VERSIONS
62 glibc 2.0.
63 .SH NOTES
64 Only the main heap (using
65 .BR sbrk (2))
66 honors the
67 .I pad
68 argument; thread heaps do not.
70 Since glibc 2.8 this function frees memory in all arenas and in all
71 chunks with whole free pages.
72 .\" See commit 68631c8eb92ff38d9da1ae34f6aa048539b199cc
73 .\" (dated 2007-12-16) which adds iteration over all
74 .\" arenas and frees all pages in chunks which are free.
76 Before glibc 2.8 this function only freed memory at the
77 top of the heap in the main arena.
78 .SH SEE ALSO
79 .BR sbrk (2),
80 .BR malloc (3),
81 .BR mallopt (3)