X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fos%2Fbluestore%2FStupidAllocator.h;fp=src%2Fceph%2Fsrc%2Fos%2Fbluestore%2FStupidAllocator.h;h=431c636a61022a82eca8b88143ff12d39e4e53ca;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/os/bluestore/StupidAllocator.h b/src/ceph/src/os/bluestore/StupidAllocator.h new file mode 100644 index 0000000..431c636 --- /dev/null +++ b/src/ceph/src/os/bluestore/StupidAllocator.h @@ -0,0 +1,62 @@ +// -*- 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_interval_set.h" +#include "os/bluestore/bluestore_types.h" +#include "include/mempool.h" + +class StupidAllocator : public Allocator { + CephContext* cct; + std::mutex lock; + + int64_t num_free; ///< total bytes in freelist + int64_t num_reserved; ///< reserved bytes + + typedef mempool::bluestore_alloc::pool_allocator< + pair> allocator; + std::vector> free; ///< leading-edge copy + + uint64_t last_alloc; + + unsigned _choose_bin(uint64_t len); + void _insert_free(uint64_t offset, uint64_t len); + + uint64_t _aligned_len( + btree_interval_set::iterator p, + uint64_t alloc_unit); + +public: + StupidAllocator(CephContext* cct); + ~StupidAllocator() override; + + int reserve(uint64_t need) override; + void unreserve(uint64_t unused) override; + + int64_t allocate( + uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, + int64_t hint, mempool::bluestore_alloc::vector *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( + uint64_t offset, uint64_t length) override; + + uint64_t get_free() override; + + void dump() 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