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
b08c36c5
Commit
b08c36c5
authored
Sep 25, 2015
by
antirez
Browse files
Lazyfree: keep count of objects to free.
parent
c7b46a47
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/bio.c
View file @
b08c36c5
...
...
@@ -84,6 +84,7 @@ struct bio_job {
};
void
*
bioProcessBackgroundJobs
(
void
*
arg
);
void
lazyfreeFreeObjectFromBioThread
(
robj
*
o
);
/* Make sure we have enough stack to perform all the things we do in the
* main thread. */
...
...
@@ -186,7 +187,7 @@ void *bioProcessBackgroundJobs(void *arg) {
}
else
if
(
type
==
BIO_AOF_FSYNC
)
{
aof_fsync
((
long
)
job
->
arg1
);
}
else
if
(
type
==
BIO_LAZY_FREE
)
{
decrRefCount
((
robj
*
)
job
->
arg1
);
lazyfreeFreeObjectFromBioThread
(
job
->
arg1
);
}
else
{
serverPanic
(
"Wrong job type in bioProcessBackgroundJobs()."
);
}
...
...
src/lazyfree.c
View file @
b08c36c5
#include "server.h"
#include "bio.h"
#include "atomicvar.h"
static
size_t
lazyfree_objects
=
0
;
static
size_t
lazyfree_dbs
=
0
;
pthread_mutex_t
lazyfree_objects_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
lazyfree_objects_dbs
=
PTHREAD_MUTEX_INITIALIZER
;
/* Return the amount of work needed in order to free an object.
* The return value is not always the actual number of allocations the
...
...
@@ -60,6 +59,7 @@ int dbAsyncDelete(redisDb *db, robj *key) {
/* If releasing the object is too much work, let's put it into the
* lazy free list. */
if
(
free_effort
>
LAZYFREE_THRESHOLD
)
{
atomicIncr
(
lazyfree_objects
,
1
,
&
lazyfree_objects_mutex
);
bioCreateBackgroundJob
(
BIO_LAZY_FREE
,
val
,
NULL
,
NULL
);
dictSetVal
(
db
->
dict
,
de
,
NULL
);
}
...
...
@@ -74,3 +74,10 @@ int dbAsyncDelete(redisDb *db, robj *key) {
return
0
;
}
}
/* Implementation of function to release a single object called from the
* lazyfree thread from bio.c. */
void
lazyfreeFreeObjectFromBioThread
(
robj
*
o
)
{
decrRefCount
(
o
);
atomicDecr
(
lazyfree_objects
,
1
,
&
lazyfree_objects_mutex
);
}
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