pgstat: Create memory contexts below TopMemoryContext
authorAndres Freund <andres@anarazel.de>
Fri, 16 Sep 2022 21:08:40 +0000 (14:08 -0700)
committerAndres Freund <andres@anarazel.de>
Sat, 17 Sep 2022 16:04:23 +0000 (09:04 -0700)
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 <reid.thompson@crunchydata.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Author: "Drouvot, Bertrand" <bdrouvot@amazon.com>
Discussion: https://postgr.es/m/b948b729-42fe-f88c-2f4a-0e65d84c049b@amazon.com
Backpatch: 15-

src/backend/utils/activity/pgstat.c
src/backend/utils/activity/pgstat_shmem.c

index 6224c498c21d0ee129907c7f730270e99e4a6fcd..b0ff21b6908a27c01974e4b8eb28007974e907c2 100644 (file)
@@ -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);
    }
index ac9891868847f29508178bf026ad03ac4183c2c5..9a4f037959edf01f4d7375c4c382b5b117dc2c38 100644 (file)
@@ -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);
 }