=== Applying patches on top of PostgreSQL commit ID 9018c7d37bb464cd53567c0b553a6f49b50bec78 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Apr 19 14:47:25 UTC 2026 On branch cf/5938 nothing to commit, working tree clean === using 'git am' to apply patch ./v55-0001-Add-function-to-get-memory-context-stats-for-pro.patch === Applying: Add function to get memory context stats for processes Using index info to reconstruct a base tree... M doc/src/sgml/func/func-admin.sgml M src/backend/postmaster/autovacuum.c M src/backend/postmaster/checkpointer.c M src/backend/postmaster/pgarch.c M src/backend/postmaster/startup.c M src/backend/postmaster/walsummarizer.c M src/backend/storage/ipc/dsm_registry.c M src/backend/storage/ipc/ipci.c M src/backend/storage/ipc/procsignal.c M src/backend/tcop/postgres.c M src/backend/utils/activity/wait_event_names.txt M src/backend/utils/adt/mcxtfuncs.c M src/backend/utils/init/globals.c M src/backend/utils/init/postinit.c M src/include/catalog/pg_proc.dat M src/include/miscadmin.h M src/include/storage/lwlocklist.h M src/include/storage/procsignal.h M src/test/modules/Makefile M src/test/modules/meson.build M src/tools/pgindent/typedefs.list Falling back to patching base and 3-way merge... Auto-merging src/tools/pgindent/typedefs.list Auto-merging src/test/modules/meson.build Auto-merging src/test/modules/Makefile Auto-merging src/include/storage/procsignal.h Auto-merging src/include/storage/lwlocklist.h CONFLICT (content): Merge conflict in src/include/storage/lwlocklist.h Auto-merging src/include/miscadmin.h Auto-merging src/include/catalog/pg_proc.dat Auto-merging src/backend/utils/init/postinit.c Auto-merging src/backend/utils/init/globals.c Auto-merging src/backend/utils/adt/mcxtfuncs.c CONFLICT (content): Merge conflict in src/backend/utils/adt/mcxtfuncs.c Auto-merging src/backend/utils/activity/wait_event_names.txt CONFLICT (content): Merge conflict in src/backend/utils/activity/wait_event_names.txt Auto-merging src/backend/tcop/postgres.c Auto-merging src/backend/storage/ipc/procsignal.c Auto-merging src/backend/storage/ipc/ipci.c CONFLICT (content): Merge conflict in src/backend/storage/ipc/ipci.c Auto-merging src/backend/storage/ipc/dsm_registry.c Auto-merging src/backend/postmaster/walsummarizer.c Auto-merging src/backend/postmaster/startup.c Auto-merging src/backend/postmaster/pgarch.c Auto-merging src/backend/postmaster/checkpointer.c Auto-merging src/backend/postmaster/autovacuum.c Auto-merging doc/src/sgml/func/func-admin.sgml error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Add function to get memory context stats for processes When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". === using patch(1) to apply patch ./v55-0001-Add-function-to-get-memory-context-stats-for-pro.patch === patching file doc/src/sgml/func/func-admin.sgml patching file src/backend/postmaster/autovacuum.c Hunk #1 succeeded at 825 (offset 37 lines). patching file src/backend/postmaster/checkpointer.c Hunk #1 succeeded at 694 (offset 9 lines). patching file src/backend/postmaster/interrupt.c patching file src/backend/postmaster/pgarch.c Hunk #1 succeeded at 870 (offset -1 lines). patching file src/backend/postmaster/startup.c patching file src/backend/postmaster/walsummarizer.c patching file src/backend/storage/ipc/dsm_registry.c Hunk #1 succeeded at 273 (offset 3 lines). Hunk #2 succeeded at 356 (offset 3 lines). patching file src/backend/storage/ipc/ipci.c Hunk #1 FAILED at 52. Hunk #2 FAILED at 142. Hunk #3 FAILED at 329. 3 out of 3 hunks FAILED -- saving rejects to file src/backend/storage/ipc/ipci.c.rej patching file src/backend/storage/ipc/procsignal.c Hunk #1 succeeded at 705 (offset 8 lines). patching file src/backend/tcop/postgres.c Hunk #1 succeeded at 3608 with fuzz 1 (offset 35 lines). patching file src/backend/utils/activity/wait_event_names.txt Hunk #1 succeeded at 166 (offset 3 lines). Hunk #2 FAILED at 367. 1 out of 2 hunks FAILED -- saving rejects to file src/backend/utils/activity/wait_event_names.txt.rej patching file src/backend/utils/adt/mcxtfuncs.c Hunk #1 FAILED at 15. Hunk #2 succeeded at 65 (offset 2 lines). Hunk #3 succeeded at 207 (offset 2 lines). Hunk #4 succeeded at 352 (offset 2 lines). 1 out of 4 hunks FAILED -- saving rejects to file src/backend/utils/adt/mcxtfuncs.c.rej patching file src/backend/utils/init/globals.c patching file src/backend/utils/init/postinit.c Hunk #1 succeeded at 670 (offset 1 line). patching file src/backend/utils/mmgr/mcxt.c patching file src/include/catalog/pg_proc.dat Hunk #1 succeeded at 8755 (offset 63 lines). patching file src/include/miscadmin.h Hunk #1 succeeded at 98 (offset 2 lines). patching file src/include/storage/lwlocklist.h Hunk #1 FAILED at 87. 1 out of 1 hunk FAILED -- saving rejects to file src/include/storage/lwlocklist.h.rej patching file src/include/storage/procsignal.h Hunk #1 succeeded at 35 with fuzz 2. patching file src/include/utils/memutils.h patching file src/test/modules/Makefile Hunk #1 succeeded at 37 (offset 2 lines). patching file src/test/modules/meson.build Hunk #1 succeeded at 38 (offset 2 lines). patching file src/test/modules/test_memcontext_reporting/Makefile patching file src/test/modules/test_memcontext_reporting/meson.build patching file src/test/modules/test_memcontext_reporting/t/001_memcontext_inj.pl patching file src/test/modules/test_memcontext_reporting/test_memcontext_reporting.c patching file src/test/regress/expected/sysviews.out patching file src/test/regress/sql/sysviews.sql patching file src/tools/pgindent/typedefs.list Hunk #1 succeeded at 1754 (offset 44 lines). Unstaged changes after reset: M doc/src/sgml/func/func-admin.sgml M src/backend/postmaster/autovacuum.c M src/backend/postmaster/checkpointer.c M src/backend/postmaster/interrupt.c M src/backend/postmaster/pgarch.c M src/backend/postmaster/startup.c M src/backend/postmaster/walsummarizer.c M src/backend/storage/ipc/dsm_registry.c M src/backend/storage/ipc/procsignal.c M src/backend/tcop/postgres.c M src/backend/utils/activity/wait_event_names.txt M src/backend/utils/adt/mcxtfuncs.c M src/backend/utils/init/globals.c M src/backend/utils/init/postinit.c M src/backend/utils/mmgr/mcxt.c M src/include/catalog/pg_proc.dat M src/include/miscadmin.h M src/include/storage/procsignal.h M src/include/utils/memutils.h M src/test/modules/Makefile M src/test/modules/meson.build M src/test/regress/expected/sysviews.out M src/test/regress/sql/sysviews.sql M src/tools/pgindent/typedefs.list Removing src/backend/storage/ipc/ipci.c.rej Removing src/backend/utils/activity/wait_event_names.txt.rej Removing src/backend/utils/adt/mcxtfuncs.c.rej Removing src/include/storage/lwlocklist.h.rej Removing src/test/modules/test_memcontext_reporting/ === using 'git apply' to apply patch ./v55-0001-Add-function-to-get-memory-context-stats-for-pro.patch === Applied patch to 'doc/src/sgml/func/func-admin.sgml' cleanly. Applied patch to 'src/backend/postmaster/autovacuum.c' cleanly. Applied patch to 'src/backend/postmaster/checkpointer.c' cleanly. Applied patch to 'src/backend/postmaster/interrupt.c' cleanly. Applied patch to 'src/backend/postmaster/pgarch.c' cleanly. Applied patch to 'src/backend/postmaster/startup.c' cleanly. Applied patch to 'src/backend/postmaster/walsummarizer.c' cleanly. Applied patch to 'src/backend/storage/ipc/dsm_registry.c' cleanly. Applied patch to 'src/backend/storage/ipc/ipci.c' with conflicts. Applied patch to 'src/backend/storage/ipc/procsignal.c' cleanly. Applied patch to 'src/backend/tcop/postgres.c' cleanly. Applied patch to 'src/backend/utils/activity/wait_event_names.txt' with conflicts. Applied patch to 'src/backend/utils/adt/mcxtfuncs.c' with conflicts. Applied patch to 'src/backend/utils/init/globals.c' cleanly. Applied patch to 'src/backend/utils/init/postinit.c' cleanly. Applied patch to 'src/backend/utils/mmgr/mcxt.c' cleanly. Applied patch to 'src/include/catalog/pg_proc.dat' cleanly. Applied patch to 'src/include/miscadmin.h' cleanly. Applied patch to 'src/include/storage/lwlocklist.h' with conflicts. Applied patch to 'src/include/storage/procsignal.h' cleanly. Applied patch to 'src/include/utils/memutils.h' cleanly. Applied patch to 'src/test/modules/Makefile' cleanly. Applied patch to 'src/test/modules/meson.build' cleanly. Falling back to direct application... Falling back to direct application... Falling back to direct application... Falling back to direct application... Applied patch to 'src/test/regress/expected/sysviews.out' cleanly. Applied patch to 'src/test/regress/sql/sysviews.sql' cleanly. Applied patch to 'src/tools/pgindent/typedefs.list' cleanly. U src/backend/storage/ipc/ipci.c U src/backend/utils/activity/wait_event_names.txt U src/backend/utils/adt/mcxtfuncs.c U src/include/storage/lwlocklist.h diff --cc src/backend/storage/ipc/ipci.c index bf6b81e621b,c439033fe77..00000000000 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@@ -14,16 -14,46 +14,22 @@@ */ #include "postgres.h" -#include "access/clog.h" -#include "access/commit_ts.h" -#include "access/multixact.h" -#include "access/nbtree.h" -#include "access/subtrans.h" -#include "access/syncscan.h" -#include "access/transam.h" -#include "access/twophase.h" -#include "access/xlogprefetcher.h" -#include "access/xlogrecovery.h" -#include "access/xlogwait.h" -#include "commands/async.h" #include "miscadmin.h" #include "pgstat.h" -#include "postmaster/autovacuum.h" -#include "postmaster/bgworker_internals.h" -#include "postmaster/bgwriter.h" -#include "postmaster/walsummarizer.h" -#include "replication/logicallauncher.h" -#include "replication/origin.h" -#include "replication/slot.h" -#include "replication/slotsync.h" -#include "replication/walreceiver.h" -#include "replication/walsender.h" -#include "storage/aio_subsys.h" -#include "storage/bufmgr.h" #include "storage/dsm.h" -#include "storage/dsm_registry.h" #include "storage/ipc.h" +#include "storage/lock.h" #include "storage/pg_shmem.h" -#include "storage/pmsignal.h" -#include "storage/predicate.h" #include "storage/proc.h" -#include "storage/procarray.h" -#include "storage/procsignal.h" -#include "storage/sinvaladt.h" +#include "storage/shmem_internal.h" +#include "storage/subsystems.h" #include "utils/guc.h" ++<<<<<<< ours ++======= + #include "utils/injection_point.h" + #include "utils/memutils.h" + #include "utils/wait_event.h" ++>>>>>>> theirs /* GUCs */ int shared_memory_type = DEFAULT_SHARED_MEMORY_TYPE; @@@ -68,7 -100,50 +74,54 @@@ CalculateShmemSize(void * during the actual allocation phase. */ size = 100000; ++<<<<<<< ours + size = add_size(size, ShmemGetRequestedSize()); ++======= + size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE, + sizeof(ShmemIndexEnt))); + size = add_size(size, dsm_estimate_size()); + size = add_size(size, DSMRegistryShmemSize()); + size = add_size(size, BufferManagerShmemSize()); + size = add_size(size, LockManagerShmemSize()); + size = add_size(size, PredicateLockShmemSize()); + size = add_size(size, ProcGlobalShmemSize()); + size = add_size(size, XLogPrefetchShmemSize()); + size = add_size(size, VarsupShmemSize()); + size = add_size(size, XLOGShmemSize()); + size = add_size(size, XLogRecoveryShmemSize()); + size = add_size(size, CLOGShmemSize()); + size = add_size(size, CommitTsShmemSize()); + size = add_size(size, SUBTRANSShmemSize()); + size = add_size(size, TwoPhaseShmemSize()); + size = add_size(size, BackgroundWorkerShmemSize()); + size = add_size(size, MultiXactShmemSize()); + size = add_size(size, LWLockShmemSize()); + size = add_size(size, ProcArrayShmemSize()); + size = add_size(size, BackendStatusShmemSize()); + size = add_size(size, SharedInvalShmemSize()); + size = add_size(size, PMSignalShmemSize()); + size = add_size(size, ProcSignalShmemSize()); + size = add_size(size, CheckpointerShmemSize()); + size = add_size(size, AutoVacuumShmemSize()); + size = add_size(size, ReplicationSlotsShmemSize()); + size = add_size(size, ReplicationOriginShmemSize()); + size = add_size(size, WalSndShmemSize()); + size = add_size(size, WalRcvShmemSize()); + size = add_size(size, WalSummarizerShmemSize()); + size = add_size(size, PgArchShmemSize()); + size = add_size(size, ApplyLauncherShmemSize()); + size = add_size(size, BTreeShmemSize()); + size = add_size(size, SyncScanShmemSize()); + size = add_size(size, AsyncShmemSize()); + size = add_size(size, StatsShmemSize()); + size = add_size(size, WaitEventCustomShmemSize()); + size = add_size(size, InjectionPointShmemSize()); + size = add_size(size, SlotSyncShmemSize()); + size = add_size(size, AioShmemSize()); + size = add_size(size, WaitLSNShmemSize()); + size = add_size(size, LogicalDecodingCtlShmemSize()); + size = add_size(size, MemoryContextKeysShmemSize()); ++>>>>>>> theirs /* include additional requested shmem from preload libraries */ size = add_size(size, total_addin_request); @@@ -160,23 -234,104 +213,70 @@@ CreateSharedMemoryAndSemaphores(void } /* - * Initialize various subsystems, setting up their data structures in - * shared memory. - * - * This is called by the postmaster or by a standalone backend. - * It is also called by a backend forked from the postmaster in the - * EXEC_BACKEND case. In the latter case, the shared memory segment - * already exists and has been physically attached to, but we have to - * initialize pointers in local memory that reference the shared structures, - * because we didn't inherit the correct pointer values from the postmaster - * as we do in the fork() scenario. The easiest way to do that is to run - * through the same code as before. (Note that the called routines mostly - * check IsUnderPostmaster, rather than EXEC_BACKEND, to detect this case. - * This is a bit code-wasteful and could be cleaned up.) + * Early initialization of various subsystems, giving them a chance to + * register their shared memory needs before the shared memory segment is + * allocated. */ -static void -CreateOrAttachShmemStructs(void) +void +RegisterBuiltinShmemCallbacks(void) { /* - * Now initialize LWLocks, which do shared memory allocation and are - * needed for InitShmemIndex. - */ - CreateLWLocks(); - - /* - * Set up shmem.c index hashtable + * Call RegisterShmemCallbacks(...) on each subsystem listed in + * subsystemslist.h */ - InitShmemIndex(); +#define PG_SHMEM_SUBSYSTEM(subsystem_callbacks) \ + RegisterShmemCallbacks(&(subsystem_callbacks)); - dsm_shmem_init(); - DSMRegistryShmemInit(); - - /* - * Set up xlog, clog, and buffers - */ - VarsupShmemInit(); - XLOGShmemInit(); - XLogPrefetchShmemInit(); - XLogRecoveryShmemInit(); - CLOGShmemInit(); - CommitTsShmemInit(); - SUBTRANSShmemInit(); - MultiXactShmemInit(); - BufferManagerShmemInit(); - - /* - * Set up lock manager - */ - LockManagerShmemInit(); - - /* - * Set up predicate lock manager - */ - PredicateLockShmemInit(); +#include "storage/subsystemlist.h" ++<<<<<<< ours +#undef PG_SHMEM_SUBSYSTEM ++======= + /* + * Set up process table + */ + if (!IsUnderPostmaster) + InitProcGlobal(); + ProcArrayShmemInit(); + BackendStatusShmemInit(); + TwoPhaseShmemInit(); + BackgroundWorkerShmemInit(); + + /* + * Set up shared-inval messaging + */ + SharedInvalShmemInit(); + + /* + * Set up interprocess signaling mechanisms + */ + PMSignalShmemInit(); + ProcSignalShmemInit(); + CheckpointerShmemInit(); + AutoVacuumShmemInit(); + ReplicationSlotsShmemInit(); + ReplicationOriginShmemInit(); + WalSndShmemInit(); + WalRcvShmemInit(); + WalSummarizerShmemInit(); + PgArchShmemInit(); + ApplyLauncherShmemInit(); + SlotSyncShmemInit(); + + /* + * Set up other modules that need some shared memory space + */ + BTreeShmemInit(); + SyncScanShmemInit(); + AsyncShmemInit(); + StatsShmemInit(); + WaitEventCustomShmemInit(); + InjectionPointShmemInit(); + AioShmemInit(); + WaitLSNShmemInit(); + LogicalDecodingCtlShmemInit(); + MemoryContextKeysShmemInit(); ++>>>>>>> theirs } /* diff --cc src/backend/utils/activity/wait_event_names.txt index 560659f9568,5ea196eeed8..00000000000 --- a/src/backend/utils/activity/wait_event_names.txt +++ b/src/backend/utils/activity/wait_event_names.txt @@@ -368,8 -367,7 +369,12 @@@ SerialControl "Waiting to read or updat AioWorkerSubmissionQueue "Waiting to access AIO worker submission queue." WaitLSN "Waiting to read or update shared Wait-for-LSN state." LogicalDecodingControl "Waiting to read or update logical decoding status information." ++<<<<<<< ours +DataChecksumsWorker "Waiting for data checksums worker." +AioWorkerControl "Waiting to update AIO worker information." ++======= + MemContextReportingClientKeys "Waiting for another process to complete reading or writing the memory reporting keys." ++>>>>>>> theirs # # END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE) diff --cc src/backend/utils/adt/mcxtfuncs.c index 1a4dbbeb8db,666265efa1f..00000000000 --- a/src/backend/utils/adt/mcxtfuncs.c +++ b/src/backend/utils/adt/mcxtfuncs.c @@@ -15,16 -15,108 +15,116 @@@ #include "postgres.h" ++<<<<<<< ours +#include "catalog/pg_type_d.h" ++======= + #include "access/xact.h" ++>>>>>>> theirs #include "funcapi.h" #include "mb/pg_wchar.h" + #include "storage/dsm_registry.h" #include "storage/proc.h" #include "storage/procarray.h" #include "storage/procsignal.h" #include "utils/array.h" #include "utils/builtins.h" #include "utils/hsearch.h" ++<<<<<<< ours +#include "utils/tuplestore.h" ++======= + #include "utils/injection_point.h" + #include "utils/memutils.h" + #include "utils/wait_event_types.h" + + /* + * Memory Context reporting size limits. + */ + + /* Max length of context name and ident, to keep it consistent + * with ProcessLogMemoryContext() + */ + #define MEMORY_CONTEXT_IDENT_SHMEM_SIZE 100 + #define MEMORY_CONTEXT_NAME_SHMEM_SIZE 100 + #define MAX_PATH_DISPLAY_LENGTH 100 + + /* Maximum size (in bytes) of DSA area per process */ + #define MEMORY_CONTEXT_REPORT_MAX_PER_BACKEND ((size_t) (1 * 1024 * 1024)) + + /* + * Maximum number of memory context statistics is calculated by dividing + * max memory allocated per backend with maximum size per context statistics. + * The identifier and name are statically allocated arrays of size 100 bytes. + * The path depth is limited to 100 like for memory context logging. + */ + #define MAX_MEMORY_CONTEXT_STATS_NUM MEMORY_CONTEXT_REPORT_MAX_PER_BACKEND / (sizeof(MemoryStatsEntry)) + + /* Dynamic shared memory state for reporting statistics per context */ + typedef struct MemoryStatsEntry + { + char name[MEMORY_CONTEXT_NAME_SHMEM_SIZE]; + char ident[MEMORY_CONTEXT_IDENT_SHMEM_SIZE]; + int path[MAX_PATH_DISPLAY_LENGTH]; + NodeTag type; + int path_length; + int levels; + int64 totalspace; + int64 nblocks; + int64 freespace; + int64 freechunks; + int num_agg_stats; + } MemoryStatsEntry; + + /* + * Per backend dynamic shared hash entry for memory context statistics + * reporting. + */ + typedef struct MemoryStatsDSHashEntry + { + ProcNumber client_key; + ConditionVariable memcxt_cv; + bool stats_written; + int target_server_id; + int total_stats; + bool summary; + dsa_pointer memstats_dsa_pointer; + } MemoryStatsDSHashEntry; + + static const dshash_parameters memctx_dsh_params = { + sizeof(ProcNumber), + sizeof(MemoryStatsDSHashEntry), + dshash_memcmp, + dshash_memhash, + dshash_memcpy + }; + + /* + * These are used for reporting memory context statistics of a process. + */ + + /* Array to store the keys of MemoryStatsDsHash */ + static int *client_keys = NULL; + + /* + * Table to store pointers to DSA memory containing memory statistics and other + * metadata. There is one entry per client backend request, keyed by ProcNumber + * of the client obtained from client_keys array above. + */ + static dshash_table *MemoryStatsDsHash = NULL; + + /* + * Dsa area which stores the actual memory context + * statistics. + */ + static dsa_area *MemoryStatsDsaArea = NULL; + + static void memstats_dsa_cleanup(int ProcNumber); + static void memstats_client_key_reset(int ProcNumber); + static void PublishMemoryContext(MemoryStatsEntry *memcxt_info, + int curr_id, MemoryContext context, + List *path, + MemoryContextCounters stat, + int num_contexts); ++>>>>>>> theirs /* ---------- * The max bytes for showing identifiers of MemoryContext. diff --cc src/include/storage/lwlocklist.h index d7eb648bd27,6dd80689bbb..00000000000 --- a/src/include/storage/lwlocklist.h +++ b/src/include/storage/lwlocklist.h @@@ -87,8 -87,7 +87,12 @@@ PG_LWLOCK(52, SerialControl PG_LWLOCK(53, AioWorkerSubmissionQueue) PG_LWLOCK(54, WaitLSN) PG_LWLOCK(55, LogicalDecodingControl) ++<<<<<<< ours +PG_LWLOCK(56, DataChecksumsWorker) +PG_LWLOCK(57, AioWorkerControl) ++======= + PG_LWLOCK(56, MemContextReportingClientKeys) ++>>>>>>> theirs /* * There also exist several built-in LWLock tranches. As with the predefined