aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2001-10-18 07:55:04 +0000
committerH. Peter Anvin <hpa@zytor.com>2001-10-18 07:55:04 +0000
commit05bccefa7306165bb1c36f469f429500e0e6f919 (patch)
tree82fe6f08e28902dffa61d00b71c32aad3ba59cf2
parent3adff3ab0f554dc8d08c563f61b93e7c1ca80805 (diff)
downloadlpsm-05bccefa7306165bb1c36f469f429500e0e6f919.tar.gz
lpsm-05bccefa7306165bb1c36f469f429500e0e6f919.tar.xz
lpsm-05bccefa7306165bb1c36f469f429500e0e6f919.zip
Fix bug that causes failures if size extended in the middle of realloc().
Correct bugs in tests :)
-rw-r--r--alloc.c14
-rw-r--r--testalloc.c11
-rw-r--r--testrecovery.c36
3 files changed, 43 insertions, 18 deletions
diff --git a/alloc.c b/alloc.c
index 0b71725..f7c53eb 100644
--- a/alloc.c
+++ b/alloc.c
@@ -724,15 +724,15 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
order++;
if ( order > ah->arena_size_lg2 ) {
- /* Need to extend the arena... */
+ /* Need to extend the arena immediately... */
if ( objstore_extend_arena(order+1) )
return NULL;
}
rorder = ah->arena_size_lg2 - order;
- DPRINTF(("buddy: realloc rorder %d -> rorder %d\n",
- bp.rorder, rorder));
+ DPRINTF(("buddy: realloc rorder %d %d -> rorder %d\n",
+ bp.rorder, bp.xbit, rorder));
if ( rorder == bp.rorder ) {
return ptr; /* No change at all */
@@ -772,6 +772,9 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
if ( !test_bit(ah->free_bitmap, xbit^1) ) {
/* A chunk we need is unavailable. Need to copy, sorry... */
DPRINTF(("buddy: unable to reallocate in place, rorder %2d %8d in use\n", i, xbit^1));
+
+ /* Careful. If objstore_malloc_buddy resizes the arena we need to
+ adjust the rorder and xbit values afterwards. */
nptr = objstore_malloc_buddy(new_size);
if ( !nptr )
return NULL; /* realloc failed */
@@ -779,9 +782,8 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
memcpy(nptr, ptr, current_size);
/* Free the old area */
- DPRINTF(("buddy: freeing rorder %2d %8d\n", bp.rorder, bp.xbit));
- clr_bit(ah->alloc_bitmap, bp.xbit);
- objstore_free_chunk(bp.xbit, bp.rorder);
+ /* Consider later if we can optimize this given the resizing issue */
+ objstore_free_buddy(ptr);
return nptr;
}
diff --git a/testalloc.c b/testalloc.c
index 4fe5ee7..d93ceba 100644
--- a/testalloc.c
+++ b/testalloc.c
@@ -103,9 +103,14 @@ int main(int argc, char *argv[])
rnd = (double)rand()/RAND_MAX;
sizes[slot] = (int)pow(2.0, MAXLOG*pow(rnd,5.0));
areas[slot] = objstore_malloc(sizes[slot]);
- printf("Alloc: %d (0x%08x) bytes at %p\n",
- sizes[slot], sizes[slot], areas[slot]);
- occupied += sizes[slot];
+ if ( areas[slot] ) {
+ printf("Alloc: %d (0x%08x) bytes at %p\n",
+ sizes[slot], sizes[slot], areas[slot]);
+ occupied += sizes[slot];
+ } else {
+ printf("Alloc: %d (0x%08x) bytes FAILED\n",
+ sizes[slot], sizes[slot]);
+ }
verify_no_overlap(slot);
}
diff --git a/testrecovery.c b/testrecovery.c
index 4c14b01..262a95b 100644
--- a/testrecovery.c
+++ b/testrecovery.c
@@ -27,12 +27,13 @@
#include <unistd.h>
#include <limits.h>
#include <signal.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "objstore.h"
-#define COUNT 32768
-#define SLOTS 1024
+#define COUNT 262144
+#define SLOTS 65536
#define MAXLOG 26
void **areas;
@@ -60,7 +61,7 @@ void verify_no_overlap(int slot)
}
struct misc_info {
- unsigned long occupied;
+ long occupied;
int count;
};
@@ -138,20 +139,29 @@ int main(int argc, char *argv[])
if ( WIFEXITED(status) )
break; /* Child exited, not killed, consider us done */
} else {
- pid = getpid();
+ struct timeval start_time, init_time;
+ pid = getpid();
printf("*** Process starting: %d, master_waits = %d\n",
pid, master_waits);
+ gettimeofday(&start_time, NULL);
+
root_ptr = objstore_arena_init("arena.dat", "arena.log");
+ gettimeofday(&init_time, NULL);
+
misc_ptr = root_ptr[0];
areas = root_ptr[1];
sizes = root_ptr[2];
printf("*** Recovering at count %d, occupied = %ld,\n"
- "*** areas = %p, sizes = %p\n",
- misc_ptr->count, misc_ptr->occupied, areas, sizes);
+ "*** areas = %p, sizes = %p, replay time = %.6f s\n",
+ misc_ptr->count, misc_ptr->occupied, areas, sizes,
+ (init_time.tv_sec-start_time.tv_sec)+
+ (init_time.tv_usec-start_time.tv_usec)/1e+6);
+
+ assert(misc_ptr->occupied >= 0);
/* In case the master process decided to be kind and wait for replay */
if ( master_waits )
@@ -170,6 +180,7 @@ int main(int argc, char *argv[])
sizes[slot], sizes[slot], areas[slot]);
areas[slot] = NULL;
misc_ptr->occupied -= sizes[slot];
+ assert(misc_ptr->occupied >= 0);
} else {
rnd = (double)rand()/RAND_MAX;
newsize = (int)pow(2.0, MAXLOG*pow(rnd,3.0));
@@ -179,6 +190,7 @@ int main(int argc, char *argv[])
sizes[slot], areas[slot], newsize, nptr);
misc_ptr->occupied += newsize;
misc_ptr->occupied -= sizes[slot];
+ assert(misc_ptr->occupied >= 0);
sizes[slot] = newsize;
areas[slot] = nptr;
verify_no_overlap(slot);
@@ -191,9 +203,15 @@ int main(int argc, char *argv[])
rnd = (double)rand()/RAND_MAX;
sizes[slot] = (int)pow(2.0, MAXLOG*pow(rnd,5.0));
areas[slot] = objstore_malloc(sizes[slot]);
- printf("Alloc: %d (0x%08x) bytes at %p\n",
- sizes[slot], sizes[slot], areas[slot]);
- misc_ptr->occupied += sizes[slot];
+ if (areas[slot]) {
+ printf("Alloc: %d (0x%08x) bytes at %p\n",
+ sizes[slot], sizes[slot], areas[slot]);
+ misc_ptr->occupied += sizes[slot];
+ } else {
+ printf("Alloc: %d (0x%08x) bytes FAILED\n",
+ sizes[slot], sizes[slot]);
+ }
+ assert(misc_ptr->occupied >= 0);
verify_no_overlap(slot);
}