From 015316021860810dd632cb127226f10eb21160de Mon Sep 17 00:00:00 2001 From: Rusty Sears Date: Wed, 14 Nov 2012 23:04:03 -0800 Subject: [PATCH] more malloc fixes; add stasis_alloc, stasis_malloc_trailing_array --- benchmarks/bufferManager.c | 2 +- src/stasis/allocationPolicy.c | 12 +++++----- src/stasis/bufferManager.c | 2 +- src/stasis/bufferManager/bufferHash.c | 4 ++-- .../bufferManager/concurrentBufferManager.c | 6 ++--- .../legacy/legacyBufferManager.c | 2 +- src/stasis/bufferManager/legacy/pageFile.c | 2 +- src/stasis/bufferManager/pageArray.c | 6 ++--- src/stasis/bufferPool.c | 2 +- src/stasis/common.c | 10 ++++---- src/stasis/dirtyPageTable.c | 6 ++--- src/stasis/io/debug.c | 8 +++---- src/stasis/io/file.c | 8 +++---- src/stasis/io/memory.c | 10 ++++---- src/stasis/io/non_blocking.c | 24 +++++++++---------- src/stasis/io/pfile.c | 8 +++---- src/stasis/io/raid0.c | 4 ++-- src/stasis/io/raid1.c | 4 ++-- src/stasis/io/rangeTracker.c | 12 +++++----- src/stasis/logger/filePool.c | 6 ++--- src/stasis/logger/groupForce.c | 2 +- src/stasis/logger/inMemoryLog.c | 4 ++-- src/stasis/logger/logHandle.c | 2 +- src/stasis/logger/reorderingHandle.c | 4 ++-- src/stasis/logger/safeWrites.c | 4 ++-- src/stasis/operations/alloc.c | 4 ++-- src/stasis/operations/bTree.c | 4 ++-- src/stasis/operations/linearHashNTA.c | 4 ++-- src/stasis/operations/linkedListNTA.c | 14 +++++------ src/stasis/operations/naiveLinearHash.c | 10 ++++---- src/stasis/operations/pageOrientedListNTA.c | 2 +- src/stasis/page.c | 4 ++-- src/stasis/pageHandle.c | 4 ++-- src/stasis/recovery2.c | 2 +- src/stasis/replacementPolicy/clock.c | 4 ++-- .../replacementPolicy/concurrentWrapper.c | 4 ++-- src/stasis/replacementPolicy/lru.c | 6 ++--- src/stasis/replacementPolicy/lruFast.c | 4 ++-- .../replacementPolicy/threadsafeWrapper.c | 4 ++-- src/stasis/transactionTable.c | 6 ++--- src/stasis/truncation.c | 2 +- src/stasis/util/bloomFilter.c | 2 +- src/stasis/util/concurrentHash.c | 2 +- src/stasis/util/doubleLinkedList.c | 10 ++++---- src/stasis/util/lhtable.c | 6 ++--- src/stasis/util/linkedlist.c | 4 ++-- src/stasis/util/min.c | 4 ++-- src/stasis/util/multiset.c | 4 ++-- src/stasis/util/ringbuffer.c | 2 +- src/stasis/util/slab.c | 4 ++-- stasis/util/concurrentSkipList.h | 4 ++-- stasis/util/hazard.h | 4 ++-- stasis/util/histogram.h | 2 +- stasis/util/malloc.h | 2 ++ stasis/util/rw.h | 4 ++-- 55 files changed, 144 insertions(+), 142 deletions(-) diff --git a/benchmarks/bufferManager.c b/benchmarks/bufferManager.c index 4bc9cb1..fa204b9 100644 --- a/benchmarks/bufferManager.c +++ b/benchmarks/bufferManager.c @@ -100,7 +100,7 @@ int do_operations(pageid_t page_count, int num_threads, unsigned long long num_o for(int i = 0; i < num_threads ; i++) { if(ops_remaining <= 0) { num_threads = i; break; } - struct thread_arg *a = stasis_malloc(1, struct thread_arg); + struct thread_arg *a = stasis_alloc(struct thread_arg); a->seed = base_seed + i; a->num_ops = ops_remaining < ops_per_thread ? ops_remaining : ops_per_thread; a->write_frac = write_frac; diff --git a/src/stasis/allocationPolicy.c b/src/stasis/allocationPolicy.c index f6b5212..cb3675b 100644 --- a/src/stasis/allocationPolicy.c +++ b/src/stasis/allocationPolicy.c @@ -134,7 +134,7 @@ static void void_double_add(void * val, struct rbtree * a, struct rbtree * b) { static int availablePages_remove(stasis_allocation_policy_t *ap, pageid_t pageid); static int availablePages_add(stasis_allocation_policy_t *ap, pageid_t pageid, size_t freespace) { int ret = availablePages_remove(ap, pageid); - availablePages_pageid_freespace* tup= stasis_malloc(1, availablePages_pageid_freespace); + availablePages_pageid_freespace* tup= stasis_alloc(availablePages_pageid_freespace); tup->pageid = pageid; tup->freespace = freespace; void_double_add(tup, ap->availablePages_key_pageid, ap->availablePages_key_freespace_pageid); @@ -151,7 +151,7 @@ static int pageOwners_add(stasis_allocation_policy_t *ap, int xid, size_t freesp int ret = pageOwners_remove(ap, pageid); - pageOwners_xid_freespace_pageid * tup = stasis_malloc(1, pageOwners_xid_freespace_pageid); + pageOwners_xid_freespace_pageid * tup = stasis_alloc(pageOwners_xid_freespace_pageid); tup->xid = xid; tup->freespace = freespace; tup->pageid = pageid; @@ -202,7 +202,7 @@ static int allPages_lookup_by_pageid(stasis_allocation_policy_t *ap, pageid_t pa } } static int allPages_add(stasis_allocation_policy_t *ap, pageid_t pageid, size_t freespace) { - allPages_pageid_freespace * tup = stasis_malloc(1, allPages_pageid_freespace); + allPages_pageid_freespace * tup = stasis_alloc(allPages_pageid_freespace); tup->pageid = pageid; tup->freespace = freespace; int ret = void_single_add(tup, ap->allPages_key_pageid); @@ -230,7 +230,7 @@ static void allPages_removeAll(stasis_allocation_policy_t *ap) { } static void allPages_set_freespace(stasis_allocation_policy_t *ap, pageid_t pageid, size_t freespace) { - allPages_pageid_freespace * tup = stasis_malloc(1, allPages_pageid_freespace); + allPages_pageid_freespace * tup = stasis_alloc(allPages_pageid_freespace); tup->pageid = pageid; tup->freespace = freespace; int existed = void_single_add(tup, ap->allPages_key_pageid); @@ -323,7 +323,7 @@ static int xidAllocedDealloced_helper_remove(stasis_allocation_policy_t *ap, str static int xidAllocedDealloced_helper_add(stasis_allocation_policy_t *ap, struct rbtree *first, struct rbtree* second, int xid, pageid_t pageid) { int existed = xidAllocedDealloced_helper_remove(ap, first, second, xid, pageid); - xidAllocedDealloced_xid_pageid * tup = stasis_malloc(1, xidAllocedDealloced_xid_pageid); + xidAllocedDealloced_xid_pageid * tup = stasis_alloc(xidAllocedDealloced_xid_pageid); tup->xid = xid; tup->pageid = pageid; void_double_add(tup, first, second); @@ -454,7 +454,7 @@ static int xidAllocedDealloced_cmp_xid_pageid(const void *ap, const void *bp, co } stasis_allocation_policy_t * stasis_allocation_policy_init() { - stasis_allocation_policy_t * ap = stasis_malloc(1, stasis_allocation_policy_t); + stasis_allocation_policy_t * ap = stasis_alloc(stasis_allocation_policy_t); ap->availablePages_key_pageid = rbinit(availablePages_cmp_pageid, 0); ap->availablePages_key_freespace_pageid = rbinit(availablePages_cmp_freespace_pageid, 0); ap->pageOwners_key_pageid = rbinit(pageOwners_cmp_pageid, 0); diff --git a/src/stasis/bufferManager.c b/src/stasis/bufferManager.c index 33b784d..2505f03 100644 --- a/src/stasis/bufferManager.c +++ b/src/stasis/bufferManager.c @@ -100,7 +100,7 @@ compensated_function Page * __profile_loadPage(int xid, pageid_t pageid, char * int * pins = LH_ENTRY(find)(profile_load_pins_hash, &ret, sizeof(void*)); if(!pins) { - pins = stasis_malloc(1, int); + pins = stasis_alloc(int); *pins = 0; LH_ENTRY(insert)(profile_load_pins_hash, &ret, sizeof(void*), pins); } diff --git a/src/stasis/bufferManager/bufferHash.c b/src/stasis/bufferManager/bufferHash.c index 7d5a02e..f3e1e87 100644 --- a/src/stasis/bufferManager/bufferHash.c +++ b/src/stasis/bufferManager/bufferHash.c @@ -506,8 +506,8 @@ static int bhCloseHandleImpl(stasis_buffer_manager_t *bm, stasis_buffer_manager_ } stasis_buffer_manager_t* stasis_buffer_manager_hash_open(stasis_page_handle_t * h, stasis_log_t * log, stasis_dirty_page_table_t * dpt) { - stasis_buffer_manager_t *bm = stasis_malloc(1, stasis_buffer_manager_t); - stasis_buffer_hash_t *bh = stasis_malloc(1, stasis_buffer_hash_t); + stasis_buffer_manager_t *bm = stasis_alloc(stasis_buffer_manager_t); + stasis_buffer_hash_t *bh = stasis_alloc(stasis_buffer_hash_t); bm->openHandleImpl = bhOpenHandleImpl; bm->closeHandleImpl = bhCloseHandleImpl; diff --git a/src/stasis/bufferManager/concurrentBufferManager.c b/src/stasis/bufferManager/concurrentBufferManager.c index d92b587..a8b3e8a 100644 --- a/src/stasis/bufferManager/concurrentBufferManager.c +++ b/src/stasis/bufferManager/concurrentBufferManager.c @@ -177,7 +177,7 @@ static inline stasis_buffer_concurrent_hash_tls_t * populateTLS(stasis_buffer_ma stasis_buffer_concurrent_hash_t *ch = bm->impl; stasis_buffer_concurrent_hash_tls_t *tls = pthread_getspecific(ch->key); if(tls == NULL) { - tls = stasis_malloc(1, stasis_buffer_concurrent_hash_tls_t); + tls = stasis_alloc(stasis_buffer_concurrent_hash_tls_t); tls->p = NULL; tls->bm = bm; pthread_setspecific(ch->key, tls); @@ -409,8 +409,8 @@ static int chCloseHandle(stasis_buffer_manager_t *bm, stasis_buffer_manager_hand } stasis_buffer_manager_t* stasis_buffer_manager_concurrent_hash_open(stasis_page_handle_t * h, stasis_log_t * log, stasis_dirty_page_table_t * dpt) { - stasis_buffer_manager_t *bm = stasis_malloc(1, stasis_buffer_manager_t); - stasis_buffer_concurrent_hash_t *ch = stasis_malloc(1, stasis_buffer_concurrent_hash_t); + stasis_buffer_manager_t *bm = stasis_alloc(stasis_buffer_manager_t); + stasis_buffer_concurrent_hash_t *ch = stasis_alloc(stasis_buffer_concurrent_hash_t); bm->openHandleImpl = chOpenHandle; bm->closeHandleImpl = chCloseHandle; bm->loadPageImpl = chLoadPageImpl; diff --git a/src/stasis/bufferManager/legacy/legacyBufferManager.c b/src/stasis/bufferManager/legacy/legacyBufferManager.c index bb81b30..3d3cf48 100644 --- a/src/stasis/bufferManager/legacy/legacyBufferManager.c +++ b/src/stasis/bufferManager/legacy/legacyBufferManager.c @@ -54,7 +54,7 @@ static int bufManCloseHandle(stasis_buffer_manager_t *bm, stasis_buffer_manager_ stasis_buffer_manager_t* stasis_buffer_manager_deprecated_open(stasis_page_handle_t * ph) { page_handle = ph; - stasis_buffer_manager_t * bm = stasis_malloc(1, stasis_buffer_manager_t); + stasis_buffer_manager_t * bm = stasis_alloc(stasis_buffer_manager_t); bm->releasePageImpl = bufManReleasePage; bm->openHandleImpl = bufManOpenHandle; bm->closeHandleImpl = bufManCloseHandle; diff --git a/src/stasis/bufferManager/legacy/pageFile.c b/src/stasis/bufferManager/legacy/pageFile.c index ea38b49..5554de0 100644 --- a/src/stasis/bufferManager/legacy/pageFile.c +++ b/src/stasis/bufferManager/legacy/pageFile.c @@ -130,7 +130,7 @@ static void pfPageWrite(stasis_page_handle_t * h, Page * ret) { /** @todo O_DIRECT is broken in older linuxes (eg 2.4). The build script should disable it on such platforms. */ stasis_page_handle_t* openPageFile(stasis_log_t * log, stasis_dirty_page_table_t * dpt) { - stasis_page_handle_t * ret = stasis_malloc(1, stasis_page_handle_t); + stasis_page_handle_t * ret = stasis_alloc(stasis_page_handle_t); ret->read = pfPageRead; ret->write = pfPageWrite; ret->force_file = pfForcePageFile; diff --git a/src/stasis/bufferManager/pageArray.c b/src/stasis/bufferManager/pageArray.c index 755f276..b65e3fe 100644 --- a/src/stasis/bufferManager/pageArray.c +++ b/src/stasis/bufferManager/pageArray.c @@ -23,7 +23,7 @@ static Page * paLoadPage(stasis_buffer_manager_t *bm, stasis_buffer_manager_hand } if(!pa->pageMap[pageid]) { - pa->pageMap[pageid] = stasis_malloc(1, Page); + pa->pageMap[pageid] = stasis_alloc(Page); pa->pageMap[pageid]->id = pageid; pa->pageMap[pageid]->pageType = type == UNKNOWN_TYPE_PAGE ? 0 : type; pa->pageMap[pageid]->LSN = 0; @@ -82,8 +82,8 @@ static int paCloseHandle(stasis_buffer_manager_t *bm, stasis_buffer_manager_hand stasis_buffer_manager_t * stasis_buffer_manager_mem_array_open () { - stasis_buffer_manager_t * bm = stasis_malloc(1, stasis_buffer_manager_t); - stasis_buffer_manager_page_array_t * pa = stasis_malloc(1, stasis_buffer_manager_page_array_t); + stasis_buffer_manager_t * bm = stasis_alloc(stasis_buffer_manager_t); + stasis_buffer_manager_page_array_t * pa = stasis_alloc(stasis_buffer_manager_page_array_t); bm->releasePageImpl = paReleasePage; bm->openHandleImpl = paOpenHandle; diff --git a/src/stasis/bufferPool.c b/src/stasis/bufferPool.c index 3c3201b..c66884c 100644 --- a/src/stasis/bufferPool.c +++ b/src/stasis/bufferPool.c @@ -64,7 +64,7 @@ struct stasis_buffer_pool_t { stasis_buffer_pool_t* stasis_buffer_pool_init() { - stasis_buffer_pool_t * ret = stasis_malloc(1, stasis_buffer_pool_t); + stasis_buffer_pool_t * ret = stasis_alloc(stasis_buffer_pool_t); ret->nextPage = 0; diff --git a/src/stasis/common.c b/src/stasis/common.c index e113833..5b4387f 100644 --- a/src/stasis/common.c +++ b/src/stasis/common.c @@ -58,7 +58,7 @@ int __lladd_pthread_mutex_lock(lladd_pthread_mutex_t *mutex, char * file, int li mutex->last_acquired_at = location; if(!tup) { - tup = stasis_malloc(1, profile_tuple); + tup = stasis_alloc(profile_tuple); init_tuple(tup); @@ -133,7 +133,7 @@ int __lladd_pthread_cond_wait(pthread_cond_t *cond, lladd_pthread_mutex_t *mutex mutex->last_acquired_at = location; if(!tup) { - tup = stasis_malloc(1, profile_tuple); + tup = stasis_alloc(profile_tuple); init_tuple(tup); @@ -167,7 +167,7 @@ int __lladd_pthread_cond_timedwait(pthread_cond_t *cond, lladd_pthread_mutex_t * #undef downgradelock __profile_rwl *__profile_rw_initlock (char * file, int line) { - __profile_rwl * ret = stasis_malloc(1, __profile_rwl); + __profile_rwl * ret = stasis_alloc(__profile_rwl); ret->file = file; ret->line = line; @@ -219,7 +219,7 @@ void __profile_readlock (__profile_rwl *lock, int d, char * file, int line) { lock->last_acquired_at = location; if(!tup) { - tup = stasis_malloc(1, profile_tuple); + tup = stasis_alloc(profile_tuple); init_tuple(tup); @@ -258,7 +258,7 @@ void __profile_writelock (__profile_rwl *lock, int d, char * file, int line) { lock->last_acquired_at = location; if(!tup) { - tup = stasis_malloc(1, profile_tuple); + tup = stasis_alloc(profile_tuple); init_tuple(tup); diff --git a/src/stasis/dirtyPageTable.c b/src/stasis/dirtyPageTable.c index dd16506..4847e36 100644 --- a/src/stasis/dirtyPageTable.c +++ b/src/stasis/dirtyPageTable.c @@ -55,13 +55,13 @@ void stasis_dirty_page_table_set_dirty(stasis_dirty_page_table_t * dirtyPages, P pthread_mutex_lock(&dirtyPages->mutex); if(!p->dirty) { p->dirty = 1; - dpt_entry * e = stasis_malloc(1, dpt_entry); + dpt_entry * e = stasis_alloc(dpt_entry); e->p = p->id; e->lsn = p->LSN; const void * ret = rbsearch(e, dirtyPages->tableByPage); assert(ret == e); // otherwise, the entry was already in the table. - e = stasis_malloc(1, dpt_entry); + e = stasis_alloc(dpt_entry); e->p = p->id; e->lsn = p->LSN; ret = rbsearch(e, dirtyPages->tableByLsnAndPage); @@ -344,7 +344,7 @@ void stasis_dirty_page_table_set_buffer_manager(stasis_dirty_page_table_t * dpt, } stasis_dirty_page_table_t * stasis_dirty_page_table_init() { - stasis_dirty_page_table_t * ret = stasis_malloc(1, stasis_dirty_page_table_t); + stasis_dirty_page_table_t * ret = stasis_alloc(stasis_dirty_page_table_t); ret->outstanding_flush_lsns = stasis_util_multiset_create(); ret->tableByPage = rbinit(dpt_cmp_page, 0); diff --git a/src/stasis/io/debug.c b/src/stasis/io/debug.c index 59e33d6..2586729 100644 --- a/src/stasis/io/debug.c +++ b/src/stasis/io/debug.c @@ -61,7 +61,7 @@ static stasis_write_buffer_t * debug_write_buffer(stasis_handle_t * h, printf("tid=%9ld call write_buffer(%lx, %lld, %lld)\n", (long)(intptr_t)pthread_self(), (unsigned long)hh, off, len); fflush(stdout); stasis_write_buffer_t * ret = hh->write_buffer(hh,off,len); - stasis_write_buffer_t * retWrap = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t * retWrap = stasis_alloc(stasis_write_buffer_t); *retWrap = *ret; retWrap->h = h; retWrap->impl = ret; @@ -85,7 +85,7 @@ static stasis_read_buffer_t * debug_read_buffer(stasis_handle_t * h, printf("tid=%9ld call read_buffer(%lx, %lld, %lld)\n", (long)(intptr_t)pthread_self(), (unsigned long)hh, off, len); fflush(stdout); stasis_read_buffer_t * ret = hh->read_buffer(hh,off,len); - stasis_read_buffer_t * retWrap = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t * retWrap = stasis_alloc(stasis_read_buffer_t); *retWrap = *ret; retWrap->h = h; retWrap->impl = ret; @@ -156,9 +156,9 @@ struct stasis_handle_t debug_func = { stasis_handle_t * stasis_handle(open_debug)(stasis_handle_t * h) { - stasis_handle_t * ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t * ret = stasis_alloc(stasis_handle_t); *ret = debug_func; - ret->impl = stasis_malloc(1, debug_impl); + ret->impl = stasis_alloc(debug_impl); ((debug_impl*)(ret->impl))->h = h; return ret; } diff --git a/src/stasis/io/file.c b/src/stasis/io/file.c index f2a434b..8e53b87 100644 --- a/src/stasis/io/file.c +++ b/src/stasis/io/file.c @@ -245,7 +245,7 @@ static int file_write(stasis_handle_t *h, lsn_t off, const byte * dat, lsn_t len static stasis_write_buffer_t * file_write_buffer(stasis_handle_t * h, lsn_t off, lsn_t len) { // Allocate the handle - stasis_write_buffer_t * ret = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t * ret = stasis_alloc(stasis_write_buffer_t); if(!ret) { return NULL; } file_impl * impl = (file_impl*)h->impl; @@ -312,7 +312,7 @@ static int file_release_write_buffer(stasis_write_buffer_t * w) { static stasis_read_buffer_t * file_read_buffer(stasis_handle_t * h, lsn_t off, lsn_t len) { - stasis_read_buffer_t * ret = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t * ret = stasis_alloc(stasis_read_buffer_t); if(!ret) { return NULL; } byte * buf = stasis_malloc(len, byte); @@ -484,11 +484,11 @@ struct stasis_handle_t file_func = { }; stasis_handle_t * stasis_handle(open_file)(const char * filename, int flags, int mode) { - stasis_handle_t * ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t * ret = stasis_alloc(stasis_handle_t); if(!ret) { return NULL; } *ret = file_func; - file_impl * impl = stasis_malloc(1, file_impl); + file_impl * impl = stasis_alloc(file_impl); ret->impl = impl; pthread_mutex_init(&(impl->mut), 0); assert(sizeof(off_t) >= (64/8)); diff --git a/src/stasis/io/memory.c b/src/stasis/io/memory.c index 4737b9d..7b8601f 100644 --- a/src/stasis/io/memory.c +++ b/src/stasis/io/memory.c @@ -45,7 +45,7 @@ static stasis_write_buffer_t * mem_write_buffer(stasis_handle_t * h, lsn_t off, lsn_t len) { mem_impl* impl = (mem_impl*)(h->impl); - stasis_write_buffer_t * ret = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t * ret = stasis_alloc(stasis_write_buffer_t); if(!ret) { return NULL; } pthread_mutex_lock(&(impl->mut)); @@ -102,7 +102,7 @@ static stasis_read_buffer_t * mem_read_buffer(stasis_handle_t * h, mem_impl * impl = (mem_impl*)(h->impl); pthread_mutex_lock(&(impl->mut)); - stasis_read_buffer_t * ret = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t * ret = stasis_alloc(stasis_read_buffer_t); if(!ret) { return NULL; } if(off < 0 || off + len > impl->end_pos) { @@ -183,15 +183,15 @@ struct stasis_handle_t mem_func = { }; stasis_handle_t * stasis_handle(open_memory)() { - stasis_handle_t * ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t * ret = stasis_alloc(stasis_handle_t); if(!ret) { return NULL; } *ret = mem_func; - mem_impl * impl = stasis_malloc(1, mem_impl); + mem_impl * impl = stasis_alloc(mem_impl); ret->impl = impl; pthread_mutex_init(&(impl->mut), 0); impl->end_pos = 0; - impl->buf = malloc(0); + impl->buf = stasis_malloc(0, byte); impl->refcount = 1; return ret; diff --git a/src/stasis/io/non_blocking.c b/src/stasis/io/non_blocking.c index 4471089..f796b6f 100644 --- a/src/stasis/io/non_blocking.c +++ b/src/stasis/io/non_blocking.c @@ -66,7 +66,7 @@ static inline stasis_read_buffer_t* alloc_read_buffer_error(stasis_handle_t *h, int error) { assert(error); - stasis_read_buffer_t * r = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t * r = stasis_alloc(stasis_read_buffer_t); r->h = h; r->buf = 0; r->len = 0; @@ -78,7 +78,7 @@ static inline stasis_read_buffer_t* alloc_read_buffer_error(stasis_handle_t *h, static inline stasis_write_buffer_t* alloc_write_buffer_error (stasis_handle_t *h, int error) { assert(error); - stasis_write_buffer_t * w = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t * w = stasis_alloc(stasis_write_buffer_t); w->h = h; w->off = 0; w->buf = 0; @@ -214,7 +214,7 @@ static void releaseSlowHandle(nbw_impl * impl, stasis_handle_t * slow) { } static tree_node * allocTreeNode(lsn_t off, lsn_t len) { - tree_node * ret = stasis_malloc(1, tree_node); + tree_node * ret = stasis_alloc(tree_node); ret->start_pos = off; ret->end_pos = off + len; ret->dirty = CLEAN; @@ -408,11 +408,11 @@ static stasis_write_buffer_t * nbw_write_buffer(stasis_handle_t * h, const tree_node * n = allocFastHandle(impl, off, len); stasis_write_buffer_t * w = n->h->write_buffer(n->h, off, len); - write_buffer_impl * w_impl = stasis_malloc(1, write_buffer_impl); + write_buffer_impl * w_impl = stasis_alloc(write_buffer_impl); w_impl->n = n; w_impl->w = w; - stasis_write_buffer_t * ret = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t * ret = stasis_alloc(stasis_write_buffer_t); ret->h = h; ret->off = w->off; ret->len = w->len; @@ -454,11 +454,11 @@ static stasis_read_buffer_t * nbw_read_buffer(stasis_handle_t * h, stasis_handle_t * r_h = n ? n->h : getSlowHandle(impl); r = r_h->read_buffer(r_h, off, len); - read_buffer_impl * r_impl = stasis_malloc(1, read_buffer_impl); + read_buffer_impl * r_impl = stasis_alloc(read_buffer_impl); r_impl->n = n; r_impl->r = r; - stasis_read_buffer_t * ret = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t * ret = stasis_alloc(stasis_read_buffer_t); ret->h = h; ret->off = r->off; ret->len = r->len; @@ -665,7 +665,7 @@ static void * nbw_worker(void * handle) { memcpy(buf, r->buf, r->len); buf_off += r->len; - dummies = stasis_malloc(1, tree_node); + dummies = stasis_alloc(tree_node); dummies[0] = dummy; dummy_count = 1; first = 0; @@ -774,7 +774,7 @@ stasis_handle_t * stasis_handle(open_non_blocking) stasis_handle_t * (*fast_factory)(lsn_t, lsn_t, void *), void * fast_factory_arg, int worker_thread_count, lsn_t buffer_size, int max_fast_handles) { - nbw_impl * impl = stasis_malloc(1, nbw_impl); + nbw_impl * impl = stasis_alloc(nbw_impl); pthread_mutex_init(&impl->mut, 0); impl->end_pos = 0; @@ -787,7 +787,7 @@ stasis_handle_t * stasis_handle(open_non_blocking) impl->available_slow_handles = 0; impl->available_slow_handle_count = 0; - impl->all_slow_handles = stasis_malloc(1, stasis_handle_t*); + impl->all_slow_handles = stasis_alloc(stasis_handle_t*); impl->all_slow_handle_count = 0; impl->requested_bytes_written = 0; @@ -812,7 +812,7 @@ stasis_handle_t * stasis_handle(open_non_blocking) impl->still_open = 1; impl->refcount = 1; - stasis_handle_t *h = stasis_malloc(1, stasis_handle_t); + stasis_handle_t *h = stasis_alloc(stasis_handle_t); *h = nbw_func; h->impl = impl; @@ -855,7 +855,7 @@ static stasis_handle_t * slow_pfile_factory(void * argsP) { return h; } static int nop_close(stasis_handle_t*h) { return 0; } - struct sf_args * slow_arg = stasis_malloc(1, struct sf_args); + struct sf_args * slow_arg = stasis_alloc(struct sf_args); slow_arg->filename = path; slow_arg->openMode = openMode; diff --git a/src/stasis/io/pfile.c b/src/stasis/io/pfile.c index 21bc65c..a07b9a3 100644 --- a/src/stasis/io/pfile.c +++ b/src/stasis/io/pfile.c @@ -198,7 +198,7 @@ static int pfile_write(stasis_handle_t *h, lsn_t off, const byte *dat, static stasis_write_buffer_t * pfile_write_buffer(stasis_handle_t *h, lsn_t off, lsn_t len) { - stasis_write_buffer_t *ret = stasis_malloc(1, stasis_write_buffer_t); + stasis_write_buffer_t *ret = stasis_alloc(stasis_write_buffer_t); if (!ret) { h->error = ENOMEM; @@ -249,7 +249,7 @@ static int pfile_release_write_buffer(stasis_write_buffer_t *w) { static stasis_read_buffer_t *pfile_read_buffer(stasis_handle_t *h, lsn_t off, lsn_t len) { - stasis_read_buffer_t *ret = stasis_malloc(1, stasis_read_buffer_t); + stasis_read_buffer_t *ret = stasis_alloc(stasis_read_buffer_t); if (!ret) { return NULL; } byte *buf = stasis_malloc(len,byte); @@ -417,11 +417,11 @@ static struct stasis_handle_t pfile_func = { stasis_handle_t *stasis_handle(open_pfile)(const char *filename, int flags, int mode) { - stasis_handle_t *ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t *ret = stasis_alloc(stasis_handle_t); if (!ret) { return NULL; } *ret = pfile_func; - pfile_impl *impl = stasis_malloc(1, pfile_impl); + pfile_impl *impl = stasis_alloc(pfile_impl); if (!impl) { free(ret); return NULL; } ret->impl = impl; diff --git a/src/stasis/io/raid0.c b/src/stasis/io/raid0.c index ba76833..1e5dafc 100644 --- a/src/stasis/io/raid0.c +++ b/src/stasis/io/raid0.c @@ -191,9 +191,9 @@ struct stasis_handle_t raid0_func = { }; stasis_handle_t * stasis_handle_open_raid0(int handle_count, stasis_handle_t** h, uint32_t stripe_size) { - stasis_handle_t * ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t * ret = stasis_alloc(stasis_handle_t); *ret = raid0_func; - raid0_impl * r = stasis_malloc(1, raid0_impl); + raid0_impl * r = stasis_alloc(raid0_impl); r->stripe_size = stripe_size; r->handle_count = handle_count; r->h = stasis_malloc(handle_count, stasis_handle_t*); diff --git a/src/stasis/io/raid1.c b/src/stasis/io/raid1.c index 32c489f..a2a3ec9 100644 --- a/src/stasis/io/raid1.c +++ b/src/stasis/io/raid1.c @@ -149,9 +149,9 @@ struct stasis_handle_t raid1_func = { }; stasis_handle_t * stasis_handle_open_raid1(stasis_handle_t* a, stasis_handle_t* b) { - stasis_handle_t * ret = stasis_malloc(1, stasis_handle_t); + stasis_handle_t * ret = stasis_alloc(stasis_handle_t); *ret = raid1_func; - raid1_impl * i = stasis_malloc(1, raid1_impl); + raid1_impl * i = stasis_alloc(raid1_impl); i->a = a; i->b = b; ret->impl = i; return ret; diff --git a/src/stasis/io/rangeTracker.c b/src/stasis/io/rangeTracker.c index 7980a13..99e0a0f 100644 --- a/src/stasis/io/rangeTracker.c +++ b/src/stasis/io/rangeTracker.c @@ -24,7 +24,7 @@ static int cmp_transition(const void * a, const void * b, const void * arg) { } rangeTracker * rangeTrackerInit(int quantization) { - rangeTracker * ret = stasis_malloc(1, rangeTracker); + rangeTracker * ret = stasis_alloc(rangeTracker); ret->ranges = RB_ENTRY(init)(cmp_transition, 0); ret->quantization = quantization; return ret; @@ -64,7 +64,7 @@ static void rangeTrackerDelta(rangeTracker * rt, const range * r, int delta) { assert(t->pins + t->delta >= 0); if(t->pos != r->start) { int newpins = t->pins + t->delta; - t = stasis_malloc(1, transition); + t = stasis_alloc(transition); t->pos = r->start; t->delta = delta; t->pins = newpins; @@ -84,7 +84,7 @@ static void rangeTrackerDelta(rangeTracker * rt, const range * r, int delta) { } } } else { - t = stasis_malloc(1, transition); + t = stasis_alloc(transition); t->pos = r->start; t->delta = delta; t->pins = 0; @@ -111,7 +111,7 @@ static void rangeTrackerDelta(rangeTracker * rt, const range * r, int delta) { } if(!t || t->pos != r->stop) { // Need to allocate new transition - t = stasis_malloc(1, transition); + t = stasis_alloc(transition); t->pos = r->stop; t->delta = 0-delta; t->pins = curpin; @@ -167,7 +167,7 @@ static range ** rangeTrackerToArray(rangeTracker * rt) { assert(!t->pins); assert(t->delta); assert(! ret[next_range] ); - ret[next_range] = stasis_malloc(1, range); + ret[next_range] = stasis_alloc(range); ret[next_range]->start = t->pos; in_range = 1; } @@ -175,7 +175,7 @@ static range ** rangeTrackerToArray(rangeTracker * rt) { if(t->pins + t->delta) { if(!in_range) { assert(! ret[next_range]); - ret[next_range] = stasis_malloc(1, range); + ret[next_range] = stasis_alloc(range); ret[next_range]->start = t->pos; in_range = 1; } diff --git a/src/stasis/logger/filePool.c b/src/stasis/logger/filePool.c index 45d866f..4ef291b 100644 --- a/src/stasis/logger/filePool.c +++ b/src/stasis/logger/filePool.c @@ -352,7 +352,7 @@ LogEntry * stasis_log_file_pool_reserve_entry(stasis_log_t * log, size_t szs) { uint32_t sz = szs; stasis_log_file_pool_state * fp = log->impl; lsn_t * handle = pthread_getspecific(fp->handle_key); - if(!handle) { handle = stasis_malloc(1, lsn_t); pthread_setspecific(fp->handle_key, handle); } + if(!handle) { handle = stasis_alloc(lsn_t); pthread_setspecific(fp->handle_key, handle); } uint64_t framed_size = sz+sizeof(uint32_t)+sizeof(uint32_t); lsn_t off = stasis_ringbuffer_reserve_space(fp->ring, framed_size, handle); @@ -731,8 +731,8 @@ int filesort(const void * ap, const void * bp) { */ stasis_log_t* stasis_log_file_pool_open(const char* dirname, int filemode, int fileperm) { struct dirent **namelist; - stasis_log_file_pool_state* fp = stasis_malloc(1, stasis_log_file_pool_state); - stasis_log_t * ret = stasis_malloc(1, stasis_log_t); + stasis_log_file_pool_state* fp = stasis_alloc(stasis_log_file_pool_state); + stasis_log_t * ret = stasis_alloc(stasis_log_t); static const stasis_log_t proto = { stasis_log_file_pool_set_truncation, diff --git a/src/stasis/logger/groupForce.c b/src/stasis/logger/groupForce.c index 8677e9f..1d78176 100644 --- a/src/stasis/logger/groupForce.c +++ b/src/stasis/logger/groupForce.c @@ -27,7 +27,7 @@ stasis_log_group_force_t * stasis_log_group_force_init(stasis_log_t * log, uint6 "times > 1 second. (%llu second wait time requested)\n", (long long unsigned int) (wait_nsec / (1000 * 1000 * 1000))); } - stasis_log_group_force_t * ret = stasis_malloc(1, stasis_log_group_force_t); + stasis_log_group_force_t * ret = stasis_alloc(stasis_log_group_force_t); ret->log = log; pthread_mutex_init(&ret->check_commit,0); pthread_cond_init(&ret->tooFewXacts,0); diff --git a/src/stasis/logger/inMemoryLog.c b/src/stasis/logger/inMemoryLog.c index 3e79da8..11c9879 100644 --- a/src/stasis/logger/inMemoryLog.c +++ b/src/stasis/logger/inMemoryLog.c @@ -189,7 +189,7 @@ static void stasis_log_impl_in_memory_set_truncation(stasis_log_t *log, stasis_t } stasis_log_t* stasis_log_impl_in_memory_open() { - stasis_log_impl_in_memory * impl = stasis_malloc(1, stasis_log_impl_in_memory); + stasis_log_impl_in_memory * impl = stasis_alloc(stasis_log_impl_in_memory); impl->flushedLSN_lock = initlock(); impl->globalOffset_lock = initlock(); impl->globalOffset = 0; @@ -221,7 +221,7 @@ stasis_log_t* stasis_log_impl_in_memory_open() { stasis_log_impl_in_memory_close, stasis_log_impl_in_memory_is_durable }; - stasis_log_t* log = stasis_malloc(1, stasis_log_t); + stasis_log_t* log = stasis_alloc(stasis_log_t); memcpy(log,&proto, sizeof(proto)); log->impl = impl; return log; diff --git a/src/stasis/logger/logHandle.c b/src/stasis/logger/logHandle.c index baf87e7..c0f9fc5 100644 --- a/src/stasis/logger/logHandle.c +++ b/src/stasis/logger/logHandle.c @@ -68,7 +68,7 @@ LogHandle* getLogHandle(stasis_log_t* log) { } LogHandle* getLSNHandle(stasis_log_t * log, lsn_t lsn) { - LogHandle* ret = stasis_malloc(1, LogHandle); + LogHandle* ret = stasis_alloc(LogHandle); ret->next_offset = lsn; ret->prev_offset = lsn; ret->last = 0; diff --git a/src/stasis/logger/reorderingHandle.c b/src/stasis/logger/reorderingHandle.c index 8075bfc..815ccec 100644 --- a/src/stasis/logger/reorderingHandle.c +++ b/src/stasis/logger/reorderingHandle.c @@ -86,7 +86,7 @@ stasis_log_reordering_handle_open(stasis_transaction_table_entry_t * l, size_t chunk_len, size_t max_len, size_t max_size) { - stasis_log_reordering_handle_t * ret = stasis_malloc(1, stasis_log_reordering_handle_t); + stasis_log_reordering_handle_t * ret = stasis_alloc(stasis_log_reordering_handle_t); ret->l = l; ret->log = log; @@ -94,7 +94,7 @@ stasis_log_reordering_handle_open(stasis_transaction_table_entry_t * l, pthread_cond_init(&ret->done,0); pthread_cond_init(&ret->ready,0); ret->closed = 0; - ret->queue = malloc(sizeof(stasis_log_reordering_op_t)*max_len); + ret->queue = stasis_malloc(max_len, stasis_log_reordering_op_t); ret->chunk_len = chunk_len; ret->max_len = max_len; ret->cur_off = 0; diff --git a/src/stasis/logger/safeWrites.c b/src/stasis/logger/safeWrites.c index 2acd970..e8fc6d6 100644 --- a/src/stasis/logger/safeWrites.c +++ b/src/stasis/logger/safeWrites.c @@ -840,7 +840,7 @@ stasis_log_t* stasis_log_safe_writes_open(const char * filename, isDurable_LogWriter, // is_durable }; - stasis_log_safe_writes_state * sw = stasis_malloc(1, stasis_log_safe_writes_state); + stasis_log_safe_writes_state * sw = stasis_alloc(stasis_log_safe_writes_state); sw->filename = strdup(filename); { char * log_scratch_filename = malloc(strlen(sw->filename) + 2); @@ -852,7 +852,7 @@ stasis_log_t* stasis_log_safe_writes_open(const char * filename, sw->fileperm = fileperm; sw->softcommit = softcommit; - stasis_log_t* log = stasis_malloc(1, stasis_log_t); + stasis_log_t* log = stasis_alloc(stasis_log_t); memcpy(log,&proto, sizeof(proto)); log->impl = sw; diff --git a/src/stasis/operations/alloc.c b/src/stasis/operations/alloc.c index 8e6a593..ad4ddba 100644 --- a/src/stasis/operations/alloc.c +++ b/src/stasis/operations/alloc.c @@ -212,7 +212,7 @@ int stasis_alloc_callback(int xid, void * arg) { } stasis_alloc_t* stasis_alloc_init(stasis_transaction_table_t * tbl, stasis_allocation_policy_t * allocPolicy) { - stasis_alloc_t * alloc = stasis_malloc(1, stasis_alloc_t); + stasis_alloc_t * alloc = stasis_alloc(stasis_alloc_t); alloc->lastFreepage = PAGEID_T_MAX; alloc->allocPolicy = allocPolicy; pthread_mutex_init(&alloc->mut, 0); @@ -425,7 +425,7 @@ void Tdealloc(int xid, recordid rid) { if(type == NORMAL_SLOT) { type = size; } - byte * preimage = malloc(sizeof(alloc_arg)+size); + byte * preimage = (byte*)stasis_malloc_trailing_array(alloc_arg, size); ((alloc_arg*)preimage)->slot = rid.slot; ((alloc_arg*)preimage)->type = type; diff --git a/src/stasis/operations/bTree.c b/src/stasis/operations/bTree.c index 5e67d60..c71c02e 100644 --- a/src/stasis/operations/bTree.c +++ b/src/stasis/operations/bTree.c @@ -66,7 +66,7 @@ static int cmp_slot(int xid, Page *p, slotid_t slot, byte * key, size_t keySize, recordid rid = {p->id, slot, 0}; rid.size = stasis_record_length_read(xid, p, rid); if(rid.size == INVALID_SLOT) { return 1; } // treat invalid slots as infinity. - byte * cur = malloc(rid.size); + byte * cur = stasis_malloc(rid.size, byte); stasis_record_read(xid, p, rid, cur); byte * cur_ptr; size_t cur_len; @@ -149,7 +149,7 @@ int TbtreeLookup(int xid, recordid rid, void * cmp_arg, byte * key, size_t keySi btree_leaf_pair * buf = malloc(slotrid.size); stasis_record_read(xid, p, slotrid, (byte*)buf); *valueSize = slotrid.size - (buf->keylen + sizeof(btree_leaf_pair)); - *value = malloc(*valueSize); + *value = stasis_malloc(*valueSize, byte); memcpy(*value, ((byte*)(buf+1))+buf->keylen, *valueSize); unlock(p->rwlatch); releasePage(p); diff --git a/src/stasis/operations/linearHashNTA.c b/src/stasis/operations/linearHashNTA.c index f6b55dd..a5174f4 100644 --- a/src/stasis/operations/linearHashNTA.c +++ b/src/stasis/operations/linearHashNTA.c @@ -456,9 +456,9 @@ typedef struct { } lladd_linearHashNTA_generic_it; lladdIterator_t * ThashGenericIterator(int xid, recordid hash) { - lladdIterator_t * ret = stasis_malloc(1, lladdIterator_t); + lladdIterator_t * ret = stasis_alloc(lladdIterator_t); ret->type = LINEAR_HASH_NTA_ITERATOR; - ret->impl = stasis_malloc(1, lladd_linearHashNTA_generic_it); + ret->impl = stasis_alloc(lladd_linearHashNTA_generic_it); ((lladd_linearHashNTA_generic_it*)(ret->impl))->hit = ThashIterator(xid, hash, -1, -1); ((lladd_linearHashNTA_generic_it*)(ret->impl))->lastKey = NULL; diff --git a/src/stasis/operations/linkedListNTA.c b/src/stasis/operations/linkedListNTA.c index b265dc8..c2c81ed 100644 --- a/src/stasis/operations/linkedListNTA.c +++ b/src/stasis/operations/linkedListNTA.c @@ -104,7 +104,7 @@ int TlinkedListInsert(int xid, recordid list, const byte * key, int keySize, con ret = TlinkedListRemove(xid, list, key, keySize); } end_ret(compensation_error()); */ - stasis_linked_list_insert_log * undoLog = malloc(sizeof(stasis_linked_list_insert_log) + keySize); + stasis_linked_list_insert_log * undoLog = stasis_malloc_trailing_array(stasis_linked_list_insert_log, keySize); undoLog->list = list; undoLog->keySize = keySize; @@ -144,7 +144,7 @@ stasis_operation_impl stasis_op_impl_linked_list_remove() { return o; } static void stasis_linked_list_insert_helper(int xid, recordid list, const byte * key, int keySize, const byte * value, int valueSize) { - stasis_linkedList_entry * entry = malloc(sizeof(stasis_linkedList_entry) + keySize + valueSize); + stasis_linkedList_entry * entry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize); Tread(xid, list, entry); if(!entry->next.size) { @@ -155,7 +155,7 @@ static void stasis_linked_list_insert_helper(int xid, recordid list, const byte entry->next.size = -1; Tset(xid, list, entry); } else { - stasis_linkedList_entry * newEntry = malloc(sizeof(stasis_linkedList_entry) + keySize + valueSize); + stasis_linkedList_entry * newEntry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize); memcpy(newEntry + 1, key, keySize); memcpy(((byte*)(newEntry+1))+keySize, value, valueSize); newEntry->next = entry->next; @@ -189,7 +189,7 @@ int TlinkedListFind(int xid, recordid list, const byte * key, int keySize, byte if(!memcmp(entry + 1, key, keySize)) { // Bucket contains the entry of interest. int valueSize = list.size - (sizeof(stasis_linkedList_entry) + keySize); - *value = malloc(valueSize); + *value = stasis_malloc(valueSize, byte); memcpy(*value, ((byte*)(entry+1))+keySize, valueSize); done = 1; ret = valueSize; @@ -356,7 +356,7 @@ void TlinkedListDelete(int xid, recordid list) { } stasis_linkedList_iterator * TlinkedListIterator(int xid, recordid list, int keySize, int valueSize) { - stasis_linkedList_iterator * it = malloc(sizeof(stasis_linkedList_iterator)); + stasis_linkedList_iterator * it = stasis_alloc(stasis_linkedList_iterator); it->keySize = keySize; it->valueSize = valueSize; it->next = list; @@ -411,8 +411,8 @@ int TlinkedListNext(int xid, stasis_linkedList_iterator * it, byte ** key, int * if(entry->next.size) { *keySize = it->keySize; *valueSize = it->valueSize; - *key = malloc(*keySize); - *value = malloc(*valueSize); + *key = stasis_malloc(*keySize, byte); + *value = stasis_malloc(*valueSize, byte); it->next = entry->next; diff --git a/src/stasis/operations/naiveLinearHash.c b/src/stasis/operations/naiveLinearHash.c index e57597b..23adad5 100644 --- a/src/stasis/operations/naiveLinearHash.c +++ b/src/stasis/operations/naiveLinearHash.c @@ -44,7 +44,7 @@ static int findInBucket(int xid, recordid hashRid, int bucket_number, const void static int findInBucket(int xid, recordid hashRid, int bucket_number, const void * key, int keySize, void * val, int valSize) { int found; - hashEntry * e = malloc(sizeof(hashEntry) + keySize + valSize); + hashEntry * e = stasis_malloc_trailing_array(hashEntry, keySize + valSize); recordid nextEntry; @@ -306,8 +306,8 @@ static int deleteFromBucket(int xid, recordid hash, int bucket_number, hashEntry if(bucket_contents->next.size == -1) { return 0; } - hashEntry * A = malloc(sizeof(hashEntry) + keySize + valSize); - hashEntry * B = malloc(sizeof(hashEntry) + keySize + valSize); + hashEntry * A = stasis_malloc_trailing_array(hashEntry, keySize + valSize); + hashEntry * B = stasis_malloc_trailing_array(hashEntry, keySize + valSize); recordid Aaddr, Baddr; @@ -432,7 +432,7 @@ int TnaiveHashDelete(int xid, recordid hashRid, recordid deleteMe; hashRid.slot = bucket_number; - hashEntry * bucket_contents = (hashEntry*)malloc(sizeof(hashEntry) + keySize + valSize); + hashEntry * bucket_contents = stasis_malloc_trailing_array(hashEntry, keySize + valSize); assert(hashRid.size == sizeof(hashEntry) + keySize + valSize); Tread(xid, hashRid, bucket_contents); hashRid.slot = 0; @@ -448,7 +448,7 @@ int TnaiveHashDelete(int xid, recordid hashRid, } int TnaiveHashOpen(int xid, recordid hashRid, int keySize, int valSize) { - recordid * headerRidB = (recordid*)malloc(sizeof(recordid) + keySize + valSize); + recordid * headerRidB = stasis_malloc_trailing_array(recordid, keySize + valSize); hashRid.slot = 1; Tread(xid, hashRid, headerRidB); diff --git a/src/stasis/operations/pageOrientedListNTA.c b/src/stasis/operations/pageOrientedListNTA.c index 5ef6fea..b57a38a 100644 --- a/src/stasis/operations/pageOrientedListNTA.c +++ b/src/stasis/operations/pageOrientedListNTA.c @@ -183,7 +183,7 @@ lladd_pagedList_iterator * TpagedListIterator(int xid, recordid list) { assert(list.size == sizeof(pagedListHeader)); Tread(xid, list, &header); - lladd_pagedList_iterator * it = stasis_malloc(1, lladd_pagedList_iterator); + lladd_pagedList_iterator * it = stasis_alloc(lladd_pagedList_iterator); it->headerRid = header.nextPage; it->entryRid = list; diff --git a/src/stasis/page.c b/src/stasis/page.c index b527584..3b01e27 100644 --- a/src/stasis/page.c +++ b/src/stasis/page.c @@ -381,10 +381,10 @@ block_t genericBlock = { }; block_t* stasis_block_first_default_impl(int xid, Page * p) { - block_t* ret = stasis_malloc(1, block_t); + block_t* ret = stasis_alloc(block_t); *ret = genericBlock; genericBlockImpl impl = { p, NULLRID }; - ret->impl = stasis_malloc(1, genericBlockImpl); + ret->impl = stasis_alloc(genericBlockImpl); *(genericBlockImpl*)(ret->impl) = impl; return ret; } diff --git a/src/stasis/pageHandle.c b/src/stasis/pageHandle.c index e019788..3e2838d 100644 --- a/src/stasis/pageHandle.c +++ b/src/stasis/pageHandle.c @@ -81,7 +81,7 @@ static void phClose(stasis_page_handle_t * ph) { free(ph); } static stasis_page_handle_t * phDup(stasis_page_handle_t * ph, int is_sequential) { - stasis_page_handle_t * ret = stasis_malloc(1, stasis_page_handle_t); + stasis_page_handle_t * ret = stasis_alloc(stasis_page_handle_t); memcpy(ret, ph, sizeof(*ret)); ret->impl = ((stasis_handle_t*)ret->impl)->dup(ret->impl); if(((stasis_handle_t*)ret->impl)->error != 0) { @@ -97,7 +97,7 @@ static stasis_page_handle_t * phDup(stasis_page_handle_t * ph, int is_sequential stasis_page_handle_t * stasis_page_handle_open(stasis_handle_t * handle, stasis_log_t * log, stasis_dirty_page_table_t * dpt) { DEBUG("Using pageHandle implementation\n"); - stasis_page_handle_t * ret = stasis_malloc(1, stasis_page_handle_t); + stasis_page_handle_t * ret = stasis_alloc(stasis_page_handle_t); ret->write = phWrite; ret->read = phRead; ret->prefetch_range = phPrefetchRange; diff --git a/src/stasis/recovery2.c b/src/stasis/recovery2.c index a046d1f..82ac623 100644 --- a/src/stasis/recovery2.c +++ b/src/stasis/recovery2.c @@ -67,7 +67,7 @@ static void stasis_recovery_analysis(stasis_log_t* log, stasis_transaction_table */ if(xactLSN == NULL) { - xactLSN = stasis_malloc(1, lsn_t); + xactLSN = stasis_alloc(lsn_t); lhinsert(transactionLSN, &(e->xid), sizeof(int), xactLSN); } else { /* We've seen this xact before, and must have put a value in diff --git a/src/stasis/replacementPolicy/clock.c b/src/stasis/replacementPolicy/clock.c index 0363ca1..39df89d 100644 --- a/src/stasis/replacementPolicy/clock.c +++ b/src/stasis/replacementPolicy/clock.c @@ -115,8 +115,8 @@ static void clockInsert (struct replacementPolicy* impl, Page* page) { } replacementPolicy* replacementPolicyClockInit(Page * pageArray, int page_count) { - replacementPolicy *ret = stasis_malloc(1, replacementPolicy); - stasis_replacement_policy_clock_t * clock = stasis_malloc(1, stasis_replacement_policy_clock_t); + replacementPolicy *ret = stasis_alloc(replacementPolicy); + stasis_replacement_policy_clock_t * clock = stasis_alloc(stasis_replacement_policy_clock_t); clock->pages = pageArray; clock->page_count = page_count; clock->ptr = 0; diff --git a/src/stasis/replacementPolicy/concurrentWrapper.c b/src/stasis/replacementPolicy/concurrentWrapper.c index 1c7afa3..4444a02 100644 --- a/src/stasis/replacementPolicy/concurrentWrapper.c +++ b/src/stasis/replacementPolicy/concurrentWrapper.c @@ -144,8 +144,8 @@ static void cwInsert (struct replacementPolicy* impl, Page* page) { } replacementPolicy* replacementPolicyConcurrentWrapperInit(replacementPolicy** rp, int count) { - replacementPolicy *ret = stasis_malloc(1, replacementPolicy); - stasis_replacement_policy_concurrent_wrapper_t * rpw = stasis_malloc(1, stasis_replacement_policy_concurrent_wrapper_t); + replacementPolicy *ret = stasis_alloc(replacementPolicy); + stasis_replacement_policy_concurrent_wrapper_t * rpw = stasis_alloc(stasis_replacement_policy_concurrent_wrapper_t); if(stasis_replacement_policy_concurrent_wrapper_power_of_two_buckets) { // ensure that count is a power of two. diff --git a/src/stasis/replacementPolicy/lru.c b/src/stasis/replacementPolicy/lru.c index a552f67..6af96e6 100644 --- a/src/stasis/replacementPolicy/lru.c +++ b/src/stasis/replacementPolicy/lru.c @@ -77,7 +77,7 @@ static Page* stasis_replacement_policy_lru_get_stale_and_remove(replacementPolic static void stasis_replacement_policy_lru_insert(replacementPolicy* r, Page* p) { stasis_replacement_policy_lru_t * l = r->impl; - stasis_replacement_policy_lru_entry * e = stasis_malloc(1, stasis_replacement_policy_lru_entry); + stasis_replacement_policy_lru_entry * e = stasis_alloc(stasis_replacement_policy_lru_entry); e->value = p; e->clock = l->now; l->now++; @@ -87,8 +87,8 @@ static void stasis_replacement_policy_lru_insert(replacementPolicy* r, Page* p) } replacementPolicy * stasis_replacement_policy_lru_init() { - replacementPolicy * ret = stasis_malloc(1, replacementPolicy); - stasis_replacement_policy_lru_t * l = stasis_malloc(1, stasis_replacement_policy_lru_t); + replacementPolicy * ret = stasis_alloc(replacementPolicy); + stasis_replacement_policy_lru_t * l = stasis_alloc(stasis_replacement_policy_lru_t); l->now = 0; l->hash = LH_ENTRY(create)(10); l->lru = RB_ENTRY(init)(stasis_replacement_policy_lru_entry_cmp, 0); diff --git a/src/stasis/replacementPolicy/lruFast.c b/src/stasis/replacementPolicy/lruFast.c index 518309d..720b511 100644 --- a/src/stasis/replacementPolicy/lruFast.c +++ b/src/stasis/replacementPolicy/lruFast.c @@ -110,14 +110,14 @@ static void stasis_lru_fast_deinit(struct replacementPolicy * r) { free(r); } replacementPolicy * lruFastInit() { - struct replacementPolicy * ret = stasis_malloc(1, struct replacementPolicy); + struct replacementPolicy * ret = stasis_alloc(struct replacementPolicy); ret->deinit = stasis_lru_fast_deinit; ret->hit = stasis_lru_fast_hit; ret->getStale = stasis_lru_fast_getStale; ret->remove = stasis_lru_fast_remove; ret->getStaleAndRemove = stasis_lru_fast_getStaleAndRemove; ret->insert = stasis_lru_fast_insert; - lruFast * l = stasis_malloc(1, lruFast); + lruFast * l = stasis_alloc(lruFast); llInit(&l->list); ret->impl = l; return ret; diff --git a/src/stasis/replacementPolicy/threadsafeWrapper.c b/src/stasis/replacementPolicy/threadsafeWrapper.c index b5a23e3..a3c4f1c 100644 --- a/src/stasis/replacementPolicy/threadsafeWrapper.c +++ b/src/stasis/replacementPolicy/threadsafeWrapper.c @@ -52,8 +52,8 @@ static void tsInsert (struct replacementPolicy* impl, Page* page) { } replacementPolicy* replacementPolicyThreadsafeWrapperInit(replacementPolicy* rp) { - replacementPolicy *ret = stasis_malloc(1, replacementPolicy); - stasis_replacement_policy_threadsafe_wrapper_t * rpw = stasis_malloc(1, stasis_replacement_policy_threadsafe_wrapper_t); + replacementPolicy *ret = stasis_alloc(replacementPolicy); + stasis_replacement_policy_threadsafe_wrapper_t * rpw = stasis_alloc(stasis_replacement_policy_threadsafe_wrapper_t); rpw->impl = rp; pthread_mutex_init(&rpw->mut,0); ret->init = NULL; diff --git a/src/stasis/transactionTable.c b/src/stasis/transactionTable.c index beb69c5..4c5b3bb 100644 --- a/src/stasis/transactionTable.c +++ b/src/stasis/transactionTable.c @@ -172,7 +172,7 @@ int stasis_transaction_table_set_argument(stasis_transaction_table_t *tbl, int x } int* stasis_transaction_table_list_active(stasis_transaction_table_t *tbl, int *count) { - int * ret = stasis_malloc(1, int); + int * ret = stasis_alloc(int); ret[0] = INVALID_XID; *count = 0; for(int i = 0; i < MAX_TRANSACTIONS; i++) { @@ -188,7 +188,7 @@ int* stasis_transaction_table_list_active(stasis_transaction_table_t *tbl, int * } stasis_transaction_table_t * stasis_transaction_table_init() { - stasis_transaction_table_t * tbl = stasis_malloc(1, stasis_transaction_table_t); + stasis_transaction_table_t * tbl = stasis_alloc(stasis_transaction_table_t); tbl->active_count = 0; #ifndef HAVE_GCC_ATOMICS @@ -307,7 +307,7 @@ stasis_transaction_table_entry_t * stasis_transaction_table_begin(stasis_transac struct stasis_transaction_table_thread_local_state_t * tls = pthread_getspecific(tbl->key); if(tls == NULL) { - tls = stasis_malloc(1, struct stasis_transaction_table_thread_local_state_t); + tls = stasis_alloc(struct stasis_transaction_table_thread_local_state_t); tls->last_entry = 0; tls->num_entries = 0; tls->entries = NULL; diff --git a/src/stasis/truncation.c b/src/stasis/truncation.c index 4ea72c0..18b7916 100644 --- a/src/stasis/truncation.c +++ b/src/stasis/truncation.c @@ -27,7 +27,7 @@ struct stasis_truncation_t { #endif stasis_truncation_t * stasis_truncation_init(stasis_dirty_page_table_t * dpt, stasis_transaction_table_t * tbl, stasis_buffer_manager_t *buffer_manager, stasis_log_t *log) { - stasis_truncation_t * ret = stasis_malloc(1, stasis_truncation_t); + stasis_truncation_t * ret = stasis_alloc(stasis_truncation_t); ret->initialized = 1; ret->automaticallyTruncating = 0; pthread_mutex_init(&ret->shutdown_mutex, 0); diff --git a/src/stasis/util/bloomFilter.c b/src/stasis/util/bloomFilter.c index b0be275..60f081b 100644 --- a/src/stasis/util/bloomFilter.c +++ b/src/stasis/util/bloomFilter.c @@ -78,7 +78,7 @@ stasis_bloom_filter_t * stasis_bloom_filter_create(uint64_t(*func_a)(const char* uint64_t(*func_b)(const char*,int), uint64_t num_expected_items, double false_positive_rate) { - stasis_bloom_filter_t * ret = stasis_malloc(1, stasis_bloom_filter_t); + stasis_bloom_filter_t * ret = stasis_alloc(stasis_bloom_filter_t); ret->func_a = func_a; ret->func_b = func_b; ret->num_expected_items = num_expected_items; diff --git a/src/stasis/util/concurrentHash.c b/src/stasis/util/concurrentHash.c index b473a94..105eab1 100644 --- a/src/stasis/util/concurrentHash.c +++ b/src/stasis/util/concurrentHash.c @@ -422,7 +422,7 @@ hashtable_t * hashtable_init(pageid_t size) { size /= 2; newsize *= 2; } - hashtable_t *ht = stasis_malloc(1, hashtable_t); + hashtable_t *ht = stasis_alloc(hashtable_t); ht->maxbucketid = (newsize) - 1; ht->buckets = calloc(ht->maxbucketid+1, sizeof(bucket_t)); diff --git a/src/stasis/util/doubleLinkedList.c b/src/stasis/util/doubleLinkedList.c index fb0c6c8..ddf02db 100644 --- a/src/stasis/util/doubleLinkedList.c +++ b/src/stasis/util/doubleLinkedList.c @@ -15,15 +15,15 @@ static inline struct LL_ENTRY(node_t)* LL_ENTRY(shiftNode) (struct LL_ENTRY(list static inline void LL_ENTRY(removeNode)(list * l, node_t * n); list * LL_ENTRY(create)(node_t*(*getNode)(value_t*v,void*conf), void(*setNode)(value_t*v,node_t*n,void*conf),void*conf) { - list* ret = stasis_malloc(1, list); + list* ret = stasis_alloc(list); // bypass const annotation on head, tail... list tmp = { getNode, setNode, conf, - stasis_malloc(1,node_t), - stasis_malloc(1,node_t) + stasis_alloc(node_t), + stasis_alloc(node_t) }; memcpy(ret, &tmp, sizeof(list)); @@ -44,7 +44,7 @@ void LL_ENTRY(destroy)(list* l) { free(l); } int LL_ENTRY(push)(list* l, value_t * v) { - node_t * n = stasis_malloc(1, node_t); + node_t * n = stasis_alloc(node_t); if(!n) { return ENOMEM; } n->v = v; assert(l->getNode(v, l->conf) == 0); @@ -65,7 +65,7 @@ value_t* LL_ENTRY(pop) (list* l) { } } int LL_ENTRY(unshift)(list* l, value_t * v) { - node_t * n = stasis_malloc(1, node_t); + node_t * n = stasis_alloc(node_t); if(!n) { return ENOMEM; } n->v = v; assert(l->getNode(v, l->conf) == 0); diff --git a/src/stasis/util/lhtable.c b/src/stasis/util/lhtable.c index eba7c1a..e7bf228 100644 --- a/src/stasis/util/lhtable.c +++ b/src/stasis/util/lhtable.c @@ -135,7 +135,7 @@ static struct LH_ENTRY(pair_t)* insertIntoLinkedList(struct LH_ENTRY(table) * t thePair->value = value; } else { // the bucket isn't empty. - thePair = stasis_malloc(1, struct LH_ENTRY(pair_t)); + thePair = stasis_alloc(struct LH_ENTRY(pair_t)); thePair->key = (const LH_ENTRY(key_t) *)malloc(len); memcpy((void*)thePair->key, key, len); thePair->keyLength = len; @@ -220,7 +220,7 @@ static void extendHashTable(struct LH_ENTRY(table) * table) { struct LH_ENTRY(table) * LH_ENTRY(create)(int initialSize) { - struct LH_ENTRY(table) * ret = stasis_malloc(1, struct LH_ENTRY(table)); + struct LH_ENTRY(table) * ret = stasis_alloc(struct LH_ENTRY(table)); ret->bucketList = calloc(initialSize, sizeof(struct LH_ENTRY(pair_t))); HASH_ENTRY(_get_size_params)(initialSize, &(ret->bucketListBits), @@ -466,7 +466,7 @@ void * pblHtFirst ( pblHashTable_t * h ) { if(pblLists == 0) { pblLists = LH_ENTRY(create)(10); } - struct LH_ENTRY(list) *list = stasis_malloc(1, struct LH_ENTRY(list)); + struct LH_ENTRY(list) *list = stasis_alloc(struct LH_ENTRY(list)); struct LH_ENTRY(list) * oldList; if((oldList = LH_ENTRY(insert)(pblLists, diff --git a/src/stasis/util/linkedlist.c b/src/stasis/util/linkedlist.c index e6fc160..677425f 100644 --- a/src/stasis/util/linkedlist.c +++ b/src/stasis/util/linkedlist.c @@ -56,7 +56,7 @@ void printList(LinkedList **l) { printf (".\n"); } void addVal(LinkedList **list, long val) { - LinkedList * node = stasis_malloc(1, LinkedList); + LinkedList * node = stasis_alloc(LinkedList); node->val = val; node->next = NULL; if (*list==NULL) { @@ -105,7 +105,7 @@ long popMaxVal(LinkedList **list) { void addSortedVal(LinkedList **list, long val) { LinkedList * tmp; LinkedList * tmpprev; - LinkedList * node = stasis_malloc(1, LinkedList); + LinkedList * node = stasis_alloc(LinkedList); node->val = val; /*see if new entry should come in the beginning*/ if ((*list==NULL) || ((*list)->valtree = rbinit(cmp_lsn_t,0); } else { @@ -58,7 +58,7 @@ void stasis_aggregate_min_add(stasis_aggregate_min_t * min, lsn_t * a) { } lsn_t * p = pthread_getspecific(min->key); if(!p) { - p = stasis_malloc(1, lsn_t); + p = stasis_alloc(lsn_t); *p = -1; pthread_setspecific(min->key, p); } diff --git a/src/stasis/util/multiset.c b/src/stasis/util/multiset.c index 6240b6a..718ded6 100644 --- a/src/stasis/util/multiset.c +++ b/src/stasis/util/multiset.c @@ -8,8 +8,8 @@ struct stasis_util_multiset_t { }; stasis_util_multiset_t * stasis_util_multiset_create() { - stasis_util_multiset_t * set = stasis_malloc(1, stasis_util_multiset_t); - set->items = stasis_malloc(1, lsn_t); + stasis_util_multiset_t * set = stasis_alloc(stasis_util_multiset_t); + set->items = stasis_alloc(lsn_t); set->item_count = 0; return set; } diff --git a/src/stasis/util/ringbuffer.c b/src/stasis/util/ringbuffer.c index a7b65aa..077c167 100644 --- a/src/stasis/util/ringbuffer.c +++ b/src/stasis/util/ringbuffer.c @@ -272,7 +272,7 @@ stasis_ringbuffer_t * stasis_ringbuffer_init(intptr_t base, lsn_t initial_offset return 0; } - stasis_ringbuffer_t * ring = stasis_malloc(1, stasis_ringbuffer_t); + stasis_ringbuffer_t * ring = stasis_alloc(stasis_ringbuffer_t); // Allocate the memory region using mmap black magic. diff --git a/src/stasis/util/slab.c b/src/stasis/util/slab.c index 2ca627e..0047cae 100644 --- a/src/stasis/util/slab.c +++ b/src/stasis/util/slab.c @@ -25,11 +25,11 @@ struct stasis_util_slab_t { * @return a slab allocator. Calling stasis_util_slab_destroy() will deallocate it all-at-once. */ stasis_util_slab_t * stasis_util_slab_create(uint32_t obj_sz, uint32_t block_sz) { - stasis_util_slab_t* ret = stasis_malloc(1, stasis_util_slab_t); + stasis_util_slab_t* ret = stasis_alloc(stasis_util_slab_t); // printf("slab init: obj siz = %lld, block_sz = %lld\n", (long long)obj_sz, (long long)block_sz); - ret->blocks = stasis_malloc(1, byte*); + ret->blocks = stasis_alloc(byte*); ret->blocks[0] = stasis_malloc(block_sz, byte); ret->freelist_ptr = 0; diff --git a/stasis/util/concurrentSkipList.h b/stasis/util/concurrentSkipList.h index f5cd697..21831bc 100644 --- a/stasis/util/concurrentSkipList.h +++ b/stasis/util/concurrentSkipList.h @@ -80,7 +80,7 @@ int stasis_util_skiplist_default_key_finalize(void * p, void * ignored) { static inline int stasis_util_skiplist_random_level(pthread_key_t k) { kiss_table_t * kiss = pthread_getspecific(k); if(kiss == 0) { - kiss = stasis_malloc(1, kiss_table_t); + kiss = stasis_alloc(kiss_table_t); stasis_util_random_kiss_settable(kiss, random(), random(), random(), random(), random(), random()); pthread_setspecific(k, kiss); @@ -134,7 +134,7 @@ static inline int stasis_util_skiplist_cmp_helper2( static inline stasis_skiplist_t * stasis_util_skiplist_init( int (*cmp)(const void*, const void*), int (*finalize)(void *, void * nul)) { - stasis_skiplist_t * list = stasis_malloc(1, stasis_skiplist_t); + stasis_skiplist_t * list = stasis_alloc(stasis_skiplist_t); list->levelCap = 32; list->h = hazard_init(STASIS_SKIPLIST_HP_COUNT+list->levelCap, STASIS_SKIPLIST_HP_COUNT, 250, stasis_util_skiplist_node_finalize, list); diff --git a/stasis/util/hazard.h b/stasis/util/hazard.h index 8cf2a13..a70ebe3 100644 --- a/stasis/util/hazard.h +++ b/stasis/util/hazard.h @@ -127,7 +127,7 @@ static void hazard_deinit_thread(void * p) { */ static inline hazard_t* hazard_init(int hp_slots, int stack_start, int r_slots, int (*finalizer)(void*, void*), void * conf) { - hazard_t * ret = stasis_malloc(1, hazard_t); + hazard_t * ret = stasis_alloc(hazard_t); pthread_key_create(&ret->hp, hazard_deinit_thread); ret->num_slots = hp_slots; ret->stack_start = stack_start; @@ -142,7 +142,7 @@ static inline hazard_t* hazard_init(int hp_slots, int stack_start, int r_slots, static inline hazard_ptr_rec_t * hazard_ensure_tls(hazard_t * h) { hazard_ptr_rec_t * rec = pthread_getspecific(h->hp); if(rec == NULL) { - rec = stasis_malloc(1, hazard_ptr_rec_t); + rec = stasis_alloc(hazard_ptr_rec_t); rec->hp = calloc(h->num_slots, sizeof(hazard_ptr)); rec->rlist = calloc(h->num_r_slots, sizeof(hazard_ptr)); rec->rlist_len = 0; diff --git a/stasis/util/histogram.h b/stasis/util/histogram.h index bdf8806..5982eb0 100644 --- a/stasis/util/histogram.h +++ b/stasis/util/histogram.h @@ -66,7 +66,7 @@ static inline void stasis_histogram_insert_log_timeval(stasis_histogram_64_t* hi static inline void stasis_histogram_tick(stasis_histogram_64_t* hist) { struct timeval * val = pthread_getspecific(hist->tls); - if(!val) { val = stasis_malloc(1, struct timeval); pthread_setspecific(hist->tls, val); } + if(!val) { val = stasis_alloc(struct timeval); pthread_setspecific(hist->tls, val); } gettimeofday(val,0); } static inline void stasis_histogram_tock(stasis_histogram_64_t* hist) { diff --git a/stasis/util/malloc.h b/stasis/util/malloc.h index 4209cbd..d8fb941 100644 --- a/stasis/util/malloc.h +++ b/stasis/util/malloc.h @@ -10,7 +10,9 @@ #include +#define stasis_alloc(typ) ((typ*)malloc(sizeof(typ))) #define stasis_malloc(cnt, typ) ((typ*)malloc((cnt)*sizeof(typ))) +#define stasis_malloc_trailing_array(typ, array_sz) ((typ*)malloc(sizeof(typ)+(array_sz))) #define stasis_calloc(cnt, typ) ((typ*)calloc((cnt),sizeof(typ))) #define stasis_realloc(ptr, cnt, typ) ((typ*)realloc(ptr, (cnt)*sizeof(typ))) #define stasis_free(ptr) free(ptr) diff --git a/stasis/util/rw.h b/stasis/util/rw.h index 7848019..5b60360 100644 --- a/stasis/util/rw.h +++ b/stasis/util/rw.h @@ -33,7 +33,7 @@ BEGIN_C_DECLS typedef pthread_rwlock_t rwl; static inline rwl* initlock(void) { - rwl* ret = stasis_malloc(1, rwl); + rwl* ret = stasis_alloc(rwl); int err = pthread_rwlock_init(ret, 0); if(err) { perror("couldn't init rwlock"); abort(); } DEBUG("initlock(%llx)\n", (long long)ret); @@ -119,7 +119,7 @@ typedef struct rwlc { } rwlc; static inline rwlc* rwlc_initlock(void) { - rwlc* ret = stasis_malloc(1, rwlc); + rwlc* ret = stasis_alloc(rwlc); ret->rw = initlock(); int err = pthread_mutex_init(&ret->mut, 0); ret->is_writelocked = 0;