From 763d3905d93fa2cd3d0c413d76bb2cdc0a1c5e70 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 26 Apr 2018 09:57:00 -0500 Subject: [PATCH] common/PriorityCache: First pass at prototype. Signed-off-by: Mark Nelson (cherry picked from commit cb465411921ab01ea47b4ac1d37a29662213355b) Conflicts: src/os/bluestore/BlueStore.cc (trivial) --- src/CMakeLists.txt | 1 + src/common/PriorityCache.cc | 29 +++ src/common/PriorityCache.h | 69 +++++++ src/common/legacy_config_opts.h | 1 - src/common/options.cc | 22 ++- src/kv/KeyValueDB.h | 60 ++++++- src/kv/RocksDBStore.cc | 109 +++++++++-- src/kv/RocksDBStore.h | 20 ++- src/os/bluestore/BlueStore.cc | 310 +++++++++++++++++++++----------- src/os/bluestore/BlueStore.h | 129 ++++++++++++- 10 files changed, 603 insertions(+), 147 deletions(-) create mode 100644 src/common/PriorityCache.cc create mode 100644 src/common/PriorityCache.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 212658a064706..c5100a3cd75ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -544,6 +544,7 @@ set(libcommon_files common/dns_resolve.cc common/hostname.cc common/util.cc + common/PriorityCache.cc librbd/Features.cc arch/probe.cc ${auth_files} diff --git a/src/common/PriorityCache.cc b/src/common/PriorityCache.cc new file mode 100644 index 0000000000000..d62e61cc637ca --- /dev/null +++ b/src/common/PriorityCache.cc @@ -0,0 +1,29 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2018 Red Hat + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "PriorityCache.h" + +namespace PriorityCache { + int64_t get_chunk(uint64_t usage, uint64_t chunk_bytes) { + // Add a chunk of headroom and round up to the near chunk + uint64_t val = usage + chunk_bytes; + uint64_t r = (val) % chunk_bytes; + if (r > 0) + val = val + chunk_bytes - r; + return val; + } + + PriCache::~PriCache() { + } +} diff --git a/src/common/PriorityCache.h b/src/common/PriorityCache.h new file mode 100644 index 0000000000000..c31f896e5de6d --- /dev/null +++ b/src/common/PriorityCache.h @@ -0,0 +1,69 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2018 Red Hat + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#ifndef CEPH_PRIORITY_CACHE_H +#define CEPH_PRIORITY_CACHE_H + +#include +#include + +namespace PriorityCache { + enum Priority { + PRI0, // Reserved for special items + PRI1, // High priority cache items + PRI2, // Medium priority cache items + PRI3, // Low priority cache items + LAST = PRI3, + }; + + int64_t get_chunk(uint64_t usage, uint64_t chunk_bytes); + + struct PriCache { + virtual ~PriCache(); + + /* Ask the cache to request memory for the given priority rounded up to + * the nearst chunk_bytes. This for example, may return the size of all + * items associated with this priority plus some additional space for + * future growth. Note that the cache may ultimately be allocated less + * memory than it requests here. + */ + virtual int64_t request_cache_bytes(PriorityCache::Priority pri, uint64_t chunk_bytes) const = 0; + + // Get the number of bytes currently allocated to the given priority. + virtual int64_t get_cache_bytes(PriorityCache::Priority pri) const = 0; + + // Get the number of bytes currently allocated to all priorities. + virtual int64_t get_cache_bytes() const = 0; + + // Allocate bytes for a given priority. + virtual void set_cache_bytes(PriorityCache::Priority pri, int64_t bytes) = 0; + + // Allocate additional bytes for a given priority. + virtual void add_cache_bytes(PriorityCache::Priority pri, int64_t bytes) = 0; + + // Commit the current number of bytes allocated to the cache. + virtual int64_t commit_cache_size() = 0; + + // Get the ratio of available memory this cache should target. + virtual double get_cache_ratio() const = 0; + + // Set the ratio of available memory this cache should target. + virtual void set_cache_ratio(double ratio) = 0; + + // Get the name of this cache. + virtual std::string get_cache_name() const = 0; + }; +} + +#endif diff --git a/src/common/legacy_config_opts.h b/src/common/legacy_config_opts.h index 49f0bcf4519f6..4dc62a2e8b41f 100644 --- a/src/common/legacy_config_opts.h +++ b/src/common/legacy_config_opts.h @@ -1028,7 +1028,6 @@ OPTION(bluestore_cache_size_hdd, OPT_U64) OPTION(bluestore_cache_size_ssd, OPT_U64) OPTION(bluestore_cache_meta_ratio, OPT_DOUBLE) OPTION(bluestore_cache_kv_ratio, OPT_DOUBLE) -OPTION(bluestore_cache_kv_min, OPT_INT) OPTION(bluestore_kvbackend, OPT_STR) OPTION(bluestore_allocator, OPT_STR) // stupid | bitmap OPTION(bluestore_freelist_blocks_per_key, OPT_INT) diff --git a/src/common/options.cc b/src/common/options.cc index d58ecb168b226..b21e271311e12 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -4066,15 +4066,21 @@ std::vector