Skip to content

Commit

Permalink
Merge pull request #24065 from jdurgin/wip-luminous-cache-autotune
Browse files Browse the repository at this point in the history
luminous: os/bluestore: cache autotuning and memory limit

Reviewed-by: Sage Weil <sage@redhat.com>
  • Loading branch information
yuriw committed Sep 24, 2018
2 parents 7ced091 + 802ea6c commit 8b61511
Show file tree
Hide file tree
Showing 17 changed files with 2,235 additions and 162 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -537,6 +537,7 @@ set(libcommon_files
common/dns_resolve.cc
common/hostname.cc
common/util.cc
common/PriorityCache.cc
arch/probe.cc
${auth_files}
${mds_files})
Expand Down
29 changes: 29 additions & 0 deletions 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() {
}
}
69 changes: 69 additions & 0 deletions 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 <stdint.h>
#include <string>

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

0 comments on commit 8b61511

Please sign in to comment.