Bug 1925181 - Properly set small alloc randomization on Android content processes as well r=jld
Differential Revision: https://phabricator.services.mozilla.com/D226135
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)).
|
||||
|
||||
@@ -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<StaticMutex> 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( \
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user