sync wash fragment for kvcache alloc when memory not enough

This commit is contained in:
tushicheng
2023-08-01 16:18:45 +00:00
committed by ob-robot
parent da985e136d
commit a70113f97e
2 changed files with 34 additions and 2 deletions

View File

@ -372,7 +372,9 @@ int64_t ObTenantCtxAllocator::sync_wash(int64_t wash_size)
auto stat = obj_mgr_.get_stat();
const double min_utilization = 0.95;
if (stat.payload_ * min_utilization > stat.used_) {
int64_t min_memory_fragment = 64LL << 20;
if (stat.payload_ * min_utilization > stat.used_ ||
stat.payload_ - stat.used_ >= min_memory_fragment) {
washed_size = obj_mgr_.sync_wash(wash_size);
}
if (washed_size != 0 && REACH_TIME_INTERVAL(1 * 1000 * 1000)) {
@ -459,7 +461,7 @@ void* ObTenantCtxAllocator::common_realloc(const void *ptr, const int64_t size,
bool sample_allowed = ObMallocSampleLimiter::malloc_sample_allowed(size, attr);
const int64_t alloc_size = sample_allowed ? (size + AOBJECT_BACKTRACE_SIZE) : size;
obj = allocator.realloc_object(obj, alloc_size, attr);
if(OB_ISNULL(obj) && g_alloc_failed_ctx().need_wash()) {
if (OB_ISNULL(obj) && g_alloc_failed_ctx().need_wash()) {
int64_t total_size = ta.sync_wash();
obj = allocator.realloc_object(obj, alloc_size, attr);
}

View File

@ -53,6 +53,14 @@ protected:
virtual bool mb_status_match(ObKVCacheInst &inst,
const enum ObKVCachePolicy policy, MBWrapper *mb_wrapper) = 0;
virtual int64_t get_block_size() const = 0;
private:
int alloc_kvpair_without_retry(
ObKVCacheInst &inst,
const int64_t key_size,
const int64_t value_size,
ObKVCachePair *&kvpair,
MBWrapper *&mb_wrapper,
const enum ObKVCachePolicy policy);
};
class ObKVCacheStore : public ObIKVCacheStore<ObKVMemBlockHandle>,
@ -284,6 +292,28 @@ int ObIKVCacheStore<MBWrapper>::alloc_kvpair(
ObKVCachePair *&kvpair,
MBWrapper *&mb_wrapper,
const enum ObKVCachePolicy policy)
{
int ret = OB_SUCCESS;
int64_t tenant_id = inst.tenant_id_;
ret = alloc_kvpair_without_retry(inst, key_size, value_size, kvpair, mb_wrapper, policy);
if (OB_ALLOCATE_MEMORY_FAILED == ret) {
int64_t washed_size = ObMallocAllocator::get_instance()->sync_wash(tenant_id, 0, INT64_MAX);
if (washed_size > 0) {
ret = alloc_kvpair_without_retry(inst, key_size, value_size, kvpair, mb_wrapper, policy);
COMMON_LOG(INFO, "[MEM][WASH] sync wash succeed", K(ret), K(tenant_id), K(washed_size));
}
}
return ret;
}
template <typename MBWrapper>
int ObIKVCacheStore<MBWrapper>::alloc_kvpair_without_retry(
ObKVCacheInst &inst,
const int64_t key_size,
const int64_t value_size,
ObKVCachePair *&kvpair,
MBWrapper *&mb_wrapper,
const enum ObKVCachePolicy policy)
{
int ret = common::OB_SUCCESS;
const int64_t block_size = get_block_size();