]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/malloc_trim.3
dist.mk, All pages: .TH: Generate date at 'make dist'
[thirdparty/man-pages.git] / man3 / malloc_trim.3
CommitLineData
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 7malloc_trim \- release free memory from the heap
0f03517a
AC
8.SH LIBRARY
9Standard 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
18The
19.BR malloc_trim ()
0deebbe5 20function attempts to release free memory from the heap
a15b0e60
MK
21(by calling
22.BR sbrk (2)
0deebbe5
CD
23or
24.BR madvise (2)
25with suitable arguments).
847e0d88 26.PP
a15b0e60
MK
27The
28.I pad
29argument specifies the amount of free space to leave untrimmed
30at the top of the heap.
31If this argument is 0, only the minimum amount of memory is maintained
32at the top of the heap (i.e., one page or less).
33A nonzero argument can be used to maintain some trailing space
34at the top of the heap in order to allow future allocations
35to be made without having to extend the heap with
36.BR sbrk (2).
37.SH RETURN VALUE
38The
39.BR malloc_trim ()
40function returns 1 if memory was actually released back to the system,
41or 0 if it was not possible to release any memory.
42.SH ERRORS
43No errors are defined.
44.\" .SH VERSIONS
45.\" Available already in glibc 2.0, possibly earlier
0cc0b5e4
ZL
46.SH ATTRIBUTES
47For 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
52allbox;
c466875e 53lbx lb lb
0cc0b5e4
ZL
54l l l.
55Interface Attribute Value
56T{
57.BR malloc_trim ()
58T} Thread safety MT-Safe
59.TE
c466875e
MK
60.hy
61.ad
847e0d88 62.sp 1
3113c7f3 63.SH STANDARDS
a15b0e60
MK
64This function is a GNU extension.
65.SH NOTES
0deebbe5 66Only the main heap (using
09358e73
MK
67.BR sbrk (2))
68honors the
69.I pad
70argument; thread heaps do not.
0deebbe5
CD
71.PP
72Since glibc 2.8 this function frees memory in all arenas and in all
73chunks 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
78Before glibc 2.8 this function only freed memory at the
79top 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)