diff options
| author | 2023-04-29 12:22:35 +0900 | |
|---|---|---|
| committer | 2023-05-02 19:44:47 +0000 | |
| commit | c2ec76335b95ffcde66205731c3b51fe136f806e (patch) | |
| tree | 64cfd83ac344af2cd1893392c79b21ec63d0a59b | |
| parent | ece0123900dfa9330ebdb58dff2ff5b2887ca558 (diff) | |
Retry mmap if it fails
Sometimes, mmap returns ENOMEM even though there is enough memory, in
that case, retried mmap mostly succeeds.
So as a workaround, let MemMapArena::Allocate retry at most 3 time.
(to resolve flaky build failure)
Bug: 278665389
Test: run dex2oat repeatedly
(cherry picked from https://android-review.googlesource.com/q/commit:43312d5ee57fcd99ed6e97992b0b146dd6b6db9e)
Merged-In: Icbde6a06fe8d1b189486ea2ab10003425248df52
Change-Id: Icbde6a06fe8d1b189486ea2ab10003425248df52
| -rw-r--r-- | runtime/base/mem_map_arena_pool.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/runtime/base/mem_map_arena_pool.cc b/runtime/base/mem_map_arena_pool.cc index ae7db45024..fc1a61e8c8 100644 --- a/runtime/base/mem_map_arena_pool.cc +++ b/runtime/base/mem_map_arena_pool.cc @@ -57,13 +57,24 @@ MemMap MemMapArena::Allocate(size_t size, bool low_4gb, const char* name) { // and we want to be able to use all memory that we actually allocate. size = RoundUp(size, kPageSize); std::string error_msg; - MemMap map = MemMap::MapAnonymous(name, - size, - PROT_READ | PROT_WRITE, - low_4gb, - &error_msg); - CHECK(map.IsValid()) << error_msg; - return map; + // TODO(b/278665389): remove this retry logic if the root cause is found. + constexpr int MAX_RETRY_CNT = 3; + int retry_cnt = 0; + while (true) { + MemMap map = MemMap::MapAnonymous(name, size, PROT_READ | PROT_WRITE, low_4gb, &error_msg); + if (map.IsValid()) { + if (retry_cnt > 0) { + LOG(WARNING) << "Succeed with retry(cnt=" << retry_cnt << ")"; + } + return map; + } else { + if (retry_cnt == MAX_RETRY_CNT) { + CHECK(map.IsValid()) << error_msg << "(retried " << retry_cnt << " times)"; + } + } + retry_cnt++; + LOG(ERROR) << error_msg << " but retry(cnt=" << retry_cnt << ")"; + } } MemMapArena::~MemMapArena() { |