rippled
Loading...
Searching...
No Matches
include
xrpl
basics
MallocTrim.h
1
#pragma once
2
3
#include <xrpl/beast/utility/Journal.h>
4
5
#include <
chrono
>
6
#include <
cstdint
>
7
#include <
string_view
>
8
9
namespace
xrpl
{
10
11
// cSpell:ignore ptmalloc
12
13
// -----------------------------------------------------------------------------
14
// Allocator interaction note:
15
// - This facility invokes glibc's malloc_trim(0) on Linux/glibc to request that
16
// ptmalloc return free heap pages to the OS.
17
// - If an alternative allocator (e.g. jemalloc or tcmalloc) is linked or
18
// preloaded (LD_PRELOAD), calling glibc's malloc_trim typically has no effect
19
// on the *active* heap. The call is harmless but may not reclaim memory
20
// because those allocators manage their own arenas.
21
// - Only glibc sbrk/arena space is eligible for trimming; large mmap-backed
22
// allocations are usually returned to the OS on free regardless of trimming.
23
// - Call at known reclamation points (e.g., after cache sweeps / online delete)
24
// and consider rate limiting to avoid churn.
25
// -----------------------------------------------------------------------------
26
27
struct
MallocTrimReport
28
{
29
bool
supported
{
false
};
30
int
trimResult
{-1};
31
std::int64_t
rssBeforeKB
{-1};
32
std::int64_t
rssAfterKB
{-1};
33
std::chrono::microseconds
durationUs
{-1};
34
std::int64_t
minfltDelta
{-1};
35
std::int64_t
majfltDelta
{-1};
36
37
[[nodiscard]]
std::int64_t
38
deltaKB
() const noexcept
39
{
40
if
(
rssBeforeKB
< 0 ||
rssAfterKB
< 0)
41
return
0;
42
return
rssAfterKB
-
rssBeforeKB
;
43
}
44
};
45
70
MallocTrimReport
71
mallocTrim
(
std::string_view
tag,
beast::Journal
journal);
72
73
}
// namespace xrpl
std::string_view
chrono
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:40
cstdint
std::chrono::microseconds
std::int64_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::mallocTrim
MallocTrimReport mallocTrim(std::string_view tag, beast::Journal journal)
Attempt to return freed memory to the operating system.
Definition
libxrpl/basics/MallocTrim.cpp:71
string_view
xrpl::MallocTrimReport
Definition
MallocTrim.h:28
xrpl::MallocTrimReport::supported
bool supported
Definition
MallocTrim.h:29
xrpl::MallocTrimReport::majfltDelta
std::int64_t majfltDelta
Definition
MallocTrim.h:35
xrpl::MallocTrimReport::minfltDelta
std::int64_t minfltDelta
Definition
MallocTrim.h:34
xrpl::MallocTrimReport::durationUs
std::chrono::microseconds durationUs
Definition
MallocTrim.h:33
xrpl::MallocTrimReport::trimResult
int trimResult
Definition
MallocTrim.h:30
xrpl::MallocTrimReport::deltaKB
std::int64_t deltaKB() const noexcept
Definition
MallocTrim.h:38
xrpl::MallocTrimReport::rssAfterKB
std::int64_t rssAfterKB
Definition
MallocTrim.h:32
xrpl::MallocTrimReport::rssBeforeKB
std::int64_t rssBeforeKB
Definition
MallocTrim.h:31
Generated by
1.9.8