diff options
author | H. Peter Anvin <hpa@zytor.com> | 2001-10-15 23:14:57 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2001-10-15 23:14:57 +0000 |
commit | e1762ed1c23b53b26e6841f4bba1a5688e98a2dd (patch) | |
tree | b07f9def493f6b25c9e1cce62488dd9560b19e17 | |
parent | 8b171ab4486a07cc899f3e54660aeb613a3e4d23 (diff) | |
download | lpsm-e1762ed1c23b53b26e6841f4bba1a5688e98a2dd.tar.gz lpsm-e1762ed1c23b53b26e6841f4bba1a5688e98a2dd.tar.xz lpsm-e1762ed1c23b53b26e6841f4bba1a5688e98a2dd.zip |
Clean up the interfaces and remove some obviously incorrect code.to-tytso-20011015b
-rw-r--r-- | alloc.c | 22 | ||||
-rw-r--r-- | arena.c | 4 | ||||
-rw-r--r-- | ftrunctest.c | 1 | ||||
-rw-r--r-- | lpsm.h | 16 | ||||
-rw-r--r-- | testalloc.c | 9 | ||||
-rw-r--r-- | testbuddy.c | 9 |
6 files changed, 37 insertions, 24 deletions
@@ -19,8 +19,9 @@ * This code uses a modified buddy system allocator for large allocations * and a SLAB allocator for small allocations. * - * This generally assumes 8-bit bytes and 2's-complement arithmetric. - * These days, that's oh-such-a-strech... + * This generally assumes 8-bit bytes and 2's-complement arithmetric, + * and that an all-zero bit pattern is a valid NULL. These days, that's + * oh-such-a-strech... */ #include <assert.h> @@ -78,7 +79,6 @@ struct arena_header { uint16_t arena_bytesize; uint16_t arena_ptrsize; void *arena_base; /* Base of allocation */ - void *root_data_ptr; /* Root data pointer - for the user */ void *free_bitmap; /* The free bitmap */ void *alloc_bitmap; /* The allocated (buddy) bitmap */ void *data_start; /* Beginning of data area */ @@ -86,6 +86,7 @@ struct arena_header { int arena_size_lg2; /* Current arena allocation size */ int header_size; /* Size of this header+padding */ struct slab_info slab[SLAB_INFO_COUNT]; + void *root_data_ptrs[ROOT_DATA_POINTERS]; /* Root data pointers - for the user */ }; /* This is the minimal order before going to SLAB allocation. */ @@ -235,10 +236,17 @@ static struct ObjStore *os; static struct arena_header *ah; /* - * Initalize the object store arena allocator. + * Initalize the object store arena allocator. This returns NULL + * on failure, or a pointer to the "root data pointer" array if + * successful. */ -void *objstore_arena_init(void) +void **objstore_arena_init(const char *main_file, const char *log_file) { + size_t arena_len = sizeof(struct arena_header); /* Minimum initial size */ + + if ( !objstore_init(main_file, log_file, &arena_len) ) + return NULL; /* Failed to initialize arena */ + os = objstore_os_struct; ah = (struct arena_header *)os->arena; @@ -247,6 +255,8 @@ void *objstore_arena_init(void) size_t total_size, bitmap_size; int i, header_pad; + memset(ah, 0, sizeof(*ah)); /* Just in case */ + /* Uninitialized arena */ memcpy(ah->arena_magic, objstore_arena_magic, 16); ah->arena_byteorder = 0x12345678; @@ -309,7 +319,7 @@ void *objstore_arena_init(void) return NULL; /* Incompatible or corrupt arena */ } - return ah->data_start; + return ah->root_data_ptrs; } /* @@ -228,8 +228,6 @@ static int objstore_log_writeback(void) char *data; position += sizeof(record); - if ( !data ) - return -1; /* Badness... */ lockmain.l_type = F_WRLCK; lockmain.l_whence = SEEK_SET; @@ -303,7 +301,7 @@ static int objstore_recover_log(void) * playback (crash recovery) if the log file exists * and is nonempty. */ -void *objstore_init(char *main_file, char *log_file, size_t *arena_len) +void *objstore_init(const char *main_file, const char *log_file, size_t *arena_len) { struct ObjStore *os; void *arena_ptr; diff --git a/ftrunctest.c b/ftrunctest.c index dfa58b3..c8b4a05 100644 --- a/ftrunctest.c +++ b/ftrunctest.c @@ -7,7 +7,6 @@ int main(int argc, char *argv[]) { int fd; - char *mapping; fd = open("ftrunc.dat", O_RDWR|O_CREAT, 0666); ftruncate(fd, 1024*1024*1024); @@ -24,17 +24,25 @@ #include <signal.h> #include <inttypes.h> -struct Objstore; +/* Low-level core routines */ -/* Core routines */ -void *objstore_init(char *, char *, size_t *); +void *objstore_init(const char *, const char *, size_t *); int objstore_checkpoint(double); int objstore_extend(size_t); /* Arena management routines */ -void *objstore_arena_init(void); + +/* The allocator gives us this many "root pointers" for our own use. They + are initialized to NULL when a new arena is created, and are intended + to be used to find all the data structures. objstore_arena_init() + returns a pointer to this array (if successful). */ +#define ROOT_DATA_POINTERS 32 + +void **objstore_arena_init(const char *, const char *); void *objstore_malloc(size_t); void objstore_free(void *); void *objstore_realloc(void *, size_t); +void **objstore_get_root_ptrs(void); + #endif diff --git a/testalloc.c b/testalloc.c index 9c66d07..9a6d3ed 100644 --- a/testalloc.c +++ b/testalloc.c @@ -50,11 +50,10 @@ void verify_no_overlap(int slot) int main(int argc, char *argv[]) { - void *buf; int i, slot, newsize; double rnd; + void **root_ptr; void *nptr; - size_t arena_len = 4096; unsigned long occupied = 0; unlink("arena.dat"); @@ -63,12 +62,14 @@ int main(int argc, char *argv[]) memset(areas, 0, sizeof(areas)); memset(sizes, 0, sizeof(sizes)); - buf = objstore_init("arena.dat", "arena.log", &arena_len); - if ( !objstore_arena_init() ) { + if ( !(root_ptr = objstore_arena_init("arena.dat", "arena.log")) ) { fprintf(stderr, "%s: objstore_arena_init() failed\n", argv[0]); return 1; } + printf("Arena: initialized, %d root pointers at %p\n", + ROOT_DATA_POINTERS, root_ptr); + objstore_checkpoint(0.0); for ( i = 0 ; i < COUNT ; i++ ) { diff --git a/testbuddy.c b/testbuddy.c index 5bde336..4cf02a8 100644 --- a/testbuddy.c +++ b/testbuddy.c @@ -87,15 +87,12 @@ static int testsizes[] = { int main(int argc, char *argv[]) { void *areas[64]; - void *buf; - int arena_len = 16384; int i; - unlink("arena.dat"); - unlink("arena.log"); + unlink("buddy.dat"); + unlink("buddy.log"); - buf = objstore_init("arena.dat", "arena.log", &arena_len); - if ( !objstore_arena_init() ) { + if ( !objstore_arena_init("buddy.dat", "buddy.log") ) { fprintf(stderr, "%s: objstore_arena_init() failed\n", argv[0]); return 1; } |