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 8a07791fbf)
This commit is contained in:
Tim Murray 2018-10-15 16:26:56 -07:00 committed by android-build-team Robot
parent dbf4b11b11
commit 5e8614d22e
2 changed files with 13 additions and 0 deletions

View file

@ -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;
}

View file

@ -79,6 +79,7 @@ int malloc_info(int __must_be_zero, FILE* __fp) __INTRODUCED_IN(23);
/* mallopt options */
#define M_DECAY_TIME -100
#define M_PURGE -101
int mallopt(int __option, int __value) __INTRODUCED_IN(26);
/*