feat(server): Enforce decomitting memory pages upon flushdb call (#337)

This fixes #322 though some memory is still kept by memory allocator.
Tested by running:
1. debug populate 20000000 key 256
2. info memory
3. flushdb
4. info memory

Verified that the rss memory usage decreased from 5.07GB to 1.71GB
This commit is contained in:
Roman Gershman 2022-09-29 14:01:22 +03:00 committed by GitHub
parent ac90aecde1
commit b74d65dee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -13,6 +13,7 @@ extern "C" {
#include "base/logging.h"
#include "server/engine_shard_set.h"
#include "server/server_state.h"
#include "server/tiered_storage.h"
#include "util/fiber_sched_algo.h"
#include "util/proactor_base.h"
@ -61,8 +62,8 @@ class PrimeEvictionPolicy {
static constexpr bool can_evict = true; // we implement eviction functionality.
static constexpr bool can_gc = true;
PrimeEvictionPolicy(const DbContext& cntx, bool can_evict, ssize_t mem_budget,
ssize_t soft_limit, DbSlice* db_slice)
PrimeEvictionPolicy(const DbContext& cntx, bool can_evict, ssize_t mem_budget, ssize_t soft_limit,
DbSlice* db_slice)
: db_slice_(db_slice), mem_budget_(mem_budget), soft_limit_(soft_limit), cntx_(cntx),
can_evict_(can_evict) {
}
@ -471,7 +472,12 @@ void DbSlice::FlushDb(DbIndex db_ind) {
CreateDb(db_ind);
db_arr_[db_ind]->trans_locks.swap(db_ptr->trans_locks);
boost::fibers::fiber([db_ptr = std::move(db_ptr)]() mutable { db_ptr.reset(); }).detach();
auto cb = [db_ptr = std::move(db_ptr)]() mutable {
db_ptr.reset();
mi_heap_collect(ServerState::tlocal()->data_heap(), true);
};
boost::fibers::fiber(std::move(cb)).detach();
return;
}