summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2017-10-16 16:35:49 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2017-10-16 16:35:49 +0000
commit2c8fe470a4a79be7280bfa467232d7de0f6ee6d5 (patch)
tree9ba803346664363a54d37a03b3e742458bd7ac39
parentbcb82557bab28fee71512de08c0199d09057a611 (diff)
parentc42cb0e08a7c8f7085115e57b0ea92da9eee1575 (diff)
Merge "Add -XX:MadviseRandomAccess option"
-rw-r--r--runtime/oat_file.cc24
-rw-r--r--runtime/parsed_options.cc5
-rw-r--r--runtime/runtime.cc1
-rw-r--r--runtime/runtime.h10
-rw-r--r--runtime/runtime_options.def1
5 files changed, 27 insertions, 14 deletions
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index b3c3aa05f3..781ddd7aae 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -77,9 +77,6 @@ static constexpr bool kUseDlopenOnHost = true;
// For debugging, Open will print DlOpen error message if set to true.
static constexpr bool kPrintDlOpenErrorMessage = false;
-// If true, we advise the kernel about dex file mem map accesses.
-static constexpr bool kMadviseDexFileAccesses = true;
-
// Note for OatFileBase and descendents:
//
// These are used in OatFile::Open to try all our loaders.
@@ -1651,20 +1648,19 @@ const DexFile::ClassDef* OatFile::OatDexFile::FindClassDef(const DexFile& dex_fi
// Madvise the dex file based on the state we are moving to.
void OatDexFile::MadviseDexFile(const DexFile& dex_file, MadviseState state) {
- const bool low_ram = Runtime::Current()->GetHeap()->IsLowMemoryMode();
+ Runtime* const runtime = Runtime::Current();
+ const bool low_ram = runtime->GetHeap()->IsLowMemoryMode();
// TODO: Also do madvise hints for non low ram devices.
- if (!kMadviseDexFileAccesses || !low_ram) {
+ if (!low_ram) {
return;
}
- if (state == MadviseState::kMadviseStateAtLoad) {
- if (low_ram) {
- // Default every dex file to MADV_RANDOM when its loaded by default for low ram devices.
- // Other devices have enough page cache to get performance benefits from loading more pages
- // into the page cache.
- MadviseLargestPageAlignedRegion(dex_file.Begin(),
- dex_file.Begin() + dex_file.Size(),
- MADV_RANDOM);
- }
+ if (state == MadviseState::kMadviseStateAtLoad && runtime->MAdviseRandomAccess()) {
+ // Default every dex file to MADV_RANDOM when its loaded by default for low ram devices.
+ // Other devices have enough page cache to get performance benefits from loading more pages
+ // into the page cache.
+ MadviseLargestPageAlignedRegion(dex_file.Begin(),
+ dex_file.Begin() + dex_file.Size(),
+ MADV_RANDOM);
}
const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile();
if (oat_dex_file != nullptr) {
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 9888186ed0..9841a95746 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -159,6 +159,10 @@ std::unique_ptr<RuntimeParser> ParsedOptions::MakeParser(bool ignore_unrecognize
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::DumpNativeStackOnSigQuit)
+ .Define("-XX:MadviseRandomAccess:_")
+ .WithType<bool>()
+ .WithValueMap({{"false", false}, {"true", true}})
+ .IntoKey(M::MadviseRandomAccess)
.Define("-Xusejit:_")
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
@@ -717,6 +721,7 @@ void ParsedOptions::Usage(const char* fmt, ...) {
UsageMessage(stream, " -XX:LargeObjectSpace={disabled,map,freelist}\n");
UsageMessage(stream, " -XX:LargeObjectThreshold=N\n");
UsageMessage(stream, " -XX:DumpNativeStackOnSigQuit=booleanvalue\n");
+ UsageMessage(stream, " -XX:MadviseRandomAccess:booleanvalue\n");
UsageMessage(stream, " -XX:SlowDebug={false,true}\n");
UsageMessage(stream, " -Xmethod-trace\n");
UsageMessage(stream, " -Xmethod-trace-file:filename");
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index a4ed21e450..8eb4a07b64 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1143,6 +1143,7 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
zygote_max_failed_boots_ = runtime_options.GetOrDefault(Opt::ZygoteMaxFailedBoots);
experimental_flags_ = runtime_options.GetOrDefault(Opt::Experimental);
is_low_memory_mode_ = runtime_options.Exists(Opt::LowMemoryMode);
+ madvise_random_access_ = runtime_options.GetOrDefault(Opt::MadviseRandomAccess);
plugins_ = runtime_options.ReleaseOrDefault(Opt::Plugins);
agents_ = runtime_options.ReleaseOrDefault(Opt::AgentPath);
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 399e1c1622..9f79a01aa8 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -682,6 +682,12 @@ class Runtime {
return result;
}
+ // Whether or not we use MADV_RANDOM on files that are thought to have random access patterns.
+ // This is beneficial for low RAM devices since it reduces page cache thrashing.
+ bool MAdviseRandomAccess() const {
+ return madvise_random_access_;
+ }
+
private:
static void InitPlatformSignalHandlers();
@@ -916,6 +922,10 @@ class Runtime {
// Whether or not we are on a low RAM device.
bool is_low_memory_mode_;
+ // Whether or not we use MADV_RANDOM on files that are thought to have random access patterns.
+ // This is beneficial for low RAM devices since it reduces page cache thrashing.
+ bool madvise_random_access_;
+
// Whether the application should run in safe mode, that is, interpreter only.
bool safe_mode_;
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index cafae22e8c..2e03562505 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -70,6 +70,7 @@ RUNTIME_OPTIONS_KEY (bool, UseTLAB, (kUseT
RUNTIME_OPTIONS_KEY (bool, EnableHSpaceCompactForOOM, true)
RUNTIME_OPTIONS_KEY (bool, UseJitCompilation, false)
RUNTIME_OPTIONS_KEY (bool, DumpNativeStackOnSigQuit, true)
+RUNTIME_OPTIONS_KEY (bool, MadviseRandomAccess, false)
RUNTIME_OPTIONS_KEY (unsigned int, JITCompileThreshold)
RUNTIME_OPTIONS_KEY (unsigned int, JITWarmupThreshold)
RUNTIME_OPTIONS_KEY (unsigned int, JITOsrThreshold)