[compiler-rt] [scudo] Avoid splitting aligned allocations on Trusty (PR #69281)

Andrei Homescu via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 20:28:10 PDT 2023


https://github.com/ahomescu created https://github.com/llvm/llvm-project/pull/69281

Don't use multiple tagged pages at the beginning of an allocation, since
it prevents using such allocations for memrefs, and mappings aren't
reused anyway since Trusty uses MapAllocatorNoCache.
Upstreamed from https://r.android.com/2537251.


>From 7e22d11ba14710b5104e481e282544a95840797d Mon Sep 17 00:00:00 2001
From: Marco Nelissen <marcone at google.com>
Date: Thu, 13 Apr 2023 18:48:57 -0700
Subject: [PATCH] [scudo] Avoid splitting aligned allocations on Trusty

Don't use multiple tagged pages at the beginning of an allocation, since
it prevents using such allocations for memrefs, and mappings aren't
reused anyway since Trusty uses MapAllocatorNoCache.
Upstreamed from https://r.android.com/2537251.
---
 compiler-rt/lib/scudo/standalone/secondary.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index c89e6a95f5a68a4..937dbde4452f2e8 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -114,7 +114,14 @@ template <typename Config> class MapAllocatorNoCache {
   }
 };
 
-static const uptr MaxUnusedCachePages = 4U;
+/*
+ * On Trusty we want to avoid splitting page-aligned allocations into
+ * multiple mappings, because it prevents using the allocation for memref.
+ * Using only 1 tagged page at the start of the allocation prevents
+ * reusing the mapping for slightly smaller allocations, but since Trusty
+ * uses MapAllocatorNoCache, it wouldn't reuse anyway.
+ */
+static const uptr MaxUnusedCachePages = SCUDO_TRUSTY ? 1U : 4U;
 
 template <typename Config>
 bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,



More information about the llvm-commits mailing list