]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/BitmapAllocator.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / os / bluestore / BitmapAllocator.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "BitmapAllocator.h"
5
6 #define dout_context cct
7 #define dout_subsys ceph_subsys_bluestore
8 #undef dout_prefix
9 #define dout_prefix *_dout << "fbmap_alloc " << this << " "
10
11 BitmapAllocator::BitmapAllocator(CephContext* _cct,
12 int64_t capacity,
13 int64_t alloc_unit,
14 const std::string& name) :
15 Allocator(name),
16 cct(_cct)
17 {
18 ldout(cct, 10) << __func__ << " 0x" << std::hex << capacity << "/"
19 << alloc_unit << std::dec << dendl;
20 _init(capacity, alloc_unit, false);
21 }
22
23 int64_t BitmapAllocator::allocate(
24 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
25 int64_t hint, PExtentVector *extents)
26 {
27 uint64_t allocated = 0;
28 size_t old_size = extents->size();
29 ldout(cct, 10) << __func__ << std::hex << " 0x" << want_size
30 << "/" << alloc_unit << "," << max_alloc_size << "," << hint
31 << std::dec << dendl;
32
33
34 _allocate_l2(want_size, alloc_unit, max_alloc_size, hint,
35 &allocated, extents);
36 if (!allocated) {
37 return -ENOSPC;
38 }
39 for (auto i = old_size; i < extents->size(); ++i) {
40 auto& e = (*extents)[i];
41 ldout(cct, 10) << __func__
42 << " extent: 0x" << std::hex << e.offset << "~" << e.length
43 << "/" << alloc_unit << "," << max_alloc_size << "," << hint
44 << std::dec << dendl;
45 }
46 return int64_t(allocated);
47 }
48
49 void BitmapAllocator::release(
50 const interval_set<uint64_t>& release_set)
51 {
52 for (auto r : release_set) {
53 ldout(cct, 10) << __func__ << " 0x" << std::hex << r.first << "~" << r.second
54 << std::dec << dendl;
55 }
56 _free_l2(release_set);
57 ldout(cct, 10) << __func__ << " done" << dendl;
58 }
59
60
61 void BitmapAllocator::init_add_free(uint64_t offset, uint64_t length)
62 {
63 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
64 << std::dec << dendl;
65
66 auto mas = get_min_alloc_size();
67 uint64_t offs = round_up_to(offset, mas);
68 uint64_t l = p2align(offset + length - offs, mas);
69
70 _mark_free(offs, l);
71 ldout(cct, 10) << __func__ << " done" << dendl;
72 }
73 void BitmapAllocator::init_rm_free(uint64_t offset, uint64_t length)
74 {
75 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
76 << std::dec << dendl;
77 auto mas = get_min_alloc_size();
78 uint64_t offs = round_up_to(offset, mas);
79 uint64_t l = p2align(offset + length - offs, mas);
80 _mark_allocated(offs, l);
81 ldout(cct, 10) << __func__ << " done" << dendl;
82 }
83
84 void BitmapAllocator::shutdown()
85 {
86 ldout(cct, 1) << __func__ << dendl;
87 _shutdown();
88 }
89
90 void BitmapAllocator::dump()
91 {
92 // bin -> interval count
93 std::map<size_t, size_t> bins_overall;
94 collect_stats(bins_overall);
95 auto it = bins_overall.begin();
96 while (it != bins_overall.end()) {
97 ldout(cct, 0) << __func__
98 << " bin " << it->first
99 << "(< " << byte_u_t((1 << (it->first + 1)) * get_min_alloc_size()) << ")"
100 << " : " << it->second << " extents"
101 << dendl;
102 ++it;
103 }
104 }
105
106 void BitmapAllocator::dump(std::function<void(uint64_t offset, uint64_t length)> notify)
107 {
108 size_t alloc_size = get_min_alloc_size();
109 auto multiply_by_alloc_size = [alloc_size, notify](size_t off, size_t len) {
110 notify(off * alloc_size, len * alloc_size);
111 };
112 std::lock_guard lck(lock);
113 l1.dump(multiply_by_alloc_size);
114 }