]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/StupidAllocator.h
import ceph 12.2.12
[ceph.git] / ceph / src / os / bluestore / StupidAllocator.h
CommitLineData
7c673cae
FG
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"
94b18763
FG
10#include "include/btree_map.h"
11#include "include/interval_set.h"
7c673cae 12#include "os/bluestore/bluestore_types.h"
181888fb 13#include "include/mempool.h"
7c673cae
FG
14
15class StupidAllocator : public Allocator {
16 CephContext* cct;
17 std::mutex lock;
18
19 int64_t num_free; ///< total bytes in freelist
7c673cae 20
181888fb 21 typedef mempool::bluestore_alloc::pool_allocator<
94b18763
FG
22 pair<const uint64_t,uint64_t>> allocator_t;
23 typedef btree::btree_map<uint64_t,uint64_t,std::less<uint64_t>,allocator_t> interval_set_map_t;
24 typedef interval_set<uint64_t,interval_set_map_t> interval_set_t;
25 std::vector<interval_set_t> free; ///< leading-edge copy
7c673cae
FG
26
27 uint64_t last_alloc;
28
29 unsigned _choose_bin(uint64_t len);
30 void _insert_free(uint64_t offset, uint64_t len);
31
181888fb 32 uint64_t _aligned_len(
94b18763 33 interval_set_t::iterator p,
181888fb
FG
34 uint64_t alloc_unit);
35
7c673cae
FG
36public:
37 StupidAllocator(CephContext* cct);
38 ~StupidAllocator() override;
39
7c673cae
FG
40 int64_t allocate(
41 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
a8e16298 42 int64_t hint, PExtentVector *extents) override;
7c673cae
FG
43
44 int64_t allocate_int(
45 uint64_t want_size, uint64_t alloc_unit, int64_t hint,
46 uint64_t *offset, uint32_t *length);
47
48 void release(
a8e16298 49 const interval_set<uint64_t>& release_set) override;
7c673cae
FG
50
51 uint64_t get_free() override;
a8e16298 52 double get_fragmentation(uint64_t alloc_unit) override;
7c673cae
FG
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