blob: 3a1a4a28f0e6512f7d913d6226dad01547958aff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "bucket_stripe_utils.h"
#include <vespa/vespalib/util/alloc.h>
#include <cassert>
namespace storage {
namespace {
constexpr uint8_t used_bits_of(uint64_t key) noexcept {
return static_cast<uint8_t>(key & 0b11'1111ULL);
}
}
size_t
stripe_of_bucket_key(uint64_t key, uint8_t n_stripe_bits) noexcept
{
if (n_stripe_bits == 0) {
return 0;
}
assert(used_bits_of(key) >= n_stripe_bits);
// Since bucket keys have count-bits at the LSB positions, we want to look at the MSBs instead.
return (key >> (64 - n_stripe_bits));
}
uint8_t
calc_num_stripe_bits(uint32_t n_stripes) noexcept
{
assert(n_stripes > 0);
if (n_stripes == 1) {
return 0;
}
assert(n_stripes == adjusted_num_stripes(n_stripes));
auto result = vespalib::Optimized::msbIdx(n_stripes);
assert(result <= MaxStripeBits);
return result;
}
uint32_t
adjusted_num_stripes(uint32_t n_stripes) noexcept
{
if (n_stripes > 1) {
if (n_stripes > MaxStripes) {
return MaxStripes;
}
return vespalib::roundUp2inN(n_stripes);
}
return n_stripes;
}
uint32_t
tune_num_stripes_based_on_cpu_cores(uint32_t cpu_cores) noexcept
{
// This should match the calculation used when node flavor is available:
// config-model/src/main/java/com/yahoo/vespa/model/content/Distributor.java
if (cpu_cores <= 16) {
return 1;
} else if (cpu_cores <= 64) {
return 2;
} else {
return 4;
}
}
}
|