Changeset: ceecf07b2496 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ceecf07b2496 Modified Files: gdk/gdk_align.c gdk/gdk_bat.c gdk/gdk_bbp.mx gdk/gdk_private.h gdk/gdk_relop.mx Branch: default Log Message:
BBPcache code dropped The performance gains of this caching structure are too minimal. Removing the code to reduce complexity and maintenance. diffs (truncated from 774 to 300 lines): diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c --- a/gdk/gdk_align.c +++ b/gdk/gdk_align.c @@ -201,14 +201,12 @@ ALIGNsynced(BAT *b1, BAT *b2) static BAT * VIEWhcreate(BAT *h) { - BATstore *bs, *recycled = NULL; + BATstore *bs; BAT *bn; bat hp; BATcheck(h, "VIEWhcreate"); - recycled = bs = BBPrecycle(TYPE_void, TYPE_void, 1); - if (bs == NULL) - bs = BATcreatedesc(h->htype, TYPE_void, FALSE); + bs = BATcreatedesc(h->htype, TYPE_void, FALSE); if (bs == NULL) return NULL; bn = &bs->B; @@ -245,8 +243,7 @@ VIEWhcreate(BAT *h) bn->batDirty = BATdirty(h); bn->batRestricted = BAT_READ; - if (recycled == NULL) - BBPcacheit(bs, 1); /* enter in BBP */ + BBPcacheit(bs, 1); /* enter in BBP */ return bn; } @@ -254,15 +251,14 @@ VIEWhcreate(BAT *h) BAT * VIEWcreate_(BAT *h, BAT *t, int slice_view) { - BATstore *bs, *recycled = NULL; + BATstore *bs; BAT *bn; bat hp = 0, tp = 0, vc = 0; BATcheck(h, "VIEWcreate_"); BATcheck(t, "VIEWcreate_"); - recycled = bs = BBPrecycle(TYPE_void, TYPE_void, 1); - if (bs == NULL) - bs = BATcreatedesc(h->htype, t->ttype, FALSE); + + bs = BATcreatedesc(h->htype, t->ttype, FALSE); if (bs == NULL) return NULL; bn = &bs->B; @@ -346,8 +342,7 @@ VIEWcreate_(BAT *h, BAT *t, int slice_vi bn->T->hash = NULL; else bn->T->hash = t->T->hash; - if (recycled == NULL) - BBPcacheit(bs, 1); /* enter in BBP */ + BBPcacheit(bs, 1); /* enter in BBP */ /* View of VIEW combine, ie we need to fix the head of the mirror */ if (vc) { BAT *bm = BATmirror(bn); diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -236,59 +236,55 @@ BATsetdims(BAT *b) static BATstore * BATnewstorage(int ht, int tt, BUN cap) { - BATstore *bs, *recycled; + BATstore *bs; BAT *bn; assert(cap <= BUN_MAX); /* and in case we don't have assertions enabled: limit the size */ if (cap > BUN_MAX) cap = BUN_MAX; - bs = recycled = BBPrecycle(ht, tt, cap); - if (!bs) - bs = BATcreatedesc(ht, tt, (ht || tt)); + bs = BATcreatedesc(ht, tt, (ht || tt)); if (bs == NULL) return NULL; bn = &bs->B; - if (!recycled) { - BATsetdims(bn); - bn->U->capacity = cap; + BATsetdims(bn); + bn->U->capacity = cap; - /* alloc the main heaps */ - if (ht && HEAPalloc(&bn->H->heap, cap, bn->H->width) < 0) { - return NULL; + /* alloc the main heaps */ + if (ht && HEAPalloc(&bn->H->heap, cap, bn->H->width) < 0) { + return NULL; + } + if (tt && HEAPalloc(&bn->T->heap, cap, bn->T->width) < 0) { + if (ht) + HEAPfree(&bn->H->heap); + return NULL; + } + + if (ATOMheap(ht, bn->H->vheap, cap) < 0) { + if (ht) + HEAPfree(&bn->H->heap); + if (tt) + HEAPfree(&bn->T->heap); + GDKfree(bn->H->vheap); + if (bn->T->vheap) + GDKfree(bn->T->vheap); + return NULL; + } + if (ATOMheap(tt, bn->T->vheap, cap) < 0) { + if (ht) + HEAPfree(&bn->H->heap); + if (tt) + HEAPfree(&bn->T->heap); + if (bn->H->vheap) { + HEAPfree(bn->H->vheap); + GDKfree(bn->H->vheap); } - if (tt && HEAPalloc(&bn->T->heap, cap, bn->T->width) < 0) { - if (ht) - HEAPfree(&bn->H->heap); - return NULL; - } - - if (ATOMheap(ht, bn->H->vheap, cap) < 0) { - if (ht) - HEAPfree(&bn->H->heap); - if (tt) - HEAPfree(&bn->T->heap); - GDKfree(bn->H->vheap); - if (bn->T->vheap) - GDKfree(bn->T->vheap); - return NULL; - } - if (ATOMheap(tt, bn->T->vheap, cap) < 0) { - if (ht) - HEAPfree(&bn->H->heap); - if (tt) - HEAPfree(&bn->T->heap); - if (bn->H->vheap) { - HEAPfree(bn->H->vheap); - GDKfree(bn->H->vheap); - } - GDKfree(bn->T->vheap); - return NULL; - } - DELTAinit(bn); - BBPcacheit(bs, 1); + GDKfree(bn->T->vheap); + return NULL; } + DELTAinit(bn); + BBPcacheit(bs, 1); return bs; } diff --git a/gdk/gdk_bbp.mx b/gdk/gdk_bbp.mx --- a/gdk/gdk_bbp.mx +++ b/gdk/gdk_bbp.mx @@ -177,7 +177,6 @@ static void BBPspin(bat bid, str debug, static int BBPfree(BAT *b, str calledFrom); static int BBPdestroy(BAT *b); static void BBPuncacheit(bat bid, int unloaddesc); -static void BBPinitcache(void); static int BBPprepare(bit subcommit); static BAT *getBBPdescriptor(bat i, int lock); static int BBPbackup(BAT *b, bit subcommit); @@ -1308,7 +1307,6 @@ BBPinit(void) BBPsetstamp(max_stamp - min_stamp); } - BBPinitcache(); BBPinithash(); BBP_notrim = 0; @@ -1345,15 +1343,12 @@ BBPinit(void) * interference in a parallel session. */ -static wrd BBPrecycle_minsize(wrd val); - void BBPexit(void) { bat i; int skipped; - BBPrecycle_minsize(0); /* clear the bat cache */ BBPlock("BBPexit"); /* stop all threads ever touching more descriptors */ /* free all memory (just for leak-checking in Purify) */ @@ -2698,11 +2693,9 @@ BBPsave(BAT *b) * for being unloaded (or even destroyed, if the BAT is not * persistent). */ -static int BBPaddtobin(BAT *b); static int BBPdestroy(BAT *b) { - int clear = 1; bat hp = b->H->heap.parentid, tp = b->T->heap.parentid; bat vhp = VIEWvhparent(b), vtp = VIEWvtparent(b); @@ -2732,10 +2725,9 @@ BBPdestroy(BAT *b) (*tunfix) (BUNtail(bi, p)); } } - clear = BBPaddtobin(b); /* plan for re-use */ + BATdelete(b); /* handles persistent case also (file deletes) */ } - if (clear) - BBPclear(b->batCacheid); /* if destroyed; de-register from BBP */ + BBPclear(b->batCacheid); /* if destroyed; de-register from BBP */ /* parent released when completely done with child */ if (hp) @@ -3278,524 +3270,6 @@ BBPquickdesc(bat bid, int delaccess) } /* - - * @+ Small BAT Cache - - * PETER: rewrote the batcache to make it stable with views and - * actually faster than allocating new bats (I guess that was - * the purpose of it) - * - * this is tuned to minimizing the needed actions to get a BAT, in - * particular we will do no BBPinsert, BUN dimension modifications, - * BATextends(). - * - * it also covers more cases, such as views and TYPE_str - * - * main ideas: - * - have [htpe,ttpe] specific lists to O(1) get a BAT from the - * desired type (bin-lists) - * - implement LRU when the cache is full, with O(1) delete cost by - * using a fifo list - * - keep bats in the BBP, as zombies (by invalidating their name) - * - support views as void,void bats (they have in common that they - * lack heaps) - * - support TYPE_str as well, zapping their built-in string hash - * table - * - only recycle BATTINY bats. Increase BATTINY to make more BATnews - * use the cache. BATTINY=256 leading to bunheaps ~1K-2K (in - * balance with ~500byte BAT record) - * - * and then benchmark it (missing in the previous exercise) : - * - * module(alarm); - * bbp_batcache_minsize(wrd(256)); - * @{ var t := time(), i := 0; while((i :+= 1) < 100000) bat(int,int); print(time() - t); @} - * [ 490 ] - * bbp_batcache_minsize(wrd(0)); - * @{ var t := time(), i := 0; while((i :+= 1) < 100000) bat(int,int); print(time() - t); @} - * [ 847 ] - * - * so with caching *some* programs can be nearly twice as fast - * (optimized compile), though I expect the gains to be smaller in - * general. - - * June 2012 - * Using the cache makes a difference between [ 823085 ] and [ 3076993 ] usec - * when you create 1M bats. The loop itself was [ 62576 ] usec (performanceTests/tst400h.mal) - * Indeed, this code is a candidate for removal to gain simplicity. - */ -#define BATCACHE_NOTYPE(t) (ATOMstorage(t) > TYPE_str || BATatoms[t].atomFix != NULL) -#define BATCACHE_SIZE 1023 /* max size: 32767 */ -#define BATCACHE_DIMS 6 /* 0,1,2,4,8 byte types + str */ -#define BATCACHE_BIN(h,t) (batcache_headbin[ATOMstorage(h)]+batcache_tailbin[ATOMstorage(t)]) -#define BATCACHE_BUCKETS 2 /* initial value */ -#define BATCACHE_MAXBUCKETS 4 /* how big this can ever be */ - -int batcache_headbin[TYPE_str + 1], batcache_tailbin[TYPE_str + 1]; /* fast bin computation */ - -typedef signed short batcache_int; /* make compact, whole structure is < 500 bytes: CPU cache resident */ - -int batcache_maxbuckets = BATCACHE_BUCKETS; -@h -extern int batcache_maxbuckets; /* used in gdk_relop.mx */ -@c - -/* the list elements, use int as element pointer type (<0 means: no - * such element) */ -typedef struct { - bat bid; - batcache_int bin_next, bin_prev; /* doubly linked list that connects all BATs for a bin */ - batcache_int fifo_next, fifo_prev; /* doubly linked list for getting the LRU BAT O(1) */ -} batcache_elt_t; - -typedef struct { - MT_Lock lock; - - /* each bin starts a bin_next/prev list */ - batcache_int batbin[BATCACHE_DIMS * BATCACHE_DIMS]; - batcache_elt_t elt[BATCACHE_SIZE]; /* main storage */ - - /* fifo queue */ _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list