use enum class
This commit is contained in:
parent
b5a20a4f91
commit
872c60566f
@ -66,6 +66,11 @@ struct evictionPoolEntry {
|
|||||||
|
|
||||||
static struct evictionPoolEntry *EvictionPoolLRU;
|
static struct evictionPoolEntry *EvictionPoolLRU;
|
||||||
|
|
||||||
|
enum class EvictReason {
|
||||||
|
User, /* User memory exceeded limit */
|
||||||
|
System /* System memory exceeded limit */
|
||||||
|
};
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Implementation of eviction, aging and LRU
|
* Implementation of eviction, aging and LRU
|
||||||
* --------------------------------------------------------------------------*/
|
* --------------------------------------------------------------------------*/
|
||||||
@ -420,7 +425,7 @@ size_t freeMemoryGetNotCountedMemory(void) {
|
|||||||
* EVICT_REASON_SYS: available system memory under configurable threshold
|
* EVICT_REASON_SYS: available system memory under configurable threshold
|
||||||
* (Populated when C_ERR is returned)
|
* (Populated when C_ERR is returned)
|
||||||
*/
|
*/
|
||||||
int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level, int *reason, bool fQuickCycle, bool fPreSnapshot) {
|
int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level, EvictReason *reason, bool fQuickCycle, bool fPreSnapshot) {
|
||||||
size_t mem_reported, mem_used, mem_tofree;
|
size_t mem_reported, mem_used, mem_tofree;
|
||||||
|
|
||||||
/* Check if we are over the memory usage limit. If we are not, no need
|
/* Check if we are over the memory usage limit. If we are not, no need
|
||||||
@ -485,7 +490,7 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
|
|||||||
if (logical) *logical = mem_used;
|
if (logical) *logical = mem_used;
|
||||||
if (tofree) *tofree = mem_tofree;
|
if (tofree) *tofree = mem_tofree;
|
||||||
|
|
||||||
if (reason) *reason = sys_available_mem_buffer < 0 ? EVICT_REASON_SYS : EVICT_REASON_USER;
|
if (reason) *reason = sys_available_mem_buffer < 0 ? EvictReason::System : EvictReason::User;
|
||||||
|
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
@ -675,7 +680,7 @@ int performEvictions(bool fPreSnapshot) {
|
|||||||
const bool fEvictToStorage = !cserver.delete_on_evict && g_pserver->db[0]->FStorageProvider();
|
const bool fEvictToStorage = !cserver.delete_on_evict && g_pserver->db[0]->FStorageProvider();
|
||||||
int result = EVICT_FAIL;
|
int result = EVICT_FAIL;
|
||||||
int ckeysFailed = 0;
|
int ckeysFailed = 0;
|
||||||
int evictReason;
|
EvictReason evictReason;
|
||||||
|
|
||||||
std::unique_ptr<FreeMemoryLazyFree> splazy = std::make_unique<FreeMemoryLazyFree>();
|
std::unique_ptr<FreeMemoryLazyFree> splazy = std::make_unique<FreeMemoryLazyFree>();
|
||||||
|
|
||||||
@ -862,7 +867,7 @@ int performEvictions(bool fPreSnapshot) {
|
|||||||
* across the dbAsyncDelete() call, while the thread can
|
* across the dbAsyncDelete() call, while the thread can
|
||||||
* release the memory all the time. */
|
* release the memory all the time. */
|
||||||
if (g_pserver->lazyfree_lazy_eviction) {
|
if (g_pserver->lazyfree_lazy_eviction) {
|
||||||
if (evictReason == EVICT_REASON_SYS) {
|
if (evictReason == EvictReason::System) {
|
||||||
updateSysAvailableMemory();
|
updateSysAvailableMemory();
|
||||||
}
|
}
|
||||||
if (getMaxmemoryState(NULL,NULL,NULL,NULL) == C_OK) {
|
if (getMaxmemoryState(NULL,NULL,NULL,NULL) == C_OK) {
|
||||||
@ -895,7 +900,7 @@ int performEvictions(bool fPreSnapshot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cant_free:
|
cant_free:
|
||||||
if (mem_freed > 0 && evictReason == EVICT_REASON_SYS) {
|
if (mem_freed > 0 && evictReason == EvictReason::System) {
|
||||||
updateSysAvailableMemory();
|
updateSysAvailableMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3662,9 +3662,6 @@ unsigned long LFUDecrAndReturn(robj_roptr o);
|
|||||||
#define EVICT_RUNNING 1
|
#define EVICT_RUNNING 1
|
||||||
#define EVICT_FAIL 2
|
#define EVICT_FAIL 2
|
||||||
int performEvictions(bool fPreSnapshot);
|
int performEvictions(bool fPreSnapshot);
|
||||||
#define EVICT_REASON_NONE 0
|
|
||||||
#define EVICT_REASON_USER 1
|
|
||||||
#define EVICT_REASON_SYS 2
|
|
||||||
|
|
||||||
/* meminfo.cpp -- get memory info from /proc/memoryinfo for linux distros */
|
/* meminfo.cpp -- get memory info from /proc/memoryinfo for linux distros */
|
||||||
size_t getMemAvailable();
|
size_t getMemAvailable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user