*** ./src/backend/utils/mmgr/aset.c.orig Mon May 9 17:55:36 2005 --- ./src/backend/utils/mmgr/aset.c Wed May 11 15:38:33 2005 *************** *** 123,128 **** --- 123,135 ---- /* * AllocSetContext is our standard implementation of MemoryContext. + * + * shouldReset shows whether AllocSetReset should work. This is + * used to reduce cycle of AllocSetReset. When new block is + * allocated or freed chunk is put on freelist, it will be set + * to true. If it is false, AllocSetReset have nothing to do. + * In this way, the context reset repeatedly after a small allocation + * such as per-tuple contexts can be reset fast. */ typedef struct AllocSetContext { *************** *** 135,140 **** --- 142,148 ---- Size maxBlockSize; /* maximum block size */ AllocBlock keeper; /* if not NULL, keep this block over * resets */ + bool shouldReset; /* should AllocSetReset work? */ } AllocSetContext; typedef AllocSetContext *AllocSet; *************** *** 395,400 **** --- 403,416 ---- AllocSetCheck(context); #endif + /* + * Shortcut. See comment at the definition of AllocSetContext. + */ + if(!set->shouldReset) + return; + + set->shouldReset = false; + /* Clear chunk freelists */ MemSet(set->freelist, 0, sizeof(set->freelist)); /* New blocks list is either empty or just the keeper block */ *************** *** 454,459 **** --- 470,476 ---- MemSet(set->freelist, 0, sizeof(set->freelist)); set->blocks = NULL; set->keeper = NULL; + set->shouldReset = false; while (block != NULL) { *************** *** 531,536 **** --- 548,554 ---- block->next = NULL; set->blocks = block; } + set->shouldReset = true; AllocAllocInfo(set, chunk); return AllocChunkGetPointer(chunk); *************** *** 723,728 **** --- 741,747 ---- block->next = set->blocks; set->blocks = block; + set->shouldReset = true; } /* *************** *** 816,821 **** --- 835,841 ---- chunk->requested_size = 0; #endif set->freelist[fidx] = chunk; + set->shouldReset = true; } }