From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/os/bluestore/StupidAllocator.h | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/os/bluestore/StupidAllocator.h (limited to 'src/os/bluestore/StupidAllocator.h') diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h new file mode 100644 index 000000000..e1fc101e0 --- /dev/null +++ b/src/os/bluestore/StupidAllocator.h @@ -0,0 +1,73 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H +#define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H + +#include + +#include "Allocator.h" +#include "include/btree_map.h" +#include "include/interval_set.h" +#include "os/bluestore/bluestore_types.h" +#include "include/mempool.h" +#include "common/ceph_mutex.h" + +class StupidAllocator : public Allocator { + CephContext* cct; + ceph::mutex lock = ceph::make_mutex("StupidAllocator::lock"); + + int64_t num_free; ///< total bytes in freelist + uint64_t bdev_block_size; + + template using allocator_t = + mempool::bluestore_alloc::pool_allocator>; + template using btree_map_t = + btree::btree_map, allocator_t>; + using interval_set_t = interval_set; + std::vector free; ///< leading-edge copy + + uint64_t last_alloc = 0; + + unsigned _choose_bin(uint64_t len); + void _insert_free(uint64_t offset, uint64_t len); + + uint64_t _aligned_len( + interval_set_t::iterator p, + uint64_t alloc_unit); + +public: + StupidAllocator(CephContext* cct, + const std::string& name, + int64_t size, + int64_t block_size); + ~StupidAllocator() override; + const char* get_type() const override + { + return "stupid"; + } + + int64_t allocate( + uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, + int64_t hint, PExtentVector *extents) override; + + int64_t allocate_int( + uint64_t want_size, uint64_t alloc_unit, int64_t hint, + uint64_t *offset, uint32_t *length); + + void release( + const interval_set& release_set) override; + + uint64_t get_free() override; + double get_fragmentation() override; + + void dump() override; + void foreach(std::function notify) override; + + void init_add_free(uint64_t offset, uint64_t length) override; + void init_rm_free(uint64_t offset, uint64_t length) override; + + void shutdown() override; +}; + +#endif -- cgit v1.2.3