]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/StupidAllocator.h
update source to Ceph Pacific 16.2.2
[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"
11fdf7f2 14#include "common/ceph_mutex.h"
7c673cae
FG
15
16class StupidAllocator : public Allocator {
17 CephContext* cct;
11fdf7f2 18 ceph::mutex lock = ceph::make_mutex("StupidAllocator::lock");
7c673cae
FG
19
20 int64_t num_free; ///< total bytes in freelist
f67539c2 21 uint64_t bdev_block_size;
7c673cae 22
f67539c2
TL
23 template <typename K, typename V> using allocator_t =
24 mempool::bluestore_alloc::pool_allocator<std::pair<const K, V>>;
25 template <typename K, typename V> using btree_map_t =
26 btree::btree_map<K, V, std::less<K>, allocator_t<K, V>>;
27 using interval_set_t = interval_set<uint64_t, btree_map_t>;
94b18763 28 std::vector<interval_set_t> free; ///< leading-edge copy
7c673cae 29
9f95a23c 30 uint64_t last_alloc = 0;
7c673cae
FG
31
32 unsigned _choose_bin(uint64_t len);
33 void _insert_free(uint64_t offset, uint64_t len);
34
181888fb 35 uint64_t _aligned_len(
94b18763 36 interval_set_t::iterator p,
181888fb
FG
37 uint64_t alloc_unit);
38
7c673cae 39public:
f67539c2
TL
40 StupidAllocator(CephContext* cct,
41 const std::string& name,
42 int64_t size,
43 int64_t block_size);
7c673cae 44 ~StupidAllocator() override;
f67539c2
TL
45 const char* get_type() const override
46 {
47 return "stupid";
48 }
7c673cae 49
7c673cae
FG
50 int64_t allocate(
51 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
a8e16298 52 int64_t hint, PExtentVector *extents) override;
7c673cae
FG
53
54 int64_t allocate_int(
55 uint64_t want_size, uint64_t alloc_unit, int64_t hint,
56 uint64_t *offset, uint32_t *length);
57
58 void release(
a8e16298 59 const interval_set<uint64_t>& release_set) override;
7c673cae
FG
60
61 uint64_t get_free() override;
9f95a23c 62 double get_fragmentation() override;
7c673cae
FG
63
64 void dump() override;
eafe8130 65 void dump(std::function<void(uint64_t offset, uint64_t length)> notify) override;
7c673cae
FG
66
67 void init_add_free(uint64_t offset, uint64_t length) override;
68 void init_rm_free(uint64_t offset, uint64_t length) override;
69
70 void shutdown() override;
71};
72
73#endif