]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/StupidAllocator.h
add subtree-ish sources for 12.0.3
[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_interval_set.h"
11 #include "os/bluestore/bluestore_types.h"
12
13 class StupidAllocator : public Allocator {
14 CephContext* cct;
15 std::mutex lock;
16
17 int64_t num_free; ///< total bytes in freelist
18 int64_t num_reserved; ///< reserved bytes
19
20 std::vector<btree_interval_set<uint64_t> > free; ///< leading-edge copy
21
22 uint64_t last_alloc;
23
24 unsigned _choose_bin(uint64_t len);
25 void _insert_free(uint64_t offset, uint64_t len);
26
27 public:
28 StupidAllocator(CephContext* cct);
29 ~StupidAllocator() override;
30
31 int reserve(uint64_t need) override;
32 void unreserve(uint64_t unused) override;
33
34 int64_t allocate(
35 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
36 int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents) override;
37
38 int64_t allocate_int(
39 uint64_t want_size, uint64_t alloc_unit, int64_t hint,
40 uint64_t *offset, uint32_t *length);
41
42 void release(
43 uint64_t offset, uint64_t length) override;
44
45 uint64_t get_free() override;
46
47 void dump() override;
48
49 void init_add_free(uint64_t offset, uint64_t length) override;
50 void init_rm_free(uint64_t offset, uint64_t length) override;
51
52 void shutdown() override;
53 };
54
55 #endif