]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/PriorityCache.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / 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
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2018 Red Hat
7 *
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.
12 *
13 */
14
15 #include "PriorityCache.h"
16
17 namespace PriorityCache {
18 int64_t get_chunk(uint64_t usage, uint64_t total_bytes) {
19 uint64_t chunk = total_bytes;
20
21 // Find the nearest power of 2
22 chunk -= 1;
23 chunk |= chunk >> 1;
24 chunk |= chunk >> 2;
25 chunk |= chunk >> 4;
26 chunk |= chunk >> 8;
27 chunk |= chunk >> 16;
28 chunk |= chunk >> 32;
29 chunk += 1;
30 // shrink it to 1/256 of the rounded up cache size
31 chunk /= 256;
32
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;
36
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.
45 */
46 uint64_t val = usage + (16 * chunk);
47 uint64_t r = (val) % chunk;
48 if (r > 0)
49 val = val + chunk - r;
50 return val;
51 }
52
53 PriCache::~PriCache() {
54 }
55 }