]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/Allocator.h
import 15.2.4
[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
15#include <ostream>
11fdf7f2 16#include "include/ceph_assert.h"
7c673cae 17#include "os/bluestore/bluestore_types.h"
eafe8130 18#include <functional>
7c673cae 19
7c673cae
FG
20class Allocator {
21public:
eafe8130
TL
22 explicit Allocator(const std::string& name);
23 virtual ~Allocator();
7c673cae 24
7c673cae
FG
25 /*
26 * Allocate required number of blocks in n number of extents.
27 * Min and Max number of extents are limited by:
28 * a. alloc unit
29 * b. max_alloc_size.
30 * as no extent can be lesser than alloc_unit and greater than max_alloc size.
31 * Apart from that extents can vary between these lower and higher limits according
32 * to free block search algorithm and availability of contiguous space.
33 */
34 virtual int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
35 uint64_t max_alloc_size, int64_t hint,
a8e16298 36 PExtentVector *extents) = 0;
7c673cae
FG
37
38 int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
a8e16298 39 int64_t hint, PExtentVector *extents) {
7c673cae
FG
40 return allocate(want_size, alloc_unit, want_size, hint, extents);
41 }
42
a8e16298
TL
43 /* Bulk release. Implementations may override this method to handle the whole
44 * set at once. This could save e.g. unnecessary mutex dance. */
45 virtual void release(const interval_set<uint64_t>& release_set) = 0;
46 void release(const PExtentVector& release_set);
7c673cae
FG
47
48 virtual void dump() = 0;
eafe8130 49 virtual void dump(std::function<void(uint64_t offset, uint64_t length)> notify) = 0;
7c673cae
FG
50
51 virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
52 virtual void init_rm_free(uint64_t offset, uint64_t length) = 0;
53
54 virtual uint64_t get_free() = 0;
9f95a23c 55 virtual double get_fragmentation()
a8e16298
TL
56 {
57 return 0.0;
58 }
eafe8130 59 virtual double get_fragmentation_score();
7c673cae 60 virtual void shutdown() = 0;
eafe8130 61
7c673cae 62 static Allocator *create(CephContext* cct, string type, int64_t size,
eafe8130 63 int64_t block_size, const std::string& name = "");
e306af50
TL
64
65 const string& get_name() const;
66
eafe8130
TL
67private:
68 class SocketHook;
69 SocketHook* asok_hook = nullptr;
7c673cae
FG
70};
71
72#endif