]>
git.proxmox.com Git - ceph.git/blob - 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
4 #ifndef CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H
5 #define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_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 #include "common/ceph_mutex.h"
16 class StupidAllocator
: public Allocator
{
18 ceph::mutex lock
= ceph::make_mutex("StupidAllocator::lock");
20 int64_t num_free
; ///< total bytes in freelist
22 template <typename K
, typename V
> using allocator_t
=
23 mempool::bluestore_alloc::pool_allocator
<std::pair
<const K
, V
>>;
24 template <typename K
, typename V
> using btree_map_t
=
25 btree::btree_map
<K
, V
, std::less
<K
>, allocator_t
<K
, V
>>;
26 using interval_set_t
= interval_set
<uint64_t, btree_map_t
>;
27 std::vector
<interval_set_t
> free
; ///< leading-edge copy
29 uint64_t last_alloc
= 0;
31 unsigned _choose_bin(uint64_t len
);
32 void _insert_free(uint64_t offset
, uint64_t len
);
35 StupidAllocator(CephContext
* cct
,
38 std::string_view name
);
39 ~StupidAllocator() override
;
40 const char* get_type() const override
46 uint64_t want_size
, uint64_t alloc_unit
, uint64_t max_alloc_size
,
47 int64_t hint
, PExtentVector
*extents
) override
;
50 uint64_t want_size
, uint64_t alloc_unit
, int64_t hint
,
51 uint64_t *offset
, uint32_t *length
);
54 const interval_set
<uint64_t>& release_set
) override
;
56 uint64_t get_free() override
;
57 double get_fragmentation() override
;
60 void foreach(std::function
<void(uint64_t offset
, uint64_t length
)> notify
) override
;
62 void init_add_free(uint64_t offset
, uint64_t length
) override
;
63 void init_rm_free(uint64_t offset
, uint64_t length
) override
;
65 void shutdown() override
;