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