Files
clang-p2996/compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp
Dmitry Vyukov aff73487c9 tsan: increase dense slab alloc capacity
We've got a user report about heap block allocator overflow.
Bump the L1 capacity of all dense slab allocators to maximum
and be careful to not page the whole L1 array in from .bss.
If OS uses huge pages, this still may cause a limited RSS increase
due to boundary huge pages, but avoiding that looks hard.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101161
2021-04-29 07:34:50 +02:00

56 lines
1.4 KiB
C++

//===-- tsan_dense_alloc_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of ThreadSanitizer (TSan), a race detector.
//
//===----------------------------------------------------------------------===//
#include "tsan_dense_alloc.h"
#include "tsan_rtl.h"
#include "tsan_mman.h"
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdint.h>
#include <map>
namespace __tsan {
TEST(DenseSlabAlloc, Basic) {
typedef u64 T;
typedef DenseSlabAlloc<T, 128, 128> Alloc;
typedef Alloc::Cache Cache;
typedef Alloc::IndexT IndexT;
const T N = 1000;
Alloc alloc("test");
Cache cache;
alloc.InitCache(&cache);
IndexT blocks[N];
for (int ntry = 0; ntry < 3; ntry++) {
for (T i = 0; i < N; i++) {
IndexT idx = alloc.Alloc(&cache);
blocks[i] = idx;
EXPECT_NE(idx, 0U);
T *v = alloc.Map(idx);
*v = i;
}
for (T i = 0; i < N; i++) {
IndexT idx = blocks[i];
T *v = alloc.Map(idx);
EXPECT_EQ(*v, i);
alloc.Free(&cache, idx);
}
alloc.FlushCache(&cache);
}
}
} // namespace __tsan