Skip to content

Commit b08c36c

Browse files
committed
Lazyfree: keep count of objects to free.
1 parent c7b46a4 commit b08c36c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/bio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct bio_job {
8484
};
8585

8686
void *bioProcessBackgroundJobs(void *arg);
87+
void lazyfreeFreeObjectFromBioThread(robj *o);
8788

8889
/* Make sure we have enough stack to perform all the things we do in the
8990
* main thread. */
@@ -186,7 +187,7 @@ void *bioProcessBackgroundJobs(void *arg) {
186187
} else if (type == BIO_AOF_FSYNC) {
187188
aof_fsync((long)job->arg1);
188189
} else if (type == BIO_LAZY_FREE) {
189-
decrRefCount((robj*)job->arg1);
190+
lazyfreeFreeObjectFromBioThread(job->arg1);
190191
} else {
191192
serverPanic("Wrong job type in bioProcessBackgroundJobs().");
192193
}

src/lazyfree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "server.h"
22
#include "bio.h"
3+
#include "atomicvar.h"
34

45
static size_t lazyfree_objects = 0;
5-
static size_t lazyfree_dbs = 0;
66
pthread_mutex_t lazyfree_objects_mutex = PTHREAD_MUTEX_INITIALIZER;
7-
pthread_mutex_t lazyfree_objects_dbs = PTHREAD_MUTEX_INITIALIZER;
87

98
/* Return the amount of work needed in order to free an object.
109
* The return value is not always the actual number of allocations the
@@ -60,6 +59,7 @@ int dbAsyncDelete(redisDb *db, robj *key) {
6059
/* If releasing the object is too much work, let's put it into the
6160
* lazy free list. */
6261
if (free_effort > LAZYFREE_THRESHOLD) {
62+
atomicIncr(lazyfree_objects,1,&lazyfree_objects_mutex);
6363
bioCreateBackgroundJob(BIO_LAZY_FREE,val,NULL,NULL);
6464
dictSetVal(db->dict,de,NULL);
6565
}
@@ -74,3 +74,10 @@ int dbAsyncDelete(redisDb *db, robj *key) {
7474
return 0;
7575
}
7676
}
77+
78+
/* Implementation of function to release a single object called from the
79+
* lazyfree thread from bio.c. */
80+
void lazyfreeFreeObjectFromBioThread(robj *o) {
81+
decrRefCount(o);
82+
atomicDecr(lazyfree_objects,1,&lazyfree_objects_mutex);
83+
}

0 commit comments

Comments
 (0)