diff --git a/src/stasis/bufferManager/bufferHash.c b/src/stasis/bufferManager/bufferHash.c index 86a707e..e5c73f6 100644 --- a/src/stasis/bufferManager/bufferHash.c +++ b/src/stasis/bufferManager/bufferHash.c @@ -132,7 +132,7 @@ inline static int tryToWriteBackPage(stasis_buffer_manager_t *bm, pageid_t page) inline static Page * getFreePage(stasis_buffer_manager_t *bm) { stasis_buffer_hash_t * bh = bm->impl; Page * ret; - if(bh->pageCount < MAX_BUFFER_SIZE) { + if(bh->pageCount < stasis_buffer_manager_size) { ret = stasis_buffer_pool_malloc_page(bh->buffer_pool); stasis_buffer_pool_free_page(bh->buffer_pool, ret,-1); (*pagePendingPtr(ret)) = 0; @@ -219,7 +219,7 @@ static Page * bhGetCachedPage(stasis_buffer_manager_t* bm, int xid, const pageid } static Page * bhLoadPageImpl_helper(stasis_buffer_manager_t* bm, stasis_buffer_manager_handle_t* handle, - int xid, const pageid_t pageid, int uninitialized, pagetype_t type) { + int xid, const pageid_t pageid, int uninitialized, pagetype_t type) { stasis_buffer_hash_t * bh = bm->impl; DEBUG("load %lld (%d)\n", pageid, uninitialized); @@ -549,7 +549,7 @@ stasis_buffer_manager_t* stasis_buffer_manager_hash_open(stasis_page_handle_t * bh->lru = lruFastInit(pageGetNode, pageSetNode, pagePinCountPtr, 0); - bh->cachedPages = LH_ENTRY(create)(MAX_BUFFER_SIZE); + bh->cachedPages = LH_ENTRY(create)(stasis_buffer_manager_size); bh->pageCount = 0; diff --git a/src/stasis/bufferManager/concurrentBufferManager.c b/src/stasis/bufferManager/concurrentBufferManager.c index ce546bf..767681f 100644 --- a/src/stasis/bufferManager/concurrentBufferManager.c +++ b/src/stasis/bufferManager/concurrentBufferManager.c @@ -9,6 +9,7 @@ #include #include #include +#include #ifndef NO_CONCURRENT_LRU #ifndef CONCURRENT_LRU @@ -356,9 +357,9 @@ stasis_buffer_manager_t* stasis_buffer_manager_concurrent_hash_open(stasis_page_ #else ch->lru = replacementPolicyThreadsafeWrapperInit(lruFastInit(pageGetNode, pageSetNode, pagePinCountPtr, 0)); #endif - ch->ht = hashtable_init(MAX_BUFFER_SIZE * 4); + ch->ht = hashtable_init(stasis_buffer_manager_size * 4); - for(int i = 0; i < MAX_BUFFER_SIZE; i++) { + for(pageid_t i = 0; i < stasis_buffer_manager_size; i++) { Page *p = stasis_buffer_pool_malloc_page(ch->buffer_pool); stasis_buffer_pool_free_page(ch->buffer_pool, p,-1*i); pageSetNode(p,0,0); diff --git a/src/stasis/bufferManager/legacy/pageCache.c b/src/stasis/bufferManager/legacy/pageCache.c index ef2e528..3b3133d 100644 --- a/src/stasis/bufferManager/legacy/pageCache.c +++ b/src/stasis/bufferManager/legacy/pageCache.c @@ -6,6 +6,7 @@ writes, and locking. */ #include +#include #include #include @@ -14,7 +15,7 @@ #include #include -static unsigned int bufferSize; /* < MAX_BUFFER_SIZE */ +static pageid_t bufferSize; static Page *repHead, *repMiddle, *repTail; /* replacement policy */ int cache_state; @@ -106,8 +107,7 @@ void cacheInsertPage (Page * ret) { if(cache_state == FULL) { middleInsert(ret); } else { - if(bufferSize == MAX_BUFFER_SIZE/* - 1*/) { /* Set up page kick mechanism. */ - int i; + if(bufferSize == stasis_buffer_manager_size/* - 1*/) { /* Set up page kick mechanism. */ Page *iter; cache_state = FULL; @@ -120,9 +120,9 @@ void cacheInsertPage (Page * ret) { * resulted in the best performance" */ repMiddle = repHead; - for( i = 0; i < MAX_BUFFER_SIZE / 3; i++ ) { - repMiddle->queue = 1; - repMiddle = repMiddle->next; + for(pageid_t i = 0; i < stasis_buffer_manager_size / 3; i++ ) { + repMiddle->queue = 1; + repMiddle = repMiddle->next; } for( iter = repMiddle; iter; iter = iter->next ) { diff --git a/src/stasis/bufferPool.c b/src/stasis/bufferPool.c index 7676c34..fc8b326 100644 --- a/src/stasis/bufferPool.c +++ b/src/stasis/bufferPool.c @@ -49,6 +49,8 @@ terms specified in this license. * */ #include +#include + #include #include #include @@ -70,7 +72,7 @@ stasis_buffer_pool_t* stasis_buffer_pool_init() { #ifndef VALGRIND_MODE - byte * bufferSpace = calloc((MAX_BUFFER_SIZE + 2), PAGE_SIZE); + byte * bufferSpace = calloc((stasis_buffer_manager_size + 2), PAGE_SIZE); assert(bufferSpace); ret->addr_to_free = bufferSpace; @@ -83,9 +85,9 @@ stasis_buffer_pool_t* stasis_buffer_pool_init() { // We need one dummy page for locking purposes, // so this array has one extra page in it. - ret->pool = malloc(sizeof(ret->pool[0])*(MAX_BUFFER_SIZE+1)); + ret->pool = malloc(sizeof(ret->pool[0])*(stasis_buffer_manager_size+1)); - for(pageid_t i = 0; i < MAX_BUFFER_SIZE+1; i++) { + for(pageid_t i = 0; i < stasis_buffer_manager_size+1; i++) { ret->pool[i].rwlatch = initlock(); ret->pool[i].loadlatch = initlock(); #ifndef VALGRIND_MODE @@ -100,7 +102,7 @@ stasis_buffer_pool_t* stasis_buffer_pool_init() { } void stasis_buffer_pool_deinit(stasis_buffer_pool_t * ret) { - for(pageid_t i = 0; i < MAX_BUFFER_SIZE+1; i++) { + for(pageid_t i = 0; i < stasis_buffer_manager_size+1; i++) { deletelock(ret->pool[i].rwlatch); deletelock(ret->pool[i].loadlatch); #ifdef VALGRIND_MODE @@ -122,7 +124,7 @@ Page* stasis_buffer_pool_malloc_page(stasis_buffer_pool_t * ret) { assert(!page->dirty); (ret->nextPage)++; /* There's a dummy page that we need to keep around, thus the +1 */ - assert(ret->nextPage <= MAX_BUFFER_SIZE + 1); + assert(ret->nextPage <= stasis_buffer_manager_size + 1); pthread_mutex_unlock(&ret->mut); diff --git a/src/stasis/flags.c b/src/stasis/flags.c index 5b9da44..c2584ae 100644 --- a/src/stasis/flags.c +++ b/src/stasis/flags.c @@ -17,6 +17,17 @@ stasis_buffer_manager_t * (*stasis_buffer_manager_factory)(stasis_log_t*, stasis stasis_buffer_manager_t * (*stasis_buffer_manager_factory)(stasis_log_t*, stasis_dirty_page_table_t*) = stasis_buffer_manager_concurrent_hash_factory; #endif +#ifdef STASIS_BUFFER_MANAGER_SIZE +pageid_t stasis_buffer_manager_size = STASIS_BUFFER_MANAGER_SIZE; +#else // STASIS_BUFFER_MANAGER_SIZE +#ifdef MAX_BUFFER_SIZE +pageid_t stasis_buffer_manager_size = MAX_BUFFER_SIZE; +#else // MAX_BUFFER_SIZE +pageid_t stasis_buffer_manager_size = 20029; // ~ 82MB +#endif // MAX_BUFFER_SIZE +#endif // STASIS_BUFFER_MANAGER_SIZE + + #ifdef BUFFER_MANAGER_O_DIRECT int bufferManagerO_DIRECT = BUFFER_MANAGER_O_DIRECT; #else diff --git a/stasis/bufferManager/legacy/pageCache.h b/stasis/bufferManager/legacy/pageCache.h index 87927aa..bd12627 100644 --- a/stasis/bufferManager/legacy/pageCache.h +++ b/stasis/bufferManager/legacy/pageCache.h @@ -37,8 +37,6 @@ Page * cacheStalePage(); #define INITIAL 0 #define FULL 1 - - extern int cache_state; #endif diff --git a/stasis/constants.h b/stasis/constants.h index daf1ec0..939587b 100644 --- a/stasis/constants.h +++ b/stasis/constants.h @@ -80,17 +80,6 @@ terms specified in this license. #define PAGE_SIZE 4096 -#ifndef MAX_BUFFER_SIZE -//#define MAX_BUFFER_SIZE 100003 -#define MAX_BUFFER_SIZE 20029 -//#define MAX_BUFFER_SIZE 10007 -//#define MAX_BUFFER_SIZE 5003 -//#define MAX_BUFFER_SIZE 2003 -//#define MAX_BUFFER_SIZE 4006 -/* #define MAX_BUFFER_SIZE 71 */ -/*#define MAX_BUFFER_SIZE 7 */ -#endif - #define BUFFER_MANAGER_HASH 1 #define BUFFER_MANAGER_MEM_ARRAY 2 #define BUFFER_MANAGER_DEPRECATED_HASH 3 diff --git a/stasis/flags.h b/stasis/flags.h index 8e5cddd..0a654a7 100644 --- a/stasis/flags.h +++ b/stasis/flags.h @@ -17,6 +17,8 @@ */ extern stasis_buffer_manager_t* (*stasis_buffer_manager_factory)(stasis_log_t*, stasis_dirty_page_table_t*); + +extern pageid_t stasis_buffer_manager_size; /** This determines which type of file handle the buffer manager will use. @@ -115,7 +117,7 @@ extern lsn_t stasis_log_file_write_buffer_size; Set to 1 if segment based recovery is enabled. This disables some optimizations that assume all operations are page based. - @TODO Stasis' segment implementation is a work in progress; therefore this is set to zero by default. + @todo Stasis' segment implementation is a work in progress; therefore this is set to zero by default. */ extern int stasis_segments_enabled; #endif diff --git a/stasis/transactional.h b/stasis/transactional.h index ebda1f8..46c8e93 100644 --- a/stasis/transactional.h +++ b/stasis/transactional.h @@ -763,8 +763,10 @@ int TgetTransactionFingerprint(int xid, stasis_transaction_fingerprint_t * fp); /** * Checks to see if a transaction is still active. * - * @param xid The transaction id to be tested. + * @param fp The finger print of the transaction to be tested. * @return true if the transaction is still running, false otherwise. + * + * @see TgetTransactionFingerprint() */ int TisActiveTransaction(stasis_transaction_fingerprint_t* fp); /* diff --git a/test/stasis/check_bufferManager.c b/test/stasis/check_bufferManager.c index 71b1198..3d209cf 100644 --- a/test/stasis/check_bufferManager.c +++ b/test/stasis/check_bufferManager.c @@ -14,7 +14,7 @@ #ifdef LONG_TEST #define THREAD_COUNT 100 -#define NUM_PAGES ((MAX_BUFFER_SIZE * 3)/2) // Otherwise, we run out of disk cache, and it takes forever to complete... +#define NUM_PAGES ((stasis_buffer_manager_size * 3)/2) // Otherwise, we run out of disk cache, and it takes forever to complete... #define PAGE_MULT 10 // This tells the system to only use every 10'th page, allowing us to quickly check >2 GB, >4 GB safeness. #define READS_PER_THREAD (NUM_PAGES * 5) @@ -23,7 +23,7 @@ #else #define THREAD_COUNT 25 -#define NUM_PAGES ((MAX_BUFFER_SIZE * 3)/2) +#define NUM_PAGES ((stasis_buffer_manager_size * 3)/2) #define PAGE_MULT 1000 #define READS_PER_THREAD (NUM_PAGES * 2) @@ -73,7 +73,7 @@ void * workerThread(void * p) { int k = (int) (((double)NUM_PAGES)*rand()/(RAND_MAX+1.0)); Page * p; if(! (i % (READS_PER_THREAD / 10)) ) { - printf("%d", i / (READS_PER_THREAD / 10)); fflush(NULL); + printf("%lld", i / ((unsigned long long)READS_PER_THREAD / 10)); fflush(NULL); } rid.page = PAGE_MULT * (k+1); @@ -109,7 +109,7 @@ void * workerThreadWriting(void * q) { /* fflush(NULL); */ if(! (i % (RECORDS_PER_THREAD/10)) ) { - printf("A%d", i / (RECORDS_PER_THREAD/10)); fflush(NULL); + printf("A%lld", i / ((unsigned long long)RECORDS_PER_THREAD/10)); fflush(NULL); } @@ -146,7 +146,7 @@ void * workerThreadWriting(void * q) { releasePage(p); if(! (i % (RECORDS_PER_THREAD/10)) ) { - printf("W%d", i / (RECORDS_PER_THREAD/10)); fflush(NULL); + printf("W%lld", i / ((unsigned long long)RECORDS_PER_THREAD/10)); fflush(NULL); } /* sched_yield(); */ @@ -166,7 +166,7 @@ void * workerThreadWriting(void * q) { releasePage(p); if(! (i % (RECORDS_PER_THREAD/10))) { - printf("R%d", i / (RECORDS_PER_THREAD/10)); fflush(NULL); + printf("R%lld", i / ((unsigned long long)RECORDS_PER_THREAD/10)); fflush(NULL); } @@ -256,9 +256,9 @@ START_TEST(pageThreadedWritersTest) { Tdeinit(); }END_TEST - //#define PINNED_PAGE_COUNT (MAX_BUFFER_SIZE - 1) -#define PINNED_PAGE_COUNT ((MAX_BUFFER_SIZE - 1) / THREAD_COUNT) -#define MAX_PAGE_ID (MAX_BUFFER_SIZE * 2) + //#define PINNED_PAGE_COUNT (stasis_buffer_manager_size - 1) +#define PINNED_PAGE_COUNT ((stasis_buffer_manager_size - 1) / THREAD_COUNT) +#define MAX_PAGE_ID (stasis_buffer_manager_size * 2) #ifdef LONG_TEST #define BLIND_ITERS 100000 #else @@ -312,7 +312,7 @@ START_TEST(pageBlindThreadTest) { printf("Spawning threads now.\n"); fflush(stdout); - printf("each thread pins %d pages (total: %d)\n", PINNED_PAGE_COUNT, PINNED_PAGE_COUNT*THREAD_COUNT); + printf("each thread pins %lld pages (total: %lld)\n", (unsigned long long)PINNED_PAGE_COUNT, (unsigned long long)PINNED_PAGE_COUNT*THREAD_COUNT); pthread_t workers[THREAD_COUNT]; @@ -332,15 +332,15 @@ static void stalePinTestImpl(stasis_buffer_manager_t * (*fact)(stasis_log_t*, st Tinit(); - Page * p[MAX_BUFFER_SIZE-1]; - for(int i = 0; i < MAX_BUFFER_SIZE-2; i++) { + Page * p[stasis_buffer_manager_size-1]; + for(int i = 0; i < stasis_buffer_manager_size-2; i++) { p[i] = loadUninitializedPage(-1, i); } - for(int i = 0; i < MAX_BUFFER_SIZE; i++) { - Page * foo = loadUninitializedPage(-1, i+MAX_BUFFER_SIZE); + for(int i = 0; i < stasis_buffer_manager_size; i++) { + Page * foo = loadUninitializedPage(-1, i+stasis_buffer_manager_size); releasePage(foo); } - for(int i = 0; i < MAX_BUFFER_SIZE-2; i++) { + for(int i = 0; i < stasis_buffer_manager_size-2; i++) { releasePage(p[i]); } Tdeinit();