commit 9451691a420734a97d19391aca8eb345efb375a8
parent 4f27637b168c1fb8b5acb097535891359e13f93d
Author: Paul Bone <paul@bone.id.au>
Date: Wed, 26 Nov 2025 02:46:46 +0000
Bug 1969856 - Limit PHC to 128MB of virtual address space r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D273369
Diffstat:
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/memory/build/PHC.cpp b/memory/build/PHC.cpp
@@ -365,10 +365,18 @@ static_assert((kPhcAlign % kPageSize) == 0);
// PHC will reserve some address space this large, then depending on runtime
// configuration will use a smaller fraction of it. Making
-// kPhcVirtualReservation the upper-bound of PHC's memory size. On 32bit
-// systems with less available address space we choose a more moderate value.
+// kPhcVirtualReservation the upper-bound of PHC's memory size.
+// * On 32bit systems with less available address space we choose a more
+// moderate value.
+// * On 64bit systems we set the limit to so that there are no more than 32,768
+// mappings, half of Linux's default limit (Bug 1969856). For 4KB pages
+// that's 128MB.
#ifdef HAVE_64BIT_BUILD
-static const size_t kPhcVirtualReservation = 1024 * 1024 * 1024;
+# if defined(XP_DARWIN) && defined(__aarch64__)
+static const size_t kPhcVirtualReservation = 512 * 1024 * 1024;
+# else
+static const size_t kPhcVirtualReservation = 128 * 1024 * 1024;
+# endif
#else
static const size_t kPhcVirtualReservation = 2 * 1024 * 1024;
#endif
diff --git a/memory/build/test/gtest/TestPHC.cpp b/memory/build/test/gtest/TestPHC.cpp
@@ -503,7 +503,11 @@ TEST(PHC, TestPHCLimit)
// (see kPhcVirtualReservation)
size_t limit =
#ifdef HAVE_64BIT_BUILD
- 1024 * 1024 * 1024;
+# if defined(XP_DARWIN) && defined(__aarch64__)
+ 512 * 1024 * 1024;
+# else
+ 128 * 1024 * 1024;
+# endif
#else
2 * 1024 * 1024;
#endif