Skip to content

Commit

Permalink
Rebase and address Ping commnt
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Sep 26, 2024
1 parent 4083898 commit 35437eb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ static int updateMaxmemoryReserved(const char **err) {
server.maxmemory_reserved_scale = 60;
}
}
server.maxmemory_available = (unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_reserved_scale);
calculateMaxAvailableMemory();
return 1;
}

Expand All @@ -2524,8 +2524,7 @@ static int updateMaxmemory(const char **err) {
"depending on the maxmemory-policy.",
server.maxmemory, used);
}
server.maxmemory_available =
(unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_reserved_scale);
calculateMaxAvailableMemory();
startEvictionTimeProc();
}
return 1;
Expand Down
23 changes: 6 additions & 17 deletions src/evict.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev

if (server.maxmemory_reserved_scale) {
if (mem_reported <= server.maxmemory_available && !level) return C_OK;
} else if (mem_reported <= server.maxmemory && !level)
} else if (mem_reported <= server.maxmemory && !level) {
return C_OK;
}

/* Remove the size of replicas output buffers and AOF buffer from the
* count of used memory. */
Expand All @@ -416,28 +417,16 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev

/* Compute the ratio of memory usage. */
if (level) {
if (server.maxmemory_reserved_scale)
*level = (float)mem_used / (float)server.maxmemory_available;
else
*level = (float)mem_used / (float)server.maxmemory;
*level = (float)mem_used / (float)server.maxmemory_available;
}

if (server.maxmemory_reserved_scale) {
if (mem_reported <= server.maxmemory_available) return C_OK;
} else if (mem_reported <= server.maxmemory)
return C_OK;
if (mem_reported <= server.maxmemory_available) return C_OK;

/* Check if we are still over the memory limit. */
if (server.maxmemory_reserved_scale) {
if (mem_used <= server.maxmemory_available) return C_OK;
} else if (mem_used <= server.maxmemory)
return C_OK;
if (mem_used <= server.maxmemory_available) return C_OK;

/* Compute how much memory we need to free. */
if (server.maxmemory_reserved_scale) {
mem_tofree = mem_used - server.maxmemory_available;
} else
mem_tofree = mem_used - server.maxmemory;
mem_tofree = mem_used - server.maxmemory_available;

if (logical) *logical = mem_used;
if (tofree) *tofree = mem_tofree;
Expand Down
3 changes: 1 addition & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2622,8 +2622,7 @@ void initServer(void) {
resetReplicationBuffer();

if (server.maxmemory) {
server.maxmemory_available =
(unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_reserved_scale);
calculateMaxAvailableMemory();
}

/* Make sure the locale is set on startup based on the config file. */
Expand Down
3 changes: 3 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,9 @@ void trimStringObjectIfNeeded(robj *o, int trim_small_values);
static inline int canUseSharedObject(void) {
return server.maxmemory == 0 || !(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS);
}
static inline void calculateMaxAvailableMemory(void) {
server.maxmemory_available = (unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_reserved_scale);
}
#define sdsEncodedObject(objptr) (objptr->encoding == OBJ_ENCODING_RAW || objptr->encoding == OBJ_ENCODING_EMBSTR)

/* Synchronous I/O with timeout */
Expand Down

0 comments on commit 35437eb

Please sign in to comment.