From b1c2f6235b3d7babfa46849a36b9a370a907b640 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Jan 2014 08:51:34 -0800 Subject: [PATCH] add audit function to run on an idle btree --- threads2h.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++---- threads2i.c | 29 ++++++++------------------ threads2j.c | 29 ++++++++------------------ 3 files changed, 74 insertions(+), 44 deletions(-) diff --git a/threads2h.c b/threads2h.c index db5c991..f1f774d 100644 --- a/threads2h.c +++ b/threads2h.c @@ -1,5 +1,5 @@ // btree version threads2h pthread rw lock version -// 29 JAN 2014 +// 30 JAN 2014 // author: karl malbrain, malbrain@cal.berkeley.edu @@ -1479,15 +1479,20 @@ int bt_findslot (BtDb *bt, unsigned char *key, uint len) uint diff, higher = bt->page->cnt, low = 1, slot; uint good = 0; - // make stopper key an infinite fence value + // if no right link + // make stopper key an infinite fence value + // by setting the good flag if( bt_getid (bt->page->right) ) higher++; else good++; - // low is the next candidate, higher is already - // tested as .ge. the given key, loop ends when they meet + // low is the next candidate. + // loop ends when they meet + + // if good, higher is already + // tested as .ge. the given key. while( diff = higher - low ) { slot = low + ( diff >> 1 ); @@ -1605,6 +1610,7 @@ slideright: prevpool = bt->pool; prevset = bt->set; prevmode = mode; + } while( page_no ); // return error on end of right chain @@ -2414,6 +2420,46 @@ uint bt_tod(BtDb *bt, uint slot) #ifdef STANDALONE +void bt_latchaudit (BtDb *bt) +{ +ushort idx, hashidx; +BtLatchSet *set; +BtPool *pool; +BtPage page; +uid page_no; + +#ifdef unix + for( idx = 1; idx < bt->mgr->latchmgr->latchdeployed; idx++ ) { + set = bt->mgr->latchsets + idx; + if( set->pin ) { + fprintf(stderr, "latchset %d pinned\n", idx); + set->pin = 0; + } + } + + for( hashidx = 0; hashidx < bt->mgr->latchmgr->latchhash; hashidx++ ) { + if( *(uint *)bt->mgr->latchmgr->table[hashidx].latch ) + fprintf(stderr, "latchmgr locked\n"); + if( idx = bt->mgr->latchmgr->table[hashidx].slot ) do { + set = bt->mgr->latchsets + idx; + if( set->hash != hashidx ) + fprintf(stderr, "latchset %d wrong hashidx\n", idx); + if( set->pin ) + fprintf(stderr, "latchset %d pinned\n", idx); + } while( idx = set->next ); + } + page_no = bt_getid(bt->mgr->latchmgr->alloc[1].right); + + while( page_no ) { + fprintf(stderr, "free: %.6x\n", (uint)page_no); + pool = bt_pinpool (bt, page_no); + page = bt_page (bt, pool, page_no); + page_no = bt_getid(page->right); + bt_unpinpool (pool); + } +#endif +} + typedef struct { char type, idx; char *infile; @@ -2448,6 +2494,12 @@ FILE *in; switch(args->type | 0x20) { + case 'a': + fprintf(stderr, "started latch mgr audit\n"); + bt_latchaudit (bt); + fprintf(stderr, "finished latch mgr audit\n"); + break; + case 'w': fprintf(stderr, "started indexing for %s\n", args->infile); if( in = fopen (args->infile, "rb") ) diff --git a/threads2i.c b/threads2i.c index e53e31d..73d7541 100644 --- a/threads2i.c +++ b/threads2i.c @@ -1,5 +1,5 @@ // btree version threads2i sched_yield version -// 29 JAN 2014 +// 30 JAN 2014 // author: karl malbrain, malbrain@cal.berkeley.edu @@ -207,7 +207,6 @@ typedef struct { uint seg_bits; // seg size in pages in bits uint mode; // read-write mode #ifdef unix - char *pooladvise; // bit maps for pool page advisements int idx; #else HANDLE idx; @@ -695,7 +694,6 @@ uint slot; free (mgr->pool); free (mgr->hash); free (mgr->latch); - free (mgr->pooladvise); free (mgr); #else FlushFileBuffers(mgr->idx); @@ -828,7 +826,6 @@ SYSTEM_INFO sysinfo[1]; mgr->pool = calloc (poolmax, sizeof(BtPool)); mgr->hash = calloc (hashsize, sizeof(ushort)); mgr->latch = calloc (hashsize, sizeof(BtSpinLatch)); - mgr->pooladvise = calloc (poolmax, (mgr->poolmask + 8) / 8); #else mgr->pool = GlobalAlloc (GMEM_FIXED|GMEM_ZEROINIT, poolmax * sizeof(BtPool)); mgr->hash = GlobalAlloc (GMEM_FIXED|GMEM_ZEROINIT, hashsize * sizeof(ushort)); @@ -1078,8 +1075,6 @@ int flag; if( pool->map == MAP_FAILED ) return bt->err = BTERR_map; - // clear out madvise issued bits - memset (bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8) / 8), 0, (bt->mgr->poolmask + 8)/8); #else flag = ( bt->mgr->mode == BT_ro ? PAGE_READONLY : PAGE_READWRITE ); pool->hmap = CreateFileMapping(bt->mgr->idx, NULL, flag, (DWORD)(limit >> 32), (DWORD)limit, NULL); @@ -1102,17 +1097,6 @@ uint subpage = (uint)(page_no & bt->mgr->poolmask); // page within mapping BtPage page; page = (BtPage)(pool->map + (subpage << bt->mgr->page_bits)); -#ifdef unix - { - uint idx = subpage / 8; - uint bit = subpage % 8; - - if( ~((bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8)/8))[idx] >> bit) & 1 ) { - madvise (page, bt->mgr->page_size, MADV_WILLNEED); - (bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8)/8))[idx] |= 1 << bit; - } - } -#endif return page; } @@ -1384,15 +1368,20 @@ int bt_findslot (BtDb *bt, unsigned char *key, uint len) uint diff, higher = bt->page->cnt, low = 1, slot; uint good = 0; - // make stopper key an infinite fence value + // if no right link + // make stopper key an infinite fence value + // by setting the good flag if( bt_getid (bt->page->right) ) higher++; else good++; - // low is the next candidate, higher is already - // tested as .ge. the given key, loop ends when they meet + // low is the next candidate. + // loop ends when they meet + + // if good, higher is already + // tested as .ge. the given key. while( diff = higher - low ) { slot = low + ( diff >> 1 ); diff --git a/threads2j.c b/threads2j.c index 54e14bc..e9aa1e7 100644 --- a/threads2j.c +++ b/threads2j.c @@ -1,5 +1,5 @@ // btree version threads2j linux futex concurrency version -// 29 JAN 2014 +// 30 JAN 2014 // author: karl malbrain, malbrain@cal.berkeley.edu @@ -216,7 +216,6 @@ typedef struct { uint seg_bits; // seg size in pages in bits uint mode; // read-write mode #ifdef unix - char *pooladvise; // bit maps for pool page advisements int idx; #else HANDLE idx; @@ -732,7 +731,6 @@ uint slot; free (mgr->pool); free (mgr->hash); free (mgr->latch); - free (mgr->pooladvise); free (mgr); #else FlushFileBuffers(mgr->idx); @@ -863,7 +861,6 @@ SYSTEM_INFO sysinfo[1]; mgr->pool = calloc (poolmax, sizeof(BtPool)); mgr->hash = calloc (hashsize, sizeof(ushort)); mgr->latch = calloc (hashsize, sizeof(BtLatch)); - mgr->pooladvise = calloc (poolmax, (mgr->poolmask + 8) / 8); #else mgr->pool = GlobalAlloc (GMEM_FIXED|GMEM_ZEROINIT, poolmax * sizeof(BtPool)); mgr->hash = GlobalAlloc (GMEM_FIXED|GMEM_ZEROINIT, hashsize * sizeof(ushort)); @@ -1113,8 +1110,6 @@ int flag; if( pool->map == MAP_FAILED ) return bt->err = BTERR_map; - // clear out madvise issued bits - memset (bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8) / 8), 0, (bt->mgr->poolmask + 8)/8); #else flag = ( bt->mgr->mode == BT_ro ? PAGE_READONLY : PAGE_READWRITE ); pool->hmap = CreateFileMapping(bt->mgr->idx, NULL, flag, (DWORD)(limit >> 32), (DWORD)limit, NULL); @@ -1137,17 +1132,6 @@ uint subpage = (uint)(page_no & bt->mgr->poolmask); // page within mapping BtPage page; page = (BtPage)(pool->map + (subpage << bt->mgr->page_bits)); -#ifdef unix - { - uint idx = subpage / 8; - uint bit = subpage % 8; - - if( ~((bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8)/8))[idx] >> bit) & 1 ) { - madvise (page, bt->mgr->page_size, MADV_WILLNEED); - (bt->mgr->pooladvise + pool->slot * ((bt->mgr->poolmask + 8)/8))[idx] |= 1 << bit; - } - } -#endif return page; } @@ -1419,15 +1403,20 @@ int bt_findslot (BtDb *bt, unsigned char *key, uint len) uint diff, higher = bt->page->cnt, low = 1, slot; uint good = 0; - // make stopper key an infinite fence value + // if no right link + // make stopper key an infinite fence value + // by setting the good flag if( bt_getid (bt->page->right) ) higher++; else good++; - // low is the next candidate, higher is already - // tested as .ge. the given key, loop ends when they meet + // low is the next candidate. + // loop ends when they meet + + // if good, higher is already + // tested as .ge. the given key. while( diff = higher - low ) { slot = low + ( diff >> 1 ); -- 2.40.0