Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate table size of FastLRUCache more accurately #10235

Closed
wants to merge 13 commits into from
6 changes: 3 additions & 3 deletions cache/fast_lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ LRUCacheShard::LRUCacheShard(size_t capacity, size_t estimated_value_size,
: capacity_(capacity),
strict_capacity_limit_(strict_capacity_limit),
table_(
CalcHashBits(capacity, estimated_value_size, metadata_charge_policy) +
static_cast<uint8_t>(ceil(log2(1.0 / kLoadFactor)))),
CalcHashBits(capacity, estimated_value_size, metadata_charge_policy)),
usage_(0),
lru_usage_(0) {
set_metadata_charge_policy(metadata_charge_policy);
Expand Down Expand Up @@ -300,7 +299,8 @@ uint8_t LRUCacheShard::CalcHashBits(
CacheMetadataChargePolicy metadata_charge_policy) {
LRUHandle h;
h.CalcTotalCharge(estimated_value_size, metadata_charge_policy);
size_t num_entries = capacity / h.total_charge;
size_t num_entries =
guidotag marked this conversation as resolved.
Show resolved Hide resolved
static_cast<size_t>(capacity / (kLoadFactor * h.total_charge));
uint8_t num_hash_bits = 0;
while (num_entries >>= 1) {
++num_hash_bits;
Expand Down