Currently we allocate MemoryMapper per size class.
MemoryMapper mmap's and munmap's internal buffer.
This results in 50 mmap/munmap calls under the global
allocator mutex. Reuse MemoryMapper and the buffer
for all size classes. This radically reduces number of
mmap/munmap calls. Smaller size classes tend to have
more objects allocated, so it's highly likely that
the buffer allocated for the first size class will
be enough for all subsequent size classes.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | ||
---|---|---|
46 | I think this can just be 'MemoryMapper', and the typedef later would just shadow the template class. Because there's still that 'MemoryMapperT' template argument elsewhere[1], and on a whole it looks like 'MemoryMapperT' would indicate a template arg, whereas here it no longer is. | |
50 | explicit? | |
490 | [1] |
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | ||
---|---|---|
490 | I fail to decipher this comment. |
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | ||
---|---|---|
490 | See other comment:
(... cross referencing code in comments is complicated.) |
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | ||
---|---|---|
114 | It looks like this kind of shadowing is not accepted by GCC:
I've reverted the change for now. |
PTAL
I've re-uploaded with the gcc warning fixed, you can look at the new diff with:
https://reviews.llvm.org/D105778?vs=357981&id=358180#toc
Breaks Windows https://lab.llvm.org/buildbot/#/builders/127/builds/13818/steps/8/logs/stdio
# command output: Creating library C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Windows\Output\sanitizer_purge.cpp.lib and object C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Windows\Output\sanitizer_purge.cpp.exp $ ":" "RUN: at line 7" $ "C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Windows\Output\sanitizer_purge.cpp.tmp" # command stderr: AddressSanitizer: CHECK failed: sanitizer_win.cpp:139 "((VirtualQuery(addr, &mbi, sizeof(mbi)))) != (0)" (0x0, 0x0) (tid=8988) #0 0x7ff7650e4f6d in __asan::CheckUnwind C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\asan_rtl.cpp:67 #1 0x7ff7650d0273 in __sanitizer::CheckFailed(char const *, int, char const *, unsigned __int64, unsigned __int64) C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_termination.cpp:86 #2 0x7ff7650d2e69 in __sanitizer::UnmapOrDie(void *, unsigned __int64) C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_win.cpp:139 #3 0x7ff7650d2b6a in __sanitizer::ReleaseMemoryPagesToOS(unsigned __int64, unsigned __int64) C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_win.cpp:342 #4 0x7ff765100f12 in __sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> >::FreePagesRangeTracker<__sanitizer::MemoryMapper<__sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> > > >::CloseOpenedRange C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_allocator_primary64.h:523 #5 0x7ff765100f12 in __sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> >::FreePagesRangeTracker<__sanitizer::MemoryMapper<__sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> > > >::NextPage C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_allocator_primary64.h:508 #6 0x7ff765100f12 in __sanitizer::SizeClassAllocator64<struct __asan::AP64<struct __sanitizer::LocalAddressSpaceView>>::ReleaseFreeMemoryToOS<class __sanitizer::MemoryMapper<class __sanitizer::SizeClassAllocator64<struct __asan::AP64<struct __sanitizer::LocalAddressSpaceView>>>>(unsigned int *, unsigned __int64, unsigned __int64, unsigned __int64, class __sanitizer::MemoryMapper<class __sanitizer::SizeClassAllocator64<struct __asan::AP64<struct __sanitizer::LocalAddressSpaceView>>> *, unsigned __int64) C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_allocator_primary64.h:610 #7 0x7ff7651031c8 in __sanitizer::SizeClassAllocator64<struct __asan::AP64<struct __sanitizer::LocalAddressSpaceView>>::ForceReleaseToOS(void) C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_allocator_primary64.h:181 #8 0x7ff7651071ae in __sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> >,__sanitizer::LargeMmapAllocatorPtrArrayDynamic>::ForceReleaseToOS C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_allocator_combined.h:86 #9 0x7ff7651071ae in __asan::Allocator::Purge C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\asan_allocator.cpp:836 #10 0x7ff7651071ae in __sanitizer_purge_allocator C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\asan_allocator.cpp:1242 #11 0x7ff7650c129e in main C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\test\asan\TestCases\Windows\sanitizer_purge.cpp:23 #12 0x7ff76510a247 in invoke_main d:\A01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78 #13 0x7ff76510a247 in __scrt_common_main_seh d:\A01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 #14 0x7ffb5c4213f1 (C:\windows\system32\KERNEL32.DLL+0x1800013f1) #15 0x7ffb5c9154f3 (C:\windows\SYSTEM32\ntdll.dll+0x1800154f3)
FYI @hctim
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | ||
---|---|---|
82 | Maybe problem is that class_id everywhere else is the first arg. |
Maybe problem is that class_id everywhere else is the first arg.
Thanks for fixing this.
I very much confused how all linux tests passes with the swapped args... and there is a number of tests for this...
clang-tidy: error: This file must be included inside sanitizer_allocator.h [clang-diagnostic-error]
not useful