Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
129f2d27
Commit
129f2d27
authored
Dec 12, 2018
by
antirez
Browse files
freeMemoryIfNeeded() small refactoring.
Related to issue #5686 and PR #5689.
parent
7ae184bf
Changes
4
Show whitespace changes
Inline
Side-by-side
src/config.c
View file @
129f2d27
...
...
@@ -1248,7 +1248,7 @@ void configSetCommand(client *c) {
if
(
server
.
maxmemory
<
zmalloc_used_memory
())
{
serverLog
(
LL_WARNING
,
"WARNING: the new maxmemory value set via CONFIG SET is smaller than the current memory usage. This will result in key eviction and/or the inability to accept new write commands depending on the maxmemory-policy."
);
}
freeMemoryIfNeeded
();
freeMemoryIfNeeded
AndSafe
();
}
}
config_set_memory_field
(
"proto-max-bulk-len"
,
server
.
proto_max_bulk_len
)
{
...
...
src/evict.c
View file @
129f2d27
...
...
@@ -445,14 +445,8 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
* was freed to return back under the limit, the function returns C_ERR. */
int
freeMemoryIfNeeded
(
void
)
{
/* By default replicas should ignore maxmemory
* and just be masters exact copies.
*
* And don't care about mem if loading. */
if
(
server
.
loading
||
(
server
.
masterhost
&&
server
.
repl_slave_ignore_maxmemory
))
{
return
C_OK
;
}
* and just be masters exact copies. */
if
(
server
.
masterhost
&&
server
.
repl_slave_ignore_maxmemory
)
return
C_OK
;
size_t
mem_reported
,
mem_tofree
,
mem_freed
;
mstime_t
latency
,
eviction_latency
;
...
...
@@ -628,3 +622,14 @@ cant_free:
return
C_ERR
;
}
/* This is a wrapper for freeMemoryIfNeeded() that only really calls the
* function if right now there are the conditions to do so safely:
*
* - There must be no script in timeout condition.
* - Nor we are loading data right now.
*
*/
int
freeMemoryIfNeededAndSafe
(
void
)
{
if
(
server
.
lua_timedout
||
server
.
loading
)
return
C_OK
;
return
freeMemoryIfNeeded
();
}
src/server.c
View file @
129f2d27
...
...
@@ -2613,7 +2613,7 @@ int processCommand(client *c) {
* condition, to avoid mixing the propagation of scripts with the
* propagation of DELs due to eviction. */
if
(
server
.
maxmemory
&&
!
server
.
lua_timedout
)
{
int
out_of_memory
=
freeMemoryIfNeeded
()
==
C_ERR
;
int
out_of_memory
=
freeMemoryIfNeeded
AndSafe
()
==
C_ERR
;
/* freeMemoryIfNeeded may flush slave output buffers. This may result
* into a slave, that may be the active client, to be freed. */
if
(
server
.
current_client
==
NULL
)
return
C_ERR
;
...
...
src/server.h
View file @
129f2d27
...
...
@@ -1702,6 +1702,7 @@ int zslLexValueLteMax(sds value, zlexrangespec *spec);
int
getMaxmemoryState
(
size_t
*
total
,
size_t
*
logical
,
size_t
*
tofree
,
float
*
level
);
size_t
freeMemoryGetNotCountedMemory
();
int
freeMemoryIfNeeded
(
void
);
int
freeMemoryIfNeededAndSafe
(
void
);
int
processCommand
(
client
*
c
);
void
setupSignalHandlers
(
void
);
struct
redisCommand
*
lookupCommand
(
sds
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment