-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cubestore): return physical memory to the system at rest (#1981)
We seem to hit limitations of `malloc` from glibc, which causes physical memory to be retained by the allocator even after calls to `free`. Call `malloc_trim` on allocation-heavy operations to ensure we return freed memory to the system. See the comment in the code for details.
- Loading branch information
1 parent
54e0407
commit 7249a7d
Showing
8 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// Ask the memory allocator to returned the freed memory to the system. | ||
/// This only has effect when compiled for glibc, this is a no-op on other systems. | ||
/// | ||
/// Cubestore produces allocation patterns that hit the limitations of glibc`s malloc, which results | ||
/// in too many physical memory pages being retained in the allocator's arena. This leads to the | ||
/// resident set size growing over the acceptable limits. | ||
/// Probably related to https://sourceware.org/bugzilla/show_bug.cgi?id=11261. | ||
/// | ||
/// Use this function after code that produces considerable amount of memory allocations that | ||
/// **have been already freed**. | ||
#[cfg(target_os = "linux")] // We use `linux` to test for glibc. | ||
pub fn trim_allocs() { | ||
unsafe { | ||
malloc_trim(0); | ||
} | ||
} | ||
|
||
#[cfg(not(target_os = "linux"))] | ||
pub fn trim_memory() {} | ||
|
||
#[cfg(target_os = "linux")] // we assume glibc is linked on linux. | ||
extern "C" { | ||
fn malloc_trim(pad: usize) -> i32; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod malloc; |