]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/StupidAllocator.h
update sources to v12.2.5
[ceph.git] / ceph / src / os / bluestore / StupidAllocator.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H
5 #define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H
6
7 #include <mutex>
8
9 #include "Allocator.h"
10 #include "include/btree_map.h"
11 #include "include/interval_set.h"
12 #include "os/bluestore/bluestore_types.h"
13 #include "include/mempool.h"
14
15 class StupidAllocator : public Allocator {
16 CephContext* cct;
17 std::mutex lock;
18
19 int64_t num_free; ///< total bytes in freelist
20 int64_t num_reserved; ///< reserved bytes
21
22 typedef mempool::bluestore_alloc::pool_allocator<
23 pair<const uint64_t,uint64_t>> allocator_t;
24 typedef btree::btree_map<uint64_t,uint64_t,std::less<uint64_t>,allocator_t> interval_set_map_t;
25 typedef interval_set<uint64_t,interval_set_map_t> interval_set_t;
26 std::vector<interval_set_t> free; ///< leading-edge copy
27
28 uint64_t last_alloc;
29
30 unsigned _choose_bin(uint64_t len);
31 void _insert_free(uint64_t offset, uint64_t len);
32
33 uint64_t _aligned_len(
34 interval_set_t::iterator p,
35 uint64_t alloc_unit);
36
37 public:
38 StupidAllocator(CephContext* cct);
39 ~StupidAllocator() override;
40
41 int reserve(uint64_t need) override;
42 void unreserve(uint64_t unused) override;
43
44 int64_t allocate(
45 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
46 int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents) override;
47
48 int64_t allocate_int(
49 uint64_t want_size, uint64_t alloc_unit, int64_t hint,
50 uint64_t *offset, uint32_t *length);
51
52 void release(
53 uint64_t offset, uint64_t length) override;
54
55 uint64_t get_free() override;
56
57 void dump() override;
58
59 void init_add_free(uint64_t offset, uint64_t length) override;
60 void init_rm_free(uint64_t offset, uint64_t length) override;
61
62 void shutdown() override;
63 };
64
65 #endif