]>
git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/ZonedFreelistManager.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 // A freelist manager for zoned devices. This iteration just keeps the write
6 // pointer per zone. Following iterations will add enough information to enable
9 // Copyright (C) 2020 Abutalib Aghayev
12 #ifndef CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H
13 #define CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H
15 #include "FreelistManager.h"
20 #include "common/ceph_mutex.h"
21 #include "include/buffer.h"
22 #include "kv/KeyValueDB.h"
24 using cfg_reader_t
= std::function
<int(const std::string
&, std::string
*)>;
26 class ZonedFreelistManager
: public FreelistManager
{
27 std::string meta_prefix
; ///< device size, zone size, etc.
28 std::string info_prefix
; ///< per zone write pointer, dead bytes
29 mutable ceph::mutex lock
= ceph::make_mutex("ZonedFreelistManager::lock");
31 uint64_t size
; ///< size of sequential region (bytes)
32 uint64_t bytes_per_block
; ///< bytes per allocation unit (bytes)
33 uint64_t zone_size
; ///< size of a single zone (bytes)
34 uint64_t num_zones
; ///< number of sequential zones
35 uint64_t starting_zone_num
; ///< the first sequential zone number
37 KeyValueDB::Iterator enumerate_p
;
38 uint64_t enumerate_zone_num
;
40 void write_zone_state_to_db(uint64_t zone_num
,
41 const zone_state_t
&zone_state
,
42 KeyValueDB::Transaction txn
);
43 void load_zone_state_from_db(uint64_t zone_num
,
44 zone_state_t
&zone_state
,
45 KeyValueDB::Iterator
&it
) const;
47 void init_zone_states(KeyValueDB::Transaction txn
);
49 void increment_write_pointer(
50 uint64_t zone
, uint64_t length
, KeyValueDB::Transaction txn
);
51 void increment_num_dead_bytes(
52 uint64_t zone
, uint64_t num_bytes
, KeyValueDB::Transaction txn
);
54 int _read_cfg(cfg_reader_t cfg_reader
);
57 ZonedFreelistManager(CephContext
* cct
,
58 std::string meta_prefix
,
59 std::string info_prefix
);
61 static void setup_merge_operator(KeyValueDB
*db
, std::string prefix
);
63 int create(uint64_t size
,
65 KeyValueDB::Transaction txn
) override
;
67 int init(KeyValueDB
*kvdb
,
69 cfg_reader_t cfg_reader
) override
;
71 void shutdown() override
;
72 void sync(KeyValueDB
* kvdb
) override
;
73 void dump(KeyValueDB
*kvdb
) override
;
75 void enumerate_reset() override
;
76 bool enumerate_next(KeyValueDB
*kvdb
,
78 uint64_t *length
) override
;
80 void allocate(uint64_t offset
,
82 KeyValueDB::Transaction txn
) override
;
84 void release(uint64_t offset
,
86 KeyValueDB::Transaction txn
) override
;
88 inline uint64_t get_size() const override
{
92 inline uint64_t get_alloc_units() const override
{
93 return size
/ bytes_per_block
;
96 inline uint64_t get_alloc_size() const override
{
97 return bytes_per_block
;
100 void get_meta(uint64_t target_size
,
101 std::vector
<std::pair
<string
, string
>>*) const override
;
103 std::vector
<zone_state_t
> get_zone_states(KeyValueDB
*kvdb
) const override
;