]>
git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/ZonedAllocator.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 // A simple allocator that just hands out space from the next empty zone. This
6 // is temporary, just to get the simplest append-only write workload to work.
8 // Copyright (C) 2020 Abutalib Aghayev
11 #ifndef CEPH_OS_BLUESTORE_ZONEDALLOCATOR_H
12 #define CEPH_OS_BLUESTORE_ZONEDALLOCATOR_H
16 #include "Allocator.h"
17 #include "common/ceph_mutex.h"
18 #include "include/btree_map.h"
19 #include "include/interval_set.h"
20 #include "include/mempool.h"
21 #include "bluestore_types.h"
22 #include "zoned_types.h"
24 class ZonedAllocator
: public Allocator
{
27 // Currently only one thread at a time calls into ZonedAllocator due to
28 // atomic_alloc_and_submit_lock in BlueStore.cc, but we do locking anyway
29 // because eventually ZONE_APPEND support will land and
30 // atomic_alloc_and_submit_lock will be removed.
31 ceph::mutex lock
= ceph::make_mutex("ZonedAllocator::lock");
33 std::atomic
<int64_t> num_free
; ///< total bytes in freelist
37 uint64_t starting_zone_num
;
39 std::vector
<zone_state_t
> zone_states
;
41 inline uint64_t get_offset(uint64_t zone_num
) const {
42 return zone_num
* zone_size
+ get_write_pointer(zone_num
);
45 inline uint64_t get_write_pointer(uint64_t zone_num
) const {
46 return zone_states
[zone_num
].get_write_pointer();
49 inline uint64_t get_remaining_space(uint64_t zone_num
) const {
50 return zone_size
- get_write_pointer(zone_num
);
53 inline void advance_write_pointer(uint64_t zone_num
, uint64_t want_size
) {
54 zone_states
[zone_num
].increment_write_pointer(want_size
);
57 inline bool fits(uint64_t want_size
, uint64_t zone_num
) const {
58 return want_size
<= get_remaining_space(zone_num
);
62 ZonedAllocator(CephContext
* cct
, int64_t size
, int64_t block_size
,
63 const std::string
& name
);
64 ~ZonedAllocator() override
;
66 const char *get_type() const override
{
71 uint64_t want_size
, uint64_t alloc_unit
, uint64_t max_alloc_size
,
72 int64_t hint
, PExtentVector
*extents
) override
;
74 void release(const interval_set
<uint64_t>& release_set
) override
;
76 uint64_t get_free() override
;
79 void dump(std::function
<void(uint64_t offset
,
80 uint64_t length
)> notify
) override
;
82 void zoned_set_zone_states(std::vector
<zone_state_t
> &&_zone_states
) override
;
83 bool zoned_get_zones_to_clean(std::deque
<uint64_t> *zones_to_clean
) override
;
85 void init_add_free(uint64_t offset
, uint64_t length
) override
;
86 void init_rm_free(uint64_t offset
, uint64_t length
) override
;
88 void shutdown() override
;