mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-17 16:31:27 -04:00
Limit LRU cache size
This commit is contained in:
parent
ed24a60062
commit
629f3a4177
@ -268,7 +268,11 @@ class block_cache_ : public block_cache::impl {
|
|||||||
void set_block_size(size_t size) override {
|
void set_block_size(size_t size) override {
|
||||||
// XXX: This currently inevitably clears the cache
|
// XXX: This currently inevitably clears the cache
|
||||||
auto max_blocks = std::max<size_t>(options_.max_bytes / size, 1);
|
auto max_blocks = std::max<size_t>(options_.max_bytes / size, 1);
|
||||||
{
|
|
||||||
|
if (!block_.empty() && max_blocks > block_.size()) {
|
||||||
|
max_blocks = block_.size();
|
||||||
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
cache_.~lru_type();
|
cache_.~lru_type();
|
||||||
new (&cache_) lru_type(max_blocks);
|
new (&cache_) lru_type(max_blocks);
|
||||||
@ -282,7 +286,6 @@ class block_cache_ : public block_cache::impl {
|
|||||||
update_block_stats(*block);
|
update_block_stats(*block);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::future<block_range>
|
std::future<block_range>
|
||||||
get(size_t block_no, size_t offset, size_t size) const override {
|
get(size_t block_no, size_t offset, size_t size) const override {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user