From 571aa6fb494621acb178c42a7a70f64e7c6f6e7d Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Tue, 28 Feb 2023 12:51:03 -0800 Subject: [PATCH] Switch to purge all unused memory to kernel. The new option purges all memory, but could take some extra time. However, there isn't much memory in the zygote so this should not incur much extra time during the purge operation. Bug: 243851006 Test: Verified that the zygote and zygote 64 on oriole reduce the Test: RSS by about 300K on average. Change-Id: Ic5eac43813163efb2c049ed280c2f15a89c3fa18 --- core/jni/com_android_internal_os_Zygote.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index fad9e0e798996..06e66d63de481 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -2285,7 +2285,9 @@ pid_t zygote::ForkCommon(JNIEnv* env, bool is_system_server, // region shared with the child process we reduce the number of pages that // transition to the private-dirty state when malloc adjusts the meta-data // on each of the pages it is managing after the fork. - mallopt(M_PURGE, 0); + if (mallopt(M_PURGE_ALL, 0) != 1) { + mallopt(M_PURGE, 0); + } } pid_t pid = fork();