From d916e783476d704e59a50d764fea1ccb8dba2aad Mon Sep 17 00:00:00 2001 From: John Naylor Date: Wed, 18 Aug 2021 14:03:57 -0400 Subject: [PATCH v1 6/6] Some adjustments to catcachebench and catcache.c so it will run --- contrib/catcachebench/catcachebench.c | 57 --------------------------- src/backend/utils/cache/catcache.c | 41 +++---------------- 2 files changed, 6 insertions(+), 92 deletions(-) diff --git a/contrib/catcachebench/catcachebench.c b/contrib/catcachebench/catcachebench.c index b5a4d794ed..f688196baa 100644 --- a/contrib/catcachebench/catcachebench.c +++ b/contrib/catcachebench/catcachebench.c @@ -21,7 +21,6 @@ PG_MODULE_MAGIC; double catcachebench1(void); double catcachebench2(void); -double catcachebench3(void); void collectinfo(void); void catcachewarmup(void); @@ -103,9 +102,6 @@ catcachebench(PG_FUNCTION_ARGS) collectinfo(); - /* flush the catalog -- safe? don't mind. */ - CatalogCacheFlushCatalog2(StatisticRelationId); - switch (testtype) { case 0: @@ -115,8 +111,6 @@ catcachebench(PG_FUNCTION_ARGS) ms = catcachebench1(); break; case 2: ms = catcachebench2(); break; - case 3: - ms = catcachebench3(); break; default: elog(ERROR, "Invalid test type: %d", testtype); } @@ -192,57 +186,6 @@ catcachebench2(void) return INSTR_TIME_GET_MILLISEC(duration); }; -/* - * fetch all attribute entires of all tables twice with having expiration - * happen. - */ -double -catcachebench3(void) -{ - const int clock_step = 1000; - int i, t, a; - instr_time start, - duration; - - PG_SETMASK(&BlockSig); - INSTR_TIME_SET_CURRENT(start); - for (i = 0 ; i < 4 ; i++) - { - int ct = clock_step; - - for (t = 0 ; t < ntables ; t++) - { - /* - * catcacheclock is updated by transaction timestamp, so needs to - * be updated by other means for this test to work. Here I choosed - * to update the clock every 1000 tables scan. - */ - if (--ct < 0) - { - SetCatCacheClock(GetCurrentTimestamp()); - ct = clock_step; - } - for (a = 0 ; a < natts ; a++) - { - HeapTuple tup; - - tup = SearchSysCache3(STATRELATTINH, - ObjectIdGetDatum(tableoids[t]), - Int16GetDatum(attnums[a]), - BoolGetDatum(false)); - /* should be null, but.. */ - if (HeapTupleIsValid(tup)) - ReleaseSysCache(tup); - } - } - } - INSTR_TIME_SET_CURRENT(duration); - INSTR_TIME_SUBTRACT(duration, start); - PG_SETMASK(&UnBlockSig); - - return INSTR_TIME_GET_MILLISEC(duration); -}; - void catcachewarmup(void) { diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index db64b19975..8d09576dda 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -760,40 +760,6 @@ CatalogCacheFlushCatalog(Oid catId) } -/* FUNCTION FOR BENCHMARKING */ -void -CatalogCacheFlushCatalog2(Oid catId) -{ - slist_iter iter; - - CACHE_elog(DEBUG2, "CatalogCacheFlushCatalog called for %u", catId); - - slist_foreach(iter, &CacheHdr->ch_caches) - { - CatCache *cache = slist_container(CatCache, cc_next, iter.cur); - - /* Does this cache store tuples of the target catalog? */ - if (cache->cc_reloid == catId) - { - /* Yes, so flush all its contents */ - ResetCatalogCache(cache); - - /* Tell inval.c to call syscache callbacks for this cache */ - CallSyscacheCallbacks(cache->id, 0); - - cache->cc_nbuckets = 128; - pfree(cache->cc_bucket); - cache->cc_bucket = - (dlist_head *) MemoryContextAllocZero(CacheMemoryContext, - cache->cc_nbuckets * sizeof(dlist_head)); - elog(LOG, "Catcache reset"); - } - } - - CACHE_elog(DEBUG2, "end of CatalogCacheFlushCatalog call"); -} -/* END: FUNCTION FOR BENCHMARKING */ - /* * InitCatCache * @@ -918,13 +884,18 @@ RehashCatCache(CatCache *cp) CCBucket *newbucket; int newnbuckets; int i; + size_t sz; elog(DEBUG1, "rehashing catalog cache id %d for %s; %d tups, %d buckets", cp->id, cp->cc_relname, cp->cc_ntup, cp->cc_nbuckets); /* Allocate a new, larger, hash table. */ newnbuckets = cp->cc_nbuckets * 2; - newbucket = (CCBucket *) MemoryContextAllocZero(CacheMemoryContext, newnbuckets * sizeof(CCBucket)); + sz = newnbuckets * sizeof(CCBucket); + if (sz > MaxAllocSize) + return; + + newbucket = (CCBucket *) MemoryContextAllocZero(CacheMemoryContext, sz); /* Move all entries from old hash table to new. */ for (i = 0; i < cp->cc_nbuckets; i++) -- 2.31.1