Commit 38610c88 authored by Bruce Dawson's avatar Bruce Dawson Committed by Chromium LUCI CQ

Fix address-space size calculation

PartitionAlloc tries to report out-of-memory failures differently
depending on whether it thinks that address-space is exhausted. This
change improves that by fixing the calculation of how much address
space the process has (usually 4 GiB, not 2 GiB, but variable).

Bug: 1159694
Change-Id: Ie5dba8ed55f663cf7edbcb824056042953d28c65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606634Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarBartek Nowierski <bartekn@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Auto-Submit: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840507}
parent 6be1b3d6
......@@ -13,6 +13,10 @@
#include "base/allocator/partition_allocator/pcscan.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "wow64apiset.h"
#endif
namespace base {
namespace {
......@@ -320,10 +324,10 @@ template <bool thread_safe>
[[noreturn]] NOINLINE void PartitionRoot<thread_safe>::OutOfMemory(
size_t size) {
#if !defined(ARCH_CPU_64_BITS)
size_t virtual_address_space_size =
const size_t virtual_address_space_size =
total_size_of_super_pages.load(std::memory_order_relaxed) +
total_size_of_direct_mapped_pages.load(std::memory_order_relaxed);
size_t uncommitted_size =
const size_t uncommitted_size =
virtual_address_space_size -
total_size_of_committed_pages.load(std::memory_order_relaxed);
......@@ -333,11 +337,20 @@ template <bool thread_safe>
internal::PartitionOutOfMemoryWithLotsOfUncommitedPages(size);
}
constexpr size_t kReasonableVirtualSize =
#if defined(OS_WIN)
// 1GiB on Windows, as the entire address space is typically 2GiB.
1024 * 1024 * 1024;
// If true then we are running on 64-bit Windows.
BOOL is_wow_64 = FALSE;
// Intentionally ignoring failures.
IsWow64Process(GetCurrentProcess(), &is_wow_64);
// 32-bit address space on Windows is typically either 2 GiB (on 32-bit
// Windows) or 4 GiB (on 64-bit Windows). 2.8 and 1.0 GiB are just rough
// guesses as to how much address space PA can consume (note that code,
// stacks, and other allocators will also consume address space).
const size_t kReasonableVirtualSize = (is_wow_64 ? 2800 : 1024) * 1024 * 1024;
// Make it obvious whether we are running on 64-bit Windows.
base::debug::Alias(&is_wow_64);
#else
constexpr size_t kReasonableVirtualSize =
// 1.5GiB elsewhere, since address space is typically 3GiB.
(1024 + 512) * 1024 * 1024;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment