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
052e0349
Commit
052e0349
authored
Mar 14, 2019
by
antirez
Browse files
Fix objectSetLRUOrLFU() when LFU underflows.
parent
d292a516
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/object.c
View file @
052e0349
...
@@ -1199,7 +1199,7 @@ sds getMemoryDoctorReport(void) {
...
@@ -1199,7 +1199,7 @@ sds getMemoryDoctorReport(void) {
/* Set the object LRU/LFU depending on server.maxmemory_policy.
/* Set the object LRU/LFU depending on server.maxmemory_policy.
* The lfu_freq arg is only relevant if policy is MAXMEMORY_FLAG_LFU.
* The lfu_freq arg is only relevant if policy is MAXMEMORY_FLAG_LFU.
* The lru_idle and lru_clock args are only relevant if policy
* The lru_idle and lru_clock args are only relevant if policy
* is MAXMEMORY_FLAG_LRU.
* is MAXMEMORY_FLAG_LRU.
* Either or both of them may be <0, in that case, nothing is set. */
* Either or both of them may be <0, in that case, nothing is set. */
void
objectSetLRUOrLFU
(
robj
*
val
,
long
long
lfu_freq
,
long
long
lru_idle
,
void
objectSetLRUOrLFU
(
robj
*
val
,
long
long
lfu_freq
,
long
long
lru_idle
,
...
@@ -1210,16 +1210,20 @@ void objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle,
...
@@ -1210,16 +1210,20 @@ void objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle,
val
->
lru
=
(
LFUGetTimeInMinutes
()
<<
8
)
|
lfu_freq
;
val
->
lru
=
(
LFUGetTimeInMinutes
()
<<
8
)
|
lfu_freq
;
}
}
}
else
if
(
lru_idle
>=
0
)
{
}
else
if
(
lru_idle
>=
0
)
{
/*
Serializ
ed LRU idle time is in seconds. Scale
/*
Provid
ed LRU idle time is in seconds. Scale
* according to the LRU clock resolution this Redis
* according to the LRU clock resolution this Redis
* instance was compiled with (normally 1000 ms, so the
* instance was compiled with (normally 1000 ms, so the
* below statement will expand to lru_idle*1000/1000. */
* below statement will expand to lru_idle*1000/1000. */
lru_idle
=
lru_idle
*
1000
/
LRU_CLOCK_RESOLUTION
;
lru_idle
=
lru_idle
*
1000
/
LRU_CLOCK_RESOLUTION
;
val
->
lru
=
lru_clock
-
lru_idle
;
long
lru_abs
=
lru_clock
-
lru_idle
;
/* Absolute access time. */
/* If the lru field overflows (since LRU it is a wrapping
/* If the LRU field underflows (since LRU it is a wrapping
* clock), the best we can do is to provide the maximum
* clock), the best we can do is to provide a large enough LRU
* representable idle time. */
* that is half-way in the circlular LRU clock we use: this way
if
(
val
->
lru
<
0
)
val
->
lru
=
lru_clock
+
1
;
* the computed idle time for this object will stay high for quite
* some time. */
if
(
lru_abs
<
0
)
lru_abs
=
(
lru_clock
+
(
LRU_CLOCK_MAX
/
2
))
%
LRU_CLOCK_MAX
;
val
->
lru
=
lru_abs
;
}
}
}
}
...
...
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