Simplify OOM handling.
Most OOM conditions in Chromium are expected to crash, but there were
multiple different code paths for this depending on the platform and the
allocator being used, giving slightly different kinds of crash/output.
Various shim functions had also been kept in the code for the benefit of
the crash server, which uses a list of known OOM-handling function names
to classify stack frames.
This CL simplifies things significantly and retains almost all
functionality:
- base::TerminateBecauseOutOfMemory() is the canonical function to
trigger an OOM crash. base::internal::OnNoMemoryInternal() has been
removed from base's public API (though the function still exists).
- g_oom_size has been moved from memory_linux.cc to memory.cc; it's not
actually read on other platforms but setting it unconditionally
simplifies the code and the cost is negligible.
- memory_win.cc no longer defines its own versions of
TerminateBecauseOutOfMemory or OnNoMemory as they weren't actually
different to the generic versions.
- memory_linux.cc no longer defines its own versions of OnNoMemory or
OnNoMemorySize. They used to LOG(FATAL) instead of simply crashing as
the generic versions did; this has been removed as it was only used
for some OOM failures and not others, even on Linux, and the
differing results were confusing. (e.g. PartitionAlloc failures did
not use this codepath)
- All these OOM functions now ultimately reach
base::internal::OnNoMemoryInternal() and crash there. This is NOINLINE
and has been recognised by the crash server as an OOM function for a
considerable time; none of the other NOINLINE function names should be
needed any more.
Change-Id: Iabb7ba9f1dba7fe8eca5c754d1b6b0216ad452bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2643366
Reviewed-by: Nico Weber <[email protected]>
Reviewed-by: Primiano Tucci <[email protected]>
Commit-Queue: Richard Coles <[email protected]>
Cr-Commit-Position: refs/heads/master@{#847197}
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index 3bada777..f0baaed1 100644
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -25,28 +25,12 @@
namespace base {
-size_t g_oom_size = 0U;
-
namespace {
-void OnNoMemorySize(size_t size) {
- g_oom_size = size;
-
- if (size != 0)
- LOG(FATAL) << "Out of memory, size = " << size;
- LOG(FATAL) << "Out of memory.";
-}
-
-// NOINLINE as base::`anonymous namespace`::OnNoMemory() is recognized by the
-// crash server.
-NOINLINE void OnNoMemory() {
- OnNoMemorySize(0);
-}
-
void ReleaseReservationOrTerminate() {
if (internal::ReleaseAddressSpaceReservation())
return;
- OnNoMemory();
+ TerminateBecauseOutOfMemory(0);
}
} // namespace