#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
-#include "common/Mutex.h"
#include "common/Cond.h"
#include "common/errno.h"
#include "include/stringify.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_
-#if GTEST_HAS_PARAM_TEST
-
class AllocTest : public ::testing::TestWithParam<const char*> {
public:
};
const uint64_t _1m = 1024 * 1024;
-const uint64_t _2m = 2 * 1024 * 1024;
void dump_mempools()
{
public:
AllocTracker(uint64_t capacity, uint64_t alloc_unit)
- : u1(capacity, alloc_unit)
+ : u1(0, capacity)
{
- assert(alloc_unit >= 0x100);
- assert(capacity <= (uint64_t(1) << 48)); // we use 5 octets (bytes 1 - 5) to store
+ ceph_assert(alloc_unit >= 0x100);
+ ceph_assert(capacity <= (uint64_t(1) << 48)); // we use 5 octets (bytes 1 - 5) to store
// offset to save the required space.
// This supports capacity up to 281 TB
bool push(uint64_t offs, uint32_t len)
{
- assert((len & 0xff) == 0);
- assert((offs & 0xff) == 0);
- assert((offs & 0xffff000000000000) == 0);
+ ceph_assert((len & 0xff) == 0);
+ ceph_assert((offs & 0xff) == 0);
+ ceph_assert((offs & 0xffff000000000000) == 0);
if (head + 1 == tail)
return false;
for (uint64_t i = 0; i < capacity; i += want_size)
{
tmp.clear();
- EXPECT_EQ(want_size, alloc->allocate(want_size, alloc_unit, 0, 0, &tmp));
+ EXPECT_EQ(static_cast<int64_t>(want_size),
+ alloc->allocate(want_size, alloc_unit, 0, 0, &tmp));
if (0 == (i % (1 * 1024 * _1m))) {
std::cout << "alloc " << i / 1024 / 1024 << " mb of "
<< capacity / 1024 / 1024 << std::endl;
doOverwriteTest(capacity, prefill, overwrite);
}
-INSTANTIATE_TEST_CASE_P(
- Allocator,
- AllocTest,
- ::testing::Values("stupid", "bitmap"));
+TEST_P(AllocTest, mempoolAccounting)
+{
+ uint64_t bytes = mempool::bluestore_alloc::allocated_bytes();
+ uint64_t items = mempool::bluestore_alloc::allocated_items();
+
+ uint64_t alloc_size = 4 * 1024;
+ uint64_t capacity = 512ll * 1024 * 1024 * 1024;
+ Allocator* alloc = Allocator::create(g_ceph_context, string(GetParam()),
+ capacity, alloc_size);
+ ASSERT_NE(alloc, nullptr);
+ alloc->init_add_free(0, capacity);
-#else
+ std::map<uint32_t, PExtentVector> all_allocs;
+ for (size_t i = 0; i < 10000; i++) {
+ PExtentVector tmp;
+ alloc->allocate(alloc_size, alloc_size, 0, 0, &tmp);
+ all_allocs[rand()] = tmp;
+ alloc->allocate(alloc_size, alloc_size, 0, 0, &tmp);
+ all_allocs[rand()] = tmp;
+
+ auto it = all_allocs.upper_bound(rand());
+ if (it != all_allocs.end()) {
+ alloc->release(it->second);
+ all_allocs.erase(it);
+ }
+ }
+
+ delete(alloc);
+ ASSERT_EQ(mempool::bluestore_alloc::allocated_bytes(), bytes);
+ ASSERT_EQ(mempool::bluestore_alloc::allocated_items(), items);
+}
-TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {}
-#endif
+INSTANTIATE_TEST_SUITE_P(
+ Allocator,
+ AllocTest,
+ ::testing::Values("stupid", "bitmap", "avl", "hybrid"));