]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/Allocator.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / os / bluestore / Allocator.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 * Ceph - scalable distributed file system
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 *
11 */
12#ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H
13#define CEPH_OS_BLUESTORE_ALLOCATOR_H
14
f67539c2 15#include <functional>
7c673cae 16#include <ostream>
11fdf7f2 17#include "include/ceph_assert.h"
f67539c2 18#include "bluestore_types.h"
7c673cae 19
7c673cae
FG
20class Allocator {
21public:
20effc67
TL
22 Allocator(std::string_view name,
23 int64_t _capacity,
24 int64_t _block_size);
eafe8130 25 virtual ~Allocator();
7c673cae 26
f67539c2
TL
27 /*
28 * returns allocator type name as per names in config
29 */
30 virtual const char* get_type() const = 0;
31
7c673cae
FG
32 /*
33 * Allocate required number of blocks in n number of extents.
34 * Min and Max number of extents are limited by:
35 * a. alloc unit
36 * b. max_alloc_size.
f67539c2 37 * as no extent can be lesser than block_size and greater than max_alloc size.
7c673cae
FG
38 * Apart from that extents can vary between these lower and higher limits according
39 * to free block search algorithm and availability of contiguous space.
40 */
f67539c2 41 virtual int64_t allocate(uint64_t want_size, uint64_t block_size,
7c673cae 42 uint64_t max_alloc_size, int64_t hint,
a8e16298 43 PExtentVector *extents) = 0;
7c673cae 44
f67539c2 45 int64_t allocate(uint64_t want_size, uint64_t block_size,
a8e16298 46 int64_t hint, PExtentVector *extents) {
f67539c2 47 return allocate(want_size, block_size, want_size, hint, extents);
7c673cae
FG
48 }
49
a8e16298
TL
50 /* Bulk release. Implementations may override this method to handle the whole
51 * set at once. This could save e.g. unnecessary mutex dance. */
52 virtual void release(const interval_set<uint64_t>& release_set) = 0;
53 void release(const PExtentVector& release_set);
7c673cae
FG
54
55 virtual void dump() = 0;
1e59de90
TL
56 virtual void foreach(
57 std::function<void(uint64_t offset, uint64_t length)> notify) = 0;
7c673cae
FG
58
59 virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
60 virtual void init_rm_free(uint64_t offset, uint64_t length) = 0;
61
62 virtual uint64_t get_free() = 0;
9f95a23c 63 virtual double get_fragmentation()
a8e16298
TL
64 {
65 return 0.0;
66 }
eafe8130 67 virtual double get_fragmentation_score();
7c673cae 68 virtual void shutdown() = 0;
eafe8130 69
20effc67
TL
70 static Allocator *create(
71 CephContext* cct,
72 std::string_view type,
73 int64_t size,
74 int64_t block_size,
75 int64_t zone_size = 0,
76 int64_t firs_sequential_zone = 0,
77 const std::string_view name = ""
78 );
e306af50 79
f67539c2 80
20effc67 81 const std::string& get_name() const;
f67539c2
TL
82 int64_t get_capacity() const
83 {
20effc67 84 return device_size;
f67539c2
TL
85 }
86 int64_t get_block_size() const
87 {
88 return block_size;
89 }
e306af50 90
eafe8130
TL
91private:
92 class SocketHook;
93 SocketHook* asok_hook = nullptr;
20effc67
TL
94protected:
95 const int64_t device_size = 0;
96 const int64_t block_size = 0;
7c673cae
FG
97};
98
99#endif