From: jdybnis Date: Thu, 13 Nov 2008 06:29:14 +0000 (+0000) Subject: free its keys too when freeing a ht X-Git-Url: https://pd.if.org/git/?p=nbds;a=commitdiff_plain;h=1da02238e784eaba7bc8193f62a738e9d3f3ee1a free its keys too when freeing a ht --- diff --git a/runtime/mem.c b/runtime/mem.c index e46eb7e..7e56909 100644 --- a/runtime/mem.c +++ b/runtime/mem.c @@ -62,6 +62,7 @@ void mem_init (void) { // // TODO: maybe we want to munmap() larger size blocks to reclaim virtual address space? void nbd_free (void *x) { + assert(x); LOCALIZE_THREAD_LOCAL(tid_, int); block_t *b = (block_t *)x; assert(((size_t)b >> REGION_SCALE) < ((1 << HEADER_REGION_SCALE) / sizeof(header_t))); @@ -88,6 +89,7 @@ void nbd_free (void *x) { // on the private free list. If we didn't find any blocks on the public free lists, allocate a new // region, break it up into blocks and put them on the private free list. void *nbd_malloc (size_t n) { + assert(n); LOCALIZE_THREAD_LOCAL(tid_, int); if (n < sizeof(block_t)) { n = sizeof(block_t); diff --git a/struct/ht.c b/struct/ht.c index 8703faa..aed74fa 100644 --- a/struct/ht.c +++ b/struct/ht.c @@ -517,6 +517,12 @@ hash_table_t *ht_alloc (void) { void ht_free (hash_table_t *ht) { hash_table_i_t *hti = *ht; do { + for (uint32_t i = 0; i < (1 << hti->scale); ++i) { + assert(hti->table[i].value == COPIED_VALUE || !IS_TAGGED(hti->table[i].value)); + if (hti->table[i].key != DOES_NOT_EXIST) { + nbd_free((void *)(hti->table[i].key & MASK(48))); + } + } hash_table_i_t *next = hti->next; nbd_free(hti); hti = next; diff --git a/struct/ht_test.c b/struct/ht_test.c index c7e6d57..fd76524 100644 --- a/struct/ht_test.c +++ b/struct/ht_test.c @@ -93,7 +93,7 @@ void *simple_worker (void *arg) { hash_table_t *ht = wd->ht; CuTest* tc = wd->tc; uint64_t d = wd->id; - int iters = 20000; + int iters = 1000000; SYNC_ADD(wd->wait, -1); do { } while (*((volatile worker_data_t *)wd)->wait); // wait for all workers to be ready diff --git a/todo b/todo index ff93413..ab8c0db 100644 --- a/todo +++ b/todo @@ -1,7 +1,5 @@ - make rcu wait when its buffer gets full, instead of crashing - fix makefile to compute dependency info as a side-effect of compilation (-MF) -- investigate 16 byte CAS - - ht can store GUIDs inline instead of pointers to actual keys - - mem can keep tail pointers for free-lists and do O(1) appends +- investigate 16 byte CAS; ht can store GUIDs inline instead of pointers to actual keys - test ht - optimize tracing code, still too much overhead