summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2024-09-10 15:53:34 +0100
committer David Srbecky <dsrbecky@google.com> 2024-09-11 17:42:28 +0000
commit38e82add2aa26c982d28d8b05a9f8083b98d11ff (patch)
treed99a7d3ff086e91f11fd3526e6403c77328d83fc
parentc24482f7d3c167074deb6e386afc5fa24a785467 (diff)
Use MAP_FIXED_NOREPLACE on host
It seems that the new Ubuntu kernel completely ignores the address hint, but it will honour the MAP_FIXED_NOREPLACE flag. Test: Run tests on LUCI on Ubuntu-22 Change-Id: I8a1cebdf66b0eac8ac028e3c10210230e6b4a693
-rw-r--r--libartbase/base/mem_map.cc21
-rw-r--r--libartbase/base/mem_map.h6
-rw-r--r--runtime/gc/collector/mark_compact.cc3
3 files changed, 20 insertions, 10 deletions
diff --git a/libartbase/base/mem_map.cc b/libartbase/base/mem_map.cc
index 0ab47f2384..08d452b5ff 100644
--- a/libartbase/base/mem_map.cc
+++ b/libartbase/base/mem_map.cc
@@ -344,13 +344,20 @@ MemMap MemMap::MapAnonymous(const char* name,
// We need to store and potentially set an error number for pretty printing of errors
int saved_errno = 0;
- void* actual = MapInternal(addr,
- page_aligned_byte_count,
- prot,
- flags,
- fd.get(),
- 0,
- low_4gb);
+ void* actual = nullptr;
+
+ // New Ubuntu linux kerners seem to ignore the address hint, so make it a firm request.
+ // Whereas old kernels allocated at 'addr' if provided, newer kernels seem to ignore it.
+ // However, MAP_FIXED_NOREPLACE tells the kernel it must allocate at the address or fail.
+ // Do this only on host since android kernels still obey the hint without flag (for now).
+ if (!kIsTargetBuild && (flags & MAP_FIXED) == 0 && addr != nullptr) {
+ actual = MapInternal(
+ addr, page_aligned_byte_count, prot, flags | MAP_FIXED_NOREPLACE, fd.get(), 0, low_4gb);
+ // If the fixed-address allocation failed, fallback to the default path (random address).
+ }
+ if (actual == nullptr || actual == MAP_FAILED) {
+ actual = MapInternal(addr, page_aligned_byte_count, prot, flags, fd.get(), 0, low_4gb);
+ }
saved_errno = errno;
if (actual == MAP_FAILED) {
diff --git a/libartbase/base/mem_map.h b/libartbase/base/mem_map.h
index 90e2031cf9..a3af44fadb 100644
--- a/libartbase/base/mem_map.h
+++ b/libartbase/base/mem_map.h
@@ -29,6 +29,12 @@
#include "globals.h"
#include "macros.h"
+#ifndef __BIONIC__
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE 0x100000
+#endif
+#endif // __BIONIC__
+
namespace art {
#if defined(__LP64__) && !defined(__Fuchsia__) && \
diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc
index 25f30ec485..2ef1ec5c9f 100644
--- a/runtime/gc/collector/mark_compact.cc
+++ b/runtime/gc/collector/mark_compact.cc
@@ -67,9 +67,6 @@
#ifndef MREMAP_DONTUNMAP
#define MREMAP_DONTUNMAP 4
#endif
-#ifndef MAP_FIXED_NOREPLACE
-#define MAP_FIXED_NOREPLACE 0x100000
-#endif
#endif // __BIONIC__
// See aosp/2996596 for where these values came from.