diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 8c3a6f972566..3f40b9bd9ae3 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -805,9 +805,7 @@ void ContentChild::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint, })); #endif -// Bug 1925181: Unrelated to forkserver, the android content processes are -// created in a way that makes them not follow this option correctly -#if defined(MOZ_MEMORY) && defined(DEBUG) && !defined(ANDROID) +#if defined(MOZ_MEMORY) && defined(DEBUG) jemalloc_stats_t stats; jemalloc_stats(&stats); MOZ_ASSERT(!stats.opt_randomize_small, diff --git a/memory/build/malloc_decls.h b/memory/build/malloc_decls.h index 8f309f143ad8..0931340054af 100644 --- a/memory/build/malloc_decls.h +++ b/memory/build/malloc_decls.h @@ -114,12 +114,9 @@ MALLOC_DECL(jemalloc_free_dirty_pages, void) // after lowering the max dirty pages threshold to get RSS back to normal. MALLOC_DECL(jemalloc_free_excess_dirty_pages, void) -// Only used by ForkServer after forking new child processes. // Change the value of opt_randomize_small to control small allocation // randomization and maybe perform a reinitialization of the arena's PRNG. -# if defined(MOZ_ENABLE_FORKSERVER) MALLOC_DECL(jemalloc_reset_small_alloc_randomization, void, bool) -# endif // Opt in or out of a thread local arena (bool argument is whether to opt-in // (true) or out (false)). diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index 46b0fae3c771..52d24677a9b3 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -5188,7 +5188,6 @@ inline void MozJemalloc::moz_set_max_dirty_page_modifier(int32_t aModifier) { gArenas.SetDefaultMaxDirtyPageModifier(aModifier); } -#if defined(MOZ_ENABLE_FORKSERVER) inline void MozJemalloc::jemalloc_reset_small_alloc_randomization( bool aRandomizeSmall) { // When this process got forked by ForkServer then it inherited the existing @@ -5196,6 +5195,9 @@ inline void MozJemalloc::jemalloc_reset_small_alloc_randomization( // been done but it may not reflect anymore the current set of options after // the fork(). // + // Similar behavior is also present on Android where it is also required to + // perform this step. + // // Content process will have randomization on small malloc disabled via the // MALLOC_OPTIONS environment variable set by parent process, missing this // will lead to serious performance regressions because CPU prefetch will @@ -5203,11 +5205,11 @@ inline void MozJemalloc::jemalloc_reset_small_alloc_randomization( // environment is not yet reset when the postfork child handler is being // called. // - // This API is here to allow those forkserver-forked Content processes to - // notify jemalloc to turn off the randomization on small allocations and - // perform the required reinitialization of already existing arena's PRNG. - // It is important to make sure that the PRNG state is properly re-initialized - // otherwise child processes would share all the same state. + // This API is here to allow those Content processes (spawned by ForkServer or + // Android service) to notify jemalloc to turn off the randomization on small + // allocations and perform the required reinitialization of already existing + // arena's PRNG. It is important to make sure that the PRNG state is properly + // re-initialized otherwise child processes would share all the same state. { AutoLock lock(gInitLock); @@ -5219,7 +5221,6 @@ inline void MozJemalloc::jemalloc_reset_small_alloc_randomization( arena->ResetSmallAllocRandomization(); } } -#endif #define MALLOC_DECL(name, return_type, ...) \ inline return_type MozJemalloc::moz_arena_##name( \ diff --git a/mozglue/android/APKOpen.cpp b/mozglue/android/APKOpen.cpp index 772b5a58a3a7..80eae0e83f62 100644 --- a/mozglue/android/APKOpen.cpp +++ b/mozglue/android/APKOpen.cpp @@ -402,6 +402,12 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv* jenv, jclass jc, SetGeckoProcessType(argv[--argc]); SetGeckoChildID(argv[--argc]); +#if defined(MOZ_MEMORY) + // XRE_IsContentProcess is not accessible here + jemalloc_reset_small_alloc_randomization( + /* aRandomizeSmall */ GetGeckoProcessType() != + GeckoProcessType_Content); +#endif gBootstrap->XRE_SetAndroidChildFds(jenv, jfds); @@ -425,8 +431,14 @@ extern "C" APKOPEN_EXPORT mozglueresult ChildProcessInit(int argc, if (argc < 2) { return FAILURE; } + SetGeckoProcessType(argv[--argc]); SetGeckoChildID(argv[--argc]); +#if defined(MOZ_MEMORY) + // XRE_IsContentProcess is not accessible here + jemalloc_reset_small_alloc_randomization( + /* aRandomizeSmall */ GetGeckoProcessType() != GeckoProcessType_Content); +#endif if (loadNSSLibs() != SUCCESS) { return FAILURE;