[compiler-rt] [scudo] increase frames per stack to 16 for stack depot (PR #82427)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 14:30:58 PST 2024


https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/82427

>From d087953f186e6be63fc8c51b6f01087f1ff19761 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Tue, 20 Feb 2024 14:10:38 -0800
Subject: [PATCH] [scudo] increase frames per stack to 16 for stack depot

8 was very low and it is likely that in real workloads we have more than
an average of 8 frames per stack given on Android we have 3 at the bottom:
__start_main, __libc_init, main, and three at the top: malloc,
scudo_malloc and Allocator::allocate. That leaves 2 frames for
application code, which is clearly unreasonable.
---
 compiler-rt/lib/scudo/standalone/combined.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 080ba42ad44497..41d2183fa6aeaf 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -1520,7 +1520,12 @@ class Allocator {
     constexpr u32 kStacksPerRingBufferEntry = 2;
     constexpr u32 kMaxU32Pow2 = ~(UINT32_MAX >> 1);
     static_assert(isPowerOfTwo(kMaxU32Pow2));
-    constexpr u32 kFramesPerStack = 8;
+    // On Android we always have 3 frames at the bottom: __start_main,
+    // __libc_init, main, and 3 at the top: malloc, scudo_malloc and
+    // Allocator::allocate. This leaves 10 frames for the user app. The next
+    // smallest power of two (8) would only leave 2, which is clearly too
+    // little.
+    constexpr u32 kFramesPerStack = 16;
     static_assert(isPowerOfTwo(kFramesPerStack));
 
     // We need StackDepot to be aligned to 8-bytes so the ring we store after



More information about the llvm-commits mailing list