]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/memory/memory_usage.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / memory / memory_usage.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7
8 #include <cstddef>
9 #include <unordered_map>
10 #ifdef USE_FOLLY
11 #include <folly/container/F14Map.h>
12 #endif
13
14 #include "rocksdb/rocksdb_namespace.h"
15
16 namespace ROCKSDB_NAMESPACE {
17
18 // Helper methods to estimate memroy usage by std containers.
19
20 template <class Key, class Value, class Hash>
21 size_t ApproximateMemoryUsage(
22 const std::unordered_map<Key, Value, Hash>& umap) {
23 using Map = std::unordered_map<Key, Value, Hash>;
24 return sizeof(umap) +
25 // Size of all items plus a next pointer for each item.
26 (sizeof(typename Map::value_type) + sizeof(void*)) * umap.size() +
27 // Size of hash buckets.
28 umap.bucket_count() * sizeof(void*);
29 }
30
31 #ifdef USE_FOLLY
32 template <class Key, class Value, class Hash>
33 size_t ApproximateMemoryUsage(const folly::F14FastMap<Key, Value, Hash>& umap) {
34 return sizeof(umap) + umap.getAllocatedMemorySize();
35 }
36 #endif
37
38 } // namespace ROCKSDB_NAMESPACE