From ad12cdbacda325b898b72313eaa08c2924d20e75 Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Sat, 10 May 2025 12:53:50 +0200
Subject: [PATCH v1 2/2] Use Generation contexts for rd_indexcxt

This removes completely the additional overhead caused by bucket sizing,
presumably making the system fast again.

On my local system, the memory usage is reduced by a further 52 kB
---
 src/backend/utils/cache/relcache.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index efeb65115ed..6ef857646d2 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1483,9 +1483,9 @@ RelationInitIndexAccessInfo(Relation relation)
 	 * a context, and not just a couple of pallocs, is so that we won't leak
 	 * any subsidiary info attached to fmgr lookup records.
 	 */
-	indexcxt = AllocSetContextCreate(CacheMemoryContext,
-									 "index info",
-									 ALLOCSET_SMALL_SIZES);
+	indexcxt = GenerationContextCreate(CacheMemoryContext,
+									   "index info",
+									   ALLOCSET_SMALL_SIZES);
 	relation->rd_indexcxt = indexcxt;
 	MemoryContextCopyAndSetIdentifier(indexcxt,
 									  RelationGetRelationName(relation));
@@ -6314,9 +6314,9 @@ load_relcache_init_file(bool shared)
 			 * prepare index info context --- parameters should match
 			 * RelationInitIndexAccessInfo
 			 */
-			indexcxt = AllocSetContextCreate(CacheMemoryContext,
-											 "index info",
-											 ALLOCSET_SMALL_SIZES);
+			indexcxt = GenerationContextCreate(CacheMemoryContext,
+											   "index info",
+											   ALLOCSET_SMALL_SIZES);
 			rel->rd_indexcxt = indexcxt;
 			MemoryContextCopyAndSetIdentifier(indexcxt,
 											  RelationGetRelationName(rel));
-- 
2.48.1

