]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/PriorityCache.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2018 Red Hat
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "PriorityCache.h"
17 namespace PriorityCache
{
18 int64_t get_chunk(uint64_t usage
, uint64_t total_bytes
) {
19 uint64_t chunk
= total_bytes
;
21 // Find the nearest power of 2
30 // shrink it to 1/256 of the rounded up cache size
33 // bound the chunk size to be between 4MB and 32MB
34 chunk
= (chunk
> 4ul*1024*1024) ? chunk
: 4ul*1024*1024;
35 chunk
= (chunk
< 16ul*1024*1024) ? chunk
: 16ul*1024*1024;
37 /* Add 16 chunks of headroom and round up to the near chunk. Note that
38 * if RocksDB is used, it's a good idea to have N MB of headroom where
39 * N is the target_file_size_base value. RocksDB will read SST files
40 * into the block cache during compaction which potentially can force out
41 * all existing cached data. Once compaction is finished, the SST data is
42 * released leaving an empty cache. Having enough headroom to absorb
43 * compaction reads allows the kv cache grow even during extremely heavy
44 * compaction workloads.
46 uint64_t val
= usage
+ (16 * chunk
);
47 uint64_t r
= (val
) % chunk
;
49 val
= val
+ chunk
- r
;
53 PriCache::~PriCache() {