From 970e10bb34690746ba378b0408ec37e7f7b57040 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 19 Jan 2010 13:02:02 -0500 Subject: [PATCH] removed a bug in the function to cancel an I/O job --- Makefile | 18 ++++++++++++++---- benchmark.c => redis-benchmark.c | 0 redis.c | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) rename benchmark.c => redis-benchmark.c (100%) diff --git a/Makefile b/Makefile index f3aff262..2c7bd349 100644 --- a/Makefile +++ b/Makefile @@ -15,26 +15,33 @@ CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF) DEBUG?= -g -rdynamic -ggdb OBJ = adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o -BENCHOBJ = ae.o anet.o benchmark.o sds.o adlist.o zmalloc.o +BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o +LOADOBJ = ae.o anet.o redis-load.o sds.o adlist.o zmalloc.o PRGNAME = redis-server BENCHPRGNAME = redis-benchmark CLIPRGNAME = redis-cli +LOADPRGNAME = redis-load all: redis-server redis-benchmark redis-cli +cotools: redis-load # Deps (use make dep to generate this) adlist.o: adlist.c adlist.h zmalloc.h -ae.o: ae.c ae.h zmalloc.h ae_select.c ae_epoll.c +ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c +ae_epoll.o: ae_epoll.c +ae_kqueue.o: ae_kqueue.c ae_select.o: ae_select.c anet.o: anet.c fmacros.h anet.h -benchmark.o: benchmark.c fmacros.h ae.h anet.h sds.h adlist.h zmalloc.h dict.o: dict.c fmacros.h dict.h zmalloc.h lzf_c.o: lzf_c.c lzfP.h lzf_d.o: lzf_d.c lzfP.h pqsort.o: pqsort.c +redis-benchmark.o: redis-benchmark.c fmacros.h ae.h anet.h sds.h adlist.h \ + zmalloc.h redis-cli.o: redis-cli.c fmacros.h anet.h sds.h adlist.h zmalloc.h +redis-load.o: redis-load.c fmacros.h ae.h anet.h sds.h adlist.h zmalloc.h redis.o: redis.c fmacros.h config.h redis.h ae.h sds.h anet.h dict.h \ adlist.h zmalloc.h lzf.h pqsort.h staticsymbols.h sds.o: sds.c sds.h zmalloc.h @@ -54,11 +61,14 @@ redis-benchmark: $(BENCHOBJ) redis-cli: $(CLIOBJ) $(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) +redis-load: $(LOADOBJ) + $(CC) -o $(LOADPRGNAME) $(CCOPT) $(DEBUG) $(LOADOBJ) + .c.o: $(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $< clean: - rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) *.o *.gcda *.gcno *.gcov + rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(LOADPRGNAME) *.o *.gcda *.gcno *.gcov dep: $(CC) -MM *.c diff --git a/benchmark.c b/redis-benchmark.c similarity index 100% rename from benchmark.c rename to redis-benchmark.c diff --git a/redis.c b/redis.c index aed49ed8..4aacc41b 100644 --- a/redis.c +++ b/redis.c @@ -566,6 +566,7 @@ static int vmWriteObjectOnSwap(robj *o, off_t page); static robj *vmReadObjectFromSwap(off_t page, int type); static void waitEmptyIOJobsQueue(void); static void vmReopenSwapFile(void); +static int vmFreePage(off_t page); static void authCommand(redisClient *c); static void pingCommand(redisClient *c); @@ -2498,7 +2499,8 @@ static void incrRefCount(robj *o) { static void decrRefCount(void *obj) { robj *o = obj; - /* Object is swapped out, or in the process of being loaded. */ + /* Object is a key of a swapped out value, or in the process of being + * loaded. */ if (server.vm_enabled && (o->storage == REDIS_VM_SWAPPED || o->storage == REDIS_VM_LOADING)) { @@ -7092,6 +7094,7 @@ static void vmInit(void) { static void vmMarkPageUsed(off_t page) { off_t byte = page/8; int bit = page&7; + redisAssert(vmFreePage(page) == 1); server.vm_bitmap[byte] |= 1< 100000000) { + *((char*)-1) = 'x'; + } } /* Test if the page is free */ @@ -7640,11 +7649,11 @@ again: if (job->canceled) continue; /* Skip this, already canceled. */ if (compareStringObjects(job->key,o) == 0) { - redisLog(REDIS_DEBUG,"*** CANCELED %p (%s) (LIST ID %d)\n", - (void*)job, (char*)o->ptr, i); + redisLog(REDIS_DEBUG,"*** CANCELED %p (%s) (type %d) (LIST ID %d)\n", + (void*)job, (char*)o->ptr, job->type, i); /* Mark the pages as free since the swap didn't happened * or happened but is now discarded. */ - if (job->type == REDIS_IOJOB_DO_SWAP) + if (i != 1 && job->type == REDIS_IOJOB_DO_SWAP) vmMarkPagesFree(job->page,job->pages); /* Cancel the job. It depends on the list the job is * living in. */ -- 2.45.2