Minor optimize getMaxmemoryState, when server.maxmemory is not set (#9533)

Minor optimize getMaxmemoryState, when server.maxmemory is not set,
don't count AOF and replicas buffers.

Co-authored-by: Viktor Söderqvist <viktor@zuiderkwast.se>
This commit is contained in:
Huang Zhw 2021-09-23 22:12:11 +08:00 committed by GitHub
parent bebc7f8470
commit f0fab99d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -380,8 +380,11 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
if (total) *total = mem_reported;
/* We may return ASAP if there is no need to compute the level. */
int return_ok_asap = !server.maxmemory || mem_reported <= server.maxmemory;
if (return_ok_asap && !level) return C_OK;
if (!server.maxmemory) {
if (level) *level = 0;
return C_OK;
}
if (mem_reported <= server.maxmemory && !level) return C_OK;
/* Remove the size of slaves output buffers and AOF buffer from the
* count of used memory. */
@ -390,15 +393,9 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
mem_used = (mem_used > overhead) ? mem_used-overhead : 0;
/* Compute the ratio of memory usage. */
if (level) {
if (!server.maxmemory) {
*level = 0;
} else {
*level = (float)mem_used / (float)server.maxmemory;
}
}
if (level) *level = (float)mem_used / (float)server.maxmemory;
if (return_ok_asap) return C_OK;
if (mem_reported <= server.maxmemory) return C_OK;
/* Check if we are still over the memory limit. */
if (mem_used <= server.maxmemory) return C_OK;