From: Andres Freund Date: Fri, 16 Sep 2022 21:08:40 +0000 (-0700) Subject: pgstat: Create memory contexts below TopMemoryContext X-Git-Tag: REL_15_RC1~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb503793ef50eb16eb1924251d2ed58e1621eeb3;p=thirdparty%2Fpostgresql.git pgstat: Create memory contexts below TopMemoryContext So far they were created below CacheMemoryContext. However, that's not guaranteed to exist in all situations, leading to memory contexts created as top-level contexts. There isn't actually a good reason anymore to create them below CacheMemoryContext, so just creating them below TopMemoryContext seems the best approach. Reported-by: Reid Thompson Reviewed-by: Kyotaro Horiguchi Reviewed-by: Andres Freund Author: "Drouvot, Bertrand" Discussion: https://postgr.es/m/b948b729-42fe-f88c-2f4a-0e65d84c049b@amazon.com Backpatch: 15- --- diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index 6224c498c21..b0ff21b6908 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -1069,7 +1069,7 @@ pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created if (unlikely(!pgStatPendingContext)) { pgStatPendingContext = - AllocSetContextCreate(CacheMemoryContext, + AllocSetContextCreate(TopMemoryContext, "PgStat Pending", ALLOCSET_SMALL_SIZES); } diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index ac989186884..9a4f037959e 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -992,12 +992,12 @@ pgstat_setup_memcxt(void) { if (unlikely(!pgStatSharedRefContext)) pgStatSharedRefContext = - AllocSetContextCreate(CacheMemoryContext, + AllocSetContextCreate(TopMemoryContext, "PgStat Shared Ref", ALLOCSET_SMALL_SIZES); if (unlikely(!pgStatEntryRefHashContext)) pgStatEntryRefHashContext = - AllocSetContextCreate(CacheMemoryContext, + AllocSetContextCreate(TopMemoryContext, "PgStat Shared Ref Hash", ALLOCSET_SMALL_SIZES); }