summaryrefslogtreecommitdiffstats
path: root/runtime/mem_map.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-06-04 16:22:41 -0700
committerMathieu Chartier <mathieuc@google.com>2015-06-05 14:14:36 -0700
commit3ae250c16bae3462e040b844dbc2e2fc732d67ba (patch)
treeac30e91bef5cccbd29fe2cd69a4cd66aa733137d /runtime/mem_map.cc
parent7fabaa6ba1927d21a317c03499b705cbde4f6a47 (diff)
downloadart-3ae250c16bae3462e040b844dbc2e2fc732d67ba.tar.gz
art-3ae250c16bae3462e040b844dbc2e2fc732d67ba.tar.bz2
art-3ae250c16bae3462e040b844dbc2e2fc732d67ba.zip
More LOW_4G optimizations
Eagerly try to map at an address when it doesn't overlap with the ART known maps. Reduces time spent creating the heap on N9 from ~100ms to ~10ms. Bug: 20727525 Change-Id: Ie8982ca9d1f3158104b2b53b992c3a28841fc443
Diffstat (limited to 'runtime/mem_map.cc')
-rw-r--r--runtime/mem_map.cc35
1 files changed, 26 insertions, 9 deletions
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index 7feac8ab0c..d6d71f2f75 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -240,6 +240,22 @@ static bool CheckMapRequest(uint8_t* expected_ptr, void* actual_ptr, size_t byte
return false;
}
+#if USE_ART_LOW_4G_ALLOCATOR
+static inline void* TryMemMapLow4GB(void* ptr, size_t page_aligned_byte_count, int prot, int flags,
+ int fd) {
+ void* actual = mmap(ptr, page_aligned_byte_count, prot, flags, fd, 0);
+ if (actual != MAP_FAILED) {
+ // Since we didn't use MAP_FIXED the kernel may have mapped it somewhere not in the low
+ // 4GB. If this is the case, unmap and retry.
+ if (reinterpret_cast<uintptr_t>(actual) + page_aligned_byte_count >= 4 * GB) {
+ munmap(actual, page_aligned_byte_count);
+ actual = MAP_FAILED;
+ }
+ }
+ return actual;
+}
+#endif
+
MemMap* MemMap::MapAnonymous(const char* name, uint8_t* expected_ptr, size_t byte_count, int prot,
bool low_4gb, bool reuse, std::string* error_msg) {
#ifndef __LP64__
@@ -339,6 +355,14 @@ MemMap* MemMap::MapAnonymous(const char* name, uint8_t* expected_ptr, size_t byt
++it;
}
+ // Try to see if we get lucky with this address since none of the ART maps overlap.
+ actual = TryMemMapLow4GB(reinterpret_cast<void*>(ptr), page_aligned_byte_count, prot, flags,
+ fd.get());
+ if (actual != MAP_FAILED) {
+ next_mem_pos_ = reinterpret_cast<uintptr_t>(actual) + page_aligned_byte_count;
+ break;
+ }
+
if (4U * GB - ptr < page_aligned_byte_count) {
// Not enough memory until 4GB.
if (first_run) {
@@ -368,17 +392,10 @@ MemMap* MemMap::MapAnonymous(const char* name, uint8_t* expected_ptr, size_t byt
next_mem_pos_ = tail_ptr; // update early, as we break out when we found and mapped a region
if (safe == true) {
- actual = mmap(reinterpret_cast<void*>(ptr), page_aligned_byte_count, prot, flags, fd.get(),
- 0);
+ actual = TryMemMapLow4GB(reinterpret_cast<void*>(ptr), page_aligned_byte_count, prot, flags,
+ fd.get());
if (actual != MAP_FAILED) {
- // Since we didn't use MAP_FIXED the kernel may have mapped it somewhere not in the low
- // 4GB. If this is the case, unmap and retry.
- if (reinterpret_cast<uintptr_t>(actual) + page_aligned_byte_count < 4 * GB) {
break;
- } else {
- munmap(actual, page_aligned_byte_count);
- actual = MAP_FAILED;
- }
}
} else {
// Skip over last page.