Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 #include "include/mempool.h"
13
14 class StupidAllocator : public Allocator {
15   CephContext* cct;
16   std::mutex lock;
17
18   int64_t num_free;     ///< total bytes in freelist
19   int64_t num_reserved; ///< reserved bytes
20
21   typedef mempool::bluestore_alloc::pool_allocator<
22     pair<const uint64_t,uint64_t>> allocator;
23   std::vector<btree_interval_set<uint64_t,allocator>> free;  ///< leading-edge copy
24
25   uint64_t last_alloc;
26
27   unsigned _choose_bin(uint64_t len);
28   void _insert_free(uint64_t offset, uint64_t len);
29
30   uint64_t _aligned_len(
31     btree_interval_set<uint64_t,allocator>::iterator p,
32     uint64_t alloc_unit);
33
34 public:
35   StupidAllocator(CephContext* cct);
36   ~StupidAllocator() override;
37
38   int reserve(uint64_t need) override;
39   void unreserve(uint64_t unused) override;
40
41   int64_t allocate(
42     uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
43     int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents) override;
44
45   int64_t allocate_int(
46     uint64_t want_size, uint64_t alloc_unit, int64_t hint,
47     uint64_t *offset, uint32_t *length);
48
49   void release(
50     uint64_t offset, uint64_t length) override;
51
52   uint64_t get_free() override;
53
54   void dump() override;
55
56   void init_add_free(uint64_t offset, uint64_t length) override;
57   void init_rm_free(uint64_t offset, uint64_t length) override;
58
59   void shutdown() override;
60 };
61
62 #endif