]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/BitmapAllocator.cc
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / os / bluestore / BitmapAllocator.cc
CommitLineData
a8e16298
TL
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
11BitmapAllocator::BitmapAllocator(CephContext* _cct,
12 int64_t capacity,
13 int64_t alloc_unit) :
14 cct(_cct)
15{
16 ldout(cct, 10) << __func__ << " 0x" << std::hex << capacity << "/"
17 << alloc_unit << std::dec << dendl;
18 _init(capacity, alloc_unit, false);
19}
20
21int64_t BitmapAllocator::allocate(
22 uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
23 int64_t hint, PExtentVector *extents)
24{
25 uint64_t allocated = 0;
81eedcae 26 size_t old_size = extents->size();
a8e16298
TL
27 ldout(cct, 10) << __func__ << std::hex << " 0x" << want_size
28 << "/" << alloc_unit << "," << max_alloc_size << "," << hint
29 << std::dec << dendl;
30
31
32 _allocate_l2(want_size, alloc_unit, max_alloc_size, hint,
33 &allocated, extents);
34 if (!allocated) {
35 return -ENOSPC;
36 }
81eedcae
TL
37 for (auto i = old_size; i < extents->size(); ++i) {
38 auto& e = (*extents)[i];
a8e16298 39 ldout(cct, 10) << __func__
81eedcae 40 << " extent: 0x" << std::hex << e.offset << "~" << e.length
a8e16298
TL
41 << "/" << alloc_unit << "," << max_alloc_size << "," << hint
42 << std::dec << dendl;
43 }
44 return int64_t(allocated);
45}
46
47void BitmapAllocator::release(
48 const interval_set<uint64_t>& release_set)
49{
50 for (auto r : release_set) {
51 ldout(cct, 10) << __func__ << " 0x" << std::hex << r.first << "~" << r.second
52 << std::dec << dendl;
53 }
54 _free_l2(release_set);
55 ldout(cct, 10) << __func__ << " done" << dendl;
56}
57
58
59void BitmapAllocator::init_add_free(uint64_t offset, uint64_t length)
60{
61 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
62 << std::dec << dendl;
63
64 auto mas = get_min_alloc_size();
11fdf7f2
TL
65 uint64_t offs = round_up_to(offset, mas);
66 uint64_t l = p2align(offset + length - offs, mas);
a8e16298
TL
67
68 _mark_free(offs, l);
69 ldout(cct, 10) << __func__ << " done" << dendl;
70}
71void BitmapAllocator::init_rm_free(uint64_t offset, uint64_t length)
72{
73 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
74 << std::dec << dendl;
75 auto mas = get_min_alloc_size();
11fdf7f2
TL
76 uint64_t offs = round_up_to(offset, mas);
77 uint64_t l = p2align(offset + length - offs, mas);
a8e16298
TL
78 _mark_allocated(offs, l);
79 ldout(cct, 10) << __func__ << " done" << dendl;
80}
81
82void BitmapAllocator::shutdown()
83{
84 ldout(cct, 1) << __func__ << dendl;
85 _shutdown();
86}
87
88void BitmapAllocator::dump()
89{
90 // bin -> interval count
91 std::map<size_t, size_t> bins_overall;
92 collect_stats(bins_overall);
93 auto it = bins_overall.begin();
94 while (it != bins_overall.end()) {
95 ldout(cct, 0) << __func__
96 << " bin " << it->first
97 << "(< " << byte_u_t((1 << (it->first + 1)) * get_min_alloc_size()) << ")"
98 << " : " << it->second << " extents"
99 << dendl;
100 ++it;
101 }
102}