Enable caching of writeable W^X mappings (#74526)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 25 Aug 2022 08:45:31 +0000 (10:45 +0200)
committerGitHub <noreply@github.com>
Thu, 25 Aug 2022 08:45:31 +0000 (10:45 +0200)
This change enables caching of the last used writeable mapping for
W^X. It was originally disabled by an ifdef, but after we've turned W^X
on by default, performance tests have shown a regression in some regex
tests. I have investigated those and found that they do excessive amount
of jitting (around 50000 methods). Enabling the caching of the last used
writeable mapping fixes the regression completely.
The caching implementation was present in the sources ever since I've
implemented the W^X stuff, but if was disabled by an ifdef. So this
change just defines the related symbol and enables the code.

The caching basically just keeps a writeable mapping after unmapping
until the next mapping request arrives, so it gives an opportunity to
reuse it in case of series of mappings of sequential range of executable
memory, which happens e.g. in the case mentioned.

src/coreclr/utilcode/executableallocator.cpp

index 9536b67..7872954 100644 (file)
@@ -259,7 +259,7 @@ bool ExecutableAllocator::Initialize()
     return true;
 }
 
-//#define ENABLE_CACHED_MAPPINGS
+#define ENABLE_CACHED_MAPPINGS
 
 void ExecutableAllocator::UpdateCachedMapping(BlockRW* pBlock)
 {