mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
54 lines
1.6 KiB
Diff
54 lines
1.6 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Tim Murray <timmurray@google.com>
|
||
|
Date: Mon, 15 Oct 2018 16:26:56 -0700
|
||
|
Subject: [PATCH] malloc: add M_PURGE mallopt flag
|
||
|
|
||
|
Add a new mallopt flag that purges any pending decaying pages.
|
||
|
|
||
|
Test: boots and works
|
||
|
bug 117795621
|
||
|
|
||
|
Merged-in: Ib250ae2b705b6a368c1efb801d6a7be54e075acb
|
||
|
Change-Id: Ib250ae2b705b6a368c1efb801d6a7be54e075acb
|
||
|
(cherry picked from commit 8a07791fbff0dd014ce5da8d88969d09cd3dcf0b)
|
||
|
---
|
||
|
libc/bionic/jemalloc_wrapper.cpp | 12 ++++++++++++
|
||
|
libc/include/malloc.h | 1 +
|
||
|
2 files changed, 13 insertions(+)
|
||
|
|
||
|
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
|
||
|
index 266b9660c..b4678d008 100644
|
||
|
--- a/libc/bionic/jemalloc_wrapper.cpp
|
||
|
+++ b/libc/bionic/jemalloc_wrapper.cpp
|
||
|
@@ -79,6 +79,18 @@ int je_mallopt(int param, int value) {
|
||
|
}
|
||
|
}
|
||
|
return 1;
|
||
|
+ } else if (param == M_PURGE) {
|
||
|
+ unsigned narenas;
|
||
|
+ size_t sz = sizeof(unsigned);
|
||
|
+ if (je_mallctl("arenas.narenas", &narenas, &sz, nullptr, 0) != 0) {
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+ char buffer[100];
|
||
|
+ snprintf(buffer, sizeof(buffer), "arena.%u.purge", narenas);
|
||
|
+ if (je_mallctl(buffer, nullptr, nullptr, nullptr, 0) != 0) {
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+ return 1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
|
||
|
index f0cdf82f3..50ae7d6a7 100644
|
||
|
--- a/libc/include/malloc.h
|
||
|
+++ b/libc/include/malloc.h
|
||
|
@@ -72,6 +72,7 @@ extern int malloc_info(int, FILE *);
|
||
|
|
||
|
/* mallopt options */
|
||
|
#define M_DECAY_TIME -100
|
||
|
+#define M_PURGE -101
|
||
|
|
||
|
int mallopt(int, int) __INTRODUCED_IN(26);
|
||
|
|