]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/onode_manager/staged-fltree/tree_types.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / os / seastore / onode_manager / staged-fltree / tree_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <ostream>
7
8 namespace crimson::os::seastore::onode {
9
10 // TODO: Redesign according to real requirement from onode manager
11 struct onode_t {
12 // onode should be smaller than a node
13 uint16_t size; // address up to 64 KiB sized node
14 uint16_t id;
15 // omap, extent_map, inline data
16
17 bool operator==(const onode_t& o) const { return size == o.size && id == o.id; }
18 bool operator!=(const onode_t& o) const { return !(*this == o); }
19
20 void encode(ceph::bufferlist& encoded) const {
21 ceph::encode(size, encoded);
22 ceph::encode(id, encoded);
23 }
24 static onode_t decode(ceph::bufferlist::const_iterator& delta) {
25 uint16_t size;
26 ceph::decode(size, delta);
27 uint16_t id;
28 ceph::decode(id, delta);
29 onode_t ret{size, id};
30 return ret;
31 }
32 static void validate_tail_magic(const onode_t& onode) {
33 auto p_target = (const char*)&onode + onode.size - sizeof(uint32_t);
34 uint32_t target;
35 std::memcpy(&target, p_target, sizeof(uint32_t));
36 ceph_assert(target == onode.size * 137);
37 }
38 static std::unique_ptr<char[]> allocate(const onode_t& config) {
39 ceph_assert(config.size >= sizeof(onode_t) + sizeof(uint32_t));
40
41 auto ret = std::make_unique<char[]>(config.size);
42 char* p_mem = ret.get();
43 auto p_onode = reinterpret_cast<onode_t*>(p_mem);
44 *p_onode = config;
45
46 uint32_t tail_magic = config.size * 137;
47 p_mem += (config.size - sizeof(uint32_t));
48 std::memcpy(p_mem, &tail_magic, sizeof(uint32_t));
49 validate_tail_magic(*p_onode);
50
51 return ret;
52 }
53 } __attribute__((packed));
54 inline std::ostream& operator<<(std::ostream& os, const onode_t& node) {
55 return os << "onode(" << node.id << ", " << node.size << "B)";
56 }
57
58 struct tree_stats_t {
59 size_t size_persistent_leaf = 0;
60 size_t size_persistent_internal = 0;
61 size_t size_filled_leaf = 0;
62 size_t size_filled_internal = 0;
63 size_t size_logical_leaf = 0;
64 size_t size_logical_internal = 0;
65 size_t size_overhead_leaf = 0;
66 size_t size_overhead_internal = 0;
67 size_t size_value_leaf = 0;
68 size_t size_value_internal = 0;
69 unsigned num_kvs_leaf = 0;
70 unsigned num_kvs_internal = 0;
71 unsigned num_nodes_leaf = 0;
72 unsigned num_nodes_internal = 0;
73 unsigned height = 0;
74
75 size_t size_persistent() const {
76 return size_persistent_leaf + size_persistent_internal; }
77 size_t size_filled() const {
78 return size_filled_leaf + size_filled_internal; }
79 size_t size_logical() const {
80 return size_logical_leaf + size_logical_internal; }
81 size_t size_overhead() const {
82 return size_overhead_leaf + size_overhead_internal; }
83 size_t size_value() const {
84 return size_value_leaf + size_value_internal; }
85 unsigned num_kvs() const {
86 return num_kvs_leaf + num_kvs_internal; }
87 unsigned num_nodes() const {
88 return num_nodes_leaf + num_nodes_internal; }
89
90 double ratio_fullness() const {
91 return (double)size_filled() / size_persistent(); }
92 double ratio_key_compression() const {
93 return (double)(size_filled() - size_value()) / (size_logical() - size_value()); }
94 double ratio_overhead() const {
95 return (double)size_overhead() / size_filled(); }
96 double ratio_keys_leaf() const {
97 return (double)num_kvs_leaf / num_kvs(); }
98 double ratio_nodes_leaf() const {
99 return (double)num_nodes_leaf / num_nodes(); }
100 double ratio_filled_leaf() const {
101 return (double)size_filled_leaf / size_filled(); }
102 };
103 inline std::ostream& operator<<(std::ostream& os, const tree_stats_t& stats) {
104 os << "Tree stats:"
105 << "\n height = " << stats.height
106 << "\n num values = " << stats.num_kvs_leaf
107 << "\n num nodes = " << stats.num_nodes()
108 << " (leaf=" << stats.num_nodes_leaf
109 << ", internal=" << stats.num_nodes_internal << ")"
110 << "\n size persistent = " << stats.size_persistent() << "B"
111 << "\n size filled = " << stats.size_filled() << "B"
112 << " (value=" << stats.size_value_leaf << "B"
113 << ", rest=" << stats.size_filled() - stats.size_value_leaf << "B)"
114 << "\n size logical = " << stats.size_logical() << "B"
115 << "\n size overhead = " << stats.size_overhead() << "B"
116 << "\n ratio fullness = " << stats.ratio_fullness()
117 << "\n ratio keys leaf = " << stats.ratio_keys_leaf()
118 << "\n ratio nodes leaf = " << stats.ratio_nodes_leaf()
119 << "\n ratio filled leaf = " << stats.ratio_filled_leaf()
120 << "\n ratio key compression = " << stats.ratio_key_compression();
121 assert(stats.num_kvs_internal + 1 == stats.num_nodes());
122 return os;
123 }
124
125 }