Commit 63933423 authored by tsepez@chromium.org's avatar tsepez@chromium.org

Prevent PageAllocator from fragmenting address space on small Windows systems.

Peform a runtime check in the 32-bit windows code only to see if the
address space is highly constrained by the OS. If so, we give up some
randomness in exchange for memory utilization efficiency.

BUG=394591

Review URL: https://codereview.chromium.org/408483004

git-svn-id: svn://svn.chromium.org/blink/trunk@178586 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c316e560
...@@ -58,6 +58,29 @@ ...@@ -58,6 +58,29 @@
namespace WTF { namespace WTF {
#if OS(WIN)
static bool shouldUseAddressHint()
{
#if CPU(32BIT)
// When running 32-bit processes under 32-bit Windows, the userspace is
// limited to 2 GB, and we risk fragmenting it badly if we allow further
// randomization via our address hint. On the other hand, if the process
// is running under WOW64, then it has at least 3 GB available (and likely
// 4 GB depending upon the OS version), and we want use the additional
// randomness.
static BOOL bIsWow64 = -1;
if (bIsWow64 == -1) {
IsWow64Process(GetCurrentProcess(), &bIsWow64);
}
return !!bIsWow64;
#else // CPU(32BIT)
return true;
#endif // CPU(32BIT)
}
#endif // OS(WIN)
// This simple internal function wraps the OS-specific page allocation call so // This simple internal function wraps the OS-specific page allocation call so
// that it behaves consistently: the address is a hint and if it cannot be used, // that it behaves consistently: the address is a hint and if it cannot be used,
// the allocation will be placed elsewhere. // the allocation will be placed elsewhere.
...@@ -65,8 +88,9 @@ static void* systemAllocPages(void* addr, size_t len) ...@@ -65,8 +88,9 @@ static void* systemAllocPages(void* addr, size_t len)
{ {
ASSERT(!(len & kPageAllocationGranularityOffsetMask)); ASSERT(!(len & kPageAllocationGranularityOffsetMask));
ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffsetMask)); ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffsetMask));
void* ret; void* ret = 0;
#if OS(WIN) #if OS(WIN)
if (shouldUseAddressHint())
ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!ret) if (!ret)
ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
......
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