[compiler-rt] 8725b38 - [NFC][sanitizer] Simplify MapPackedCounterArrayBuffer
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 13 17:26:46 PDT 2021
Author: Vitaly Buka
Date: 2021-07-13T17:26:07-07:00
New Revision: 8725b382b0a5ea375252d966bafbace62a21e93b
URL: https://github.com/llvm/llvm-project/commit/8725b382b0a5ea375252d966bafbace62a21e93b
DIFF: https://github.com/llvm/llvm-project/commit/8725b382b0a5ea375252d966bafbace62a21e93b.diff
LOG: [NFC][sanitizer] Simplify MapPackedCounterArrayBuffer
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 952b06976362..b142ee0131b2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -49,11 +49,6 @@ class MemoryMapper {
explicit MemoryMapper(const Allocator &allocator) : allocator_(allocator) {}
- ~MemoryMapper() {
- if (buffer_)
- UnmapOrDie(buffer_, buffer_size_);
- }
-
bool GetAndResetStats(uptr &ranges, uptr &bytes) {
ranges = released_ranges_count_;
released_ranges_count_ = 0;
@@ -62,20 +57,10 @@ class MemoryMapper {
return ranges != 0;
}
- void *MapPackedCounterArrayBuffer(uptr buffer_size) {
- // TODO(alekseyshl): The idea to explore is to check if we have enough
- // space between num_freed_chunks*sizeof(CompactPtrT) and
- // mapped_free_array to fit buffer_size bytes and use that space instead
- // of mapping a temporary one.
- if (buffer_size_ < buffer_size) {
- if (buffer_)
- UnmapOrDie(buffer_, buffer_size_);
- buffer_ = MmapOrDieOnFatalError(buffer_size, "ReleaseToOSPageCounters");
- buffer_size_ = buffer_size;
- } else {
- internal_memset(buffer_, 0, buffer_size);
- }
- return buffer_;
+ u64 *MapPackedCounterArrayBuffer(uptr count) {
+ buffer_.clear();
+ buffer_.resize(count);
+ return buffer_.data();
}
// Releases [from, to) range of pages back to OS.
@@ -92,8 +77,7 @@ class MemoryMapper {
const Allocator &allocator_;
uptr released_ranges_count_ = 0;
uptr released_bytes_ = 0;
- void *buffer_ = nullptr;
- uptr buffer_size_ = 0;
+ InternalMmapVector<u64> buffer_;
};
template <class Params>
@@ -440,11 +424,8 @@ class SizeClassAllocator64 {
packing_ratio_log = Log2(packing_ratio);
bit_offset_mask = packing_ratio - 1;
- buffer_size =
- (RoundUpTo(n, 1ULL << packing_ratio_log) >> packing_ratio_log) *
- sizeof(*buffer);
- buffer = reinterpret_cast<u64 *>(
- mapper->MapPackedCounterArrayBuffer(buffer_size));
+ buffer = mapper->MapPackedCounterArrayBuffer(
+ RoundUpTo(n, 1ULL << packing_ratio_log) >> packing_ratio_log);
}
bool IsAllocated() const {
@@ -481,8 +462,6 @@ class SizeClassAllocator64 {
u64 counter_mask;
u64 packing_ratio_log;
u64 bit_offset_mask;
-
- u64 buffer_size;
u64* buffer;
};
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
index 2e1f59c11def..552387258e1b 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
@@ -1149,15 +1149,12 @@ TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) {
class NoMemoryMapper {
public:
- uptr last_request_buffer_size;
+ uptr last_request_buffer_size = 0;
- NoMemoryMapper() : last_request_buffer_size(0) {}
-
- void *MapPackedCounterArrayBuffer(uptr buffer_size) {
- last_request_buffer_size = buffer_size;
+ u64 *MapPackedCounterArrayBuffer(uptr buffer_size) {
+ last_request_buffer_size = buffer_size * sizeof(u64);
return nullptr;
}
- void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) {}
};
class RedZoneMemoryMapper {
@@ -1168,19 +1165,17 @@ class RedZoneMemoryMapper {
MprotectNoAccess(reinterpret_cast<uptr>(buffer), page_size);
MprotectNoAccess(reinterpret_cast<uptr>(buffer) + page_size * 2, page_size);
}
- ~RedZoneMemoryMapper() {
- UnmapOrDie(buffer, 3 * GetPageSize());
- }
+ ~RedZoneMemoryMapper() { UnmapOrDie(buffer, 3 * GetPageSize()); }
- void *MapPackedCounterArrayBuffer(uptr buffer_size) {
+ u64 *MapPackedCounterArrayBuffer(uptr buffer_size) {
+ buffer_size *= sizeof(u64);
const auto page_size = GetPageSize();
CHECK_EQ(buffer_size, page_size);
- void *p =
- reinterpret_cast<void *>(reinterpret_cast<uptr>(buffer) + page_size);
+ u64 *p =
+ reinterpret_cast<u64 *>(reinterpret_cast<uptr>(buffer) + page_size);
memset(p, 0, page_size);
return p;
}
- void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) {}
private:
void *buffer;
More information about the llvm-commits
mailing list