Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
15b04090
Unverified
Commit
15b04090
authored
Apr 30, 2020
by
Salvatore Sanfilippo
Committed by
GitHub
Apr 30, 2020
Browse files
Merge pull request #4838 from soloestoy/lazyfree-eviction
lazyfree & eviction: record latency generated by lazyfree eviction
parents
058c7272
528ea98b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/evict.c
View file @
15b04090
...
...
@@ -450,9 +450,10 @@ int freeMemoryIfNeeded(void) {
if
(
server
.
masterhost
&&
server
.
repl_slave_ignore_maxmemory
)
return
C_OK
;
size_t
mem_reported
,
mem_tofree
,
mem_freed
;
mstime_t
latency
,
eviction_latency
;
mstime_t
latency
,
eviction_latency
,
lazyfree_latency
;
long
long
delta
;
int
slaves
=
listLength
(
server
.
slaves
);
int
result
=
C_ERR
;
/* When clients are paused the dataset should be static not just from the
* POV of clients not being able to write, but also from the POV of
...
...
@@ -463,10 +464,10 @@ int freeMemoryIfNeeded(void) {
mem_freed
=
0
;
latencyStartMonitor
(
latency
);
if
(
server
.
maxmemory_policy
==
MAXMEMORY_NO_EVICTION
)
goto
cant_free
;
/* We need to free memory, but policy forbids. */
latencyStartMonitor
(
latency
);
while
(
mem_freed
<
mem_tofree
)
{
int
j
,
k
,
i
;
static
unsigned
int
next_db
=
0
;
...
...
@@ -572,7 +573,6 @@ int freeMemoryIfNeeded(void) {
signalModifiedKey
(
NULL
,
db
,
keyobj
);
latencyEndMonitor
(
eviction_latency
);
latencyAddSampleIfNeeded
(
"eviction-del"
,
eviction_latency
);
latencyRemoveNestedEvent
(
latency
,
eviction_latency
);
delta
-=
(
long
long
)
zmalloc_used_memory
();
mem_freed
+=
delta
;
server
.
stat_evictedkeys
++
;
...
...
@@ -601,25 +601,30 @@ int freeMemoryIfNeeded(void) {
}
}
}
else
{
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"eviction-cycle"
,
latency
);
goto
cant_free
;
/* nothing to free... */
}
}
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"eviction-cycle"
,
latency
);
return
C_OK
;
result
=
C_OK
;
cant_free:
/* We are here if we are not able to reclaim memory. There is only one
* last thing we can try: check if the lazyfree thread has jobs in queue
* and wait... */
while
(
bioPendingJobsOfType
(
BIO_LAZY_FREE
))
{
if
(((
mem_reported
-
zmalloc_used_memory
())
+
mem_freed
)
>=
mem_tofree
)
break
;
usleep
(
1000
);
if
(
result
!=
C_OK
)
{
latencyStartMonitor
(
lazyfree_latency
);
while
(
bioPendingJobsOfType
(
BIO_LAZY_FREE
))
{
if
(
getMaxmemoryState
(
NULL
,
NULL
,
NULL
,
NULL
)
==
C_OK
)
{
result
=
C_OK
;
break
;
}
usleep
(
1000
);
}
latencyEndMonitor
(
lazyfree_latency
);
latencyAddSampleIfNeeded
(
"eviction-lazyfree"
,
lazyfree_latency
);
}
return
C_ERR
;
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"eviction-cycle"
,
latency
);
return
result
;
}
/* This is a wrapper for freeMemoryIfNeeded() that only really calls the
...
...
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