Avoid address-space exhaustion on 32-bit test processes

When running base_perftests for x86 an out-of-memory failure is hit on
MemoryAllocationPerfTest.SingleBucket/3. This test was already disabled
on Android due to its excessive use of memory and this change disables
the test for all 32-bit processes.

With this change it is now possible to run base_perftests for x86.

Change-Id: If3cfbd8b754ae6f09f70e989ac1cab94e2a188be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2288829
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786633}
GitOrigin-RevId: c327ca6149f648ef89defe7679b686010552a28c
diff --git a/allocator/partition_allocator/partition_alloc_perftest.cc b/allocator/partition_allocator/partition_alloc_perftest.cc
index d3ab0b3..5c5539f 100644
--- a/allocator/partition_allocator/partition_alloc_perftest.cc
+++ b/allocator/partition_allocator/partition_alloc_perftest.cc
@@ -15,6 +15,12 @@
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/perf/perf_result_reporter.h"
 
+#if defined(OS_ANDROID) || defined(ARCH_CPU_32_BITS)
+// Some tests allocate many GB of memory, which can cause issues on Android and
+// address-space exhaustion for any 32-bit process.
+#define MEMORY_CONSTRAINED
+#endif
+
 namespace base {
 namespace {
 
@@ -119,7 +125,7 @@
   MemoryAllocationPerfNode* next_ = nullptr;
 };
 
-#if !defined(OS_ANDROID)
+#if !defined(MEMORY_CONSTRAINED)
 float SingleBucket(Allocator* allocator) {
   auto* first =
       reinterpret_cast<MemoryAllocationPerfNode*>(allocator->Alloc(40));
@@ -142,7 +148,7 @@
   MemoryAllocationPerfNode::FreeAll(first, allocator);
   return timer.LapsPerSecond();
 }
-#endif  // defined(OS_ANDROID)
+#endif  // defined(MEMORY_CONSTRAINED)
 
 float SingleBucketWithFree(Allocator* allocator) {
   // Allocate an initial element to make sure the bucket stays set up.
@@ -160,7 +166,7 @@
   return timer.LapsPerSecond();
 }
 
-#if !defined(OS_ANDROID)
+#if !defined(MEMORY_CONSTRAINED)
 float MultiBucket(Allocator* allocator) {
   auto* first =
       reinterpret_cast<MemoryAllocationPerfNode*>(allocator->Alloc(40));
@@ -183,7 +189,7 @@
 
   return timer.LapsPerSecond() * kMultiBucketRounds;
 }
-#endif  // defined(OS_ANDROID)
+#endif  // defined(MEMORY_CONSTRAINED)
 
 float MultiBucketWithFree(Allocator* allocator) {
   std::vector<void*> elems;
@@ -263,13 +269,13 @@
 
 // This test (and the other one below) allocates a large amount of memory, which
 // can cause issues on Android.
-#if !defined(OS_ANDROID)
+#if !defined(MEMORY_CONSTRAINED)
 TEST_P(MemoryAllocationPerfTest, SingleBucket) {
   auto params = GetParam();
   RunTest(std::get<0>(params), std::get<1>(params), SingleBucket,
           "SingleBucket");
 }
-#endif
+#endif  // defined(MEMORY_CONSTRAINED)
 
 TEST_P(MemoryAllocationPerfTest, SingleBucketWithFree) {
   auto params = GetParam();
@@ -277,12 +283,12 @@
           "SingleBucketWithFree");
 }
 
-#if !defined(OS_ANDROID)
+#if !defined(MEMORY_CONSTRAINED)
 TEST_P(MemoryAllocationPerfTest, MultiBucket) {
   auto params = GetParam();
   RunTest(std::get<0>(params), std::get<1>(params), MultiBucket, "MultiBucket");
 }
-#endif
+#endif  // defined(MEMORY_CONSTRAINED)
 
 TEST_P(MemoryAllocationPerfTest, MultiBucketWithFree) {
   auto params = GetParam();