1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Allocator maintenance. glibc parks freed pages on its per-arena free lists
//! rather than returning them, so a process that peaked stays resident at that
//! peak long after the peak's memory is free (#61, #245). `malloc_trim` asks
//! for the top of each arena back.
/// Ask glibc to return freed pages to the OS. Call only from a quiescent
/// point: glibc walks and locks every arena in turn, so a caller mid-workload
/// pays for the walk and stalls every concurrently allocating thread.
///
/// The `released` flag is glibc's own report of whether anything came back; it
/// is logged rather than acted on, because "nothing to release" is the normal
/// steady-state answer, not a failure.
// `target_env = "gnu"` and not bare `target_os = "linux"`: `malloc_trim` is a
// glibc extension that the `libc` crate declares only for the gnu environment,
// so a musl target would not even compile against the branch below.
/// No-op off glibc - musl, the macOS allocator and the Windows CRT have no
/// equivalent entry point, and none of them retain pages the way glibc does.