[PATCH] D39338: [scudo] Allow to specify the maximum number of TSDs at compile time

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 10:56:22 PDT 2017


cryptoad created this revision.

This introduces `SCUDO_MAX_CACHES` allowing to define an upper bound to the
number of `ScudoTSD` created in the Shared TSD model (by default 32U).
This name felt clearer than `SCUDO_MAX_TSDS` which is technically what it really
is. I am opened to suggestions if that doesn't feel right.

Additionally change `getNumberOfCPUs` to return a `u32` to be more consistent.


https://reviews.llvm.org/D39338

Files:
  lib/scudo/scudo_platform.h
  lib/scudo/scudo_tsd_shared.cpp


Index: lib/scudo/scudo_tsd_shared.cpp
===================================================================
--- lib/scudo/scudo_tsd_shared.cpp
+++ lib/scudo/scudo_tsd_shared.cpp
@@ -25,20 +25,16 @@
 static u32 NumberOfTSDs;
 
 // sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory.
-static uptr getNumberOfCPUs() {
+static u32 getNumberOfCPUs() {
   cpu_set_t CPUs;
   CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
   return CPU_COUNT(&CPUs);
 }
 
 static void initOnce() {
   CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0);
   initScudo();
-  NumberOfTSDs = getNumberOfCPUs();
-  if (NumberOfTSDs == 0)
-    NumberOfTSDs = 1;
-  if (NumberOfTSDs > 32)
-    NumberOfTSDs = 32;
+  NumberOfTSDs = Min(Max(1U, getNumberOfCPUs()), SCUDO_MAX_CACHES);
   TSDs = reinterpret_cast<ScudoTSD *>(
       MmapOrDie(sizeof(ScudoTSD) * NumberOfTSDs, "ScudoTSDs"));
   for (u32 i = 0; i < NumberOfTSDs; i++)
Index: lib/scudo/scudo_platform.h
===================================================================
--- lib/scudo/scudo_platform.h
+++ lib/scudo/scudo_platform.h
@@ -40,6 +40,11 @@
 # error "The exclusive TSD model is not supported on this platform."
 #endif
 
+// Maximum number of caches that can be created for the Shared TSD model.
+#ifndef SCUDO_MAX_CACHES
+# define SCUDO_MAX_CACHES 32U
+#endif  // SCUDO_MAX_CACHES
+
 namespace __scudo {
 
 #if SANITIZER_CAN_USE_ALLOCATOR64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39338.120452.patch
Type: text/x-patch
Size: 1419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171026/e5d27895/attachment.bin>


More information about the llvm-commits mailing list