=== Applying patches on top of PostgreSQL commit ID 9f4fd119b2cbb9a41ec0c19a8d6ec9b59b92c125 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Feb 15 01:01:22 UTC 2026 On branch cf/5914 nothing to commit, working tree clean === using 'git am' to apply patch ./v1-0001-Document-DSM-registry.patch === Applying: Document DSM registry Using index info to reconstruct a base tree... M doc/src/sgml/xfunc.sgml Falling back to patching base and 3-way merge... Auto-merging doc/src/sgml/xfunc.sgml CONFLICT (content): Merge conflict in doc/src/sgml/xfunc.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 Document DSM registry 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". Unstaged changes after reset: M doc/src/sgml/xfunc.sgml === using patch(1) to apply patch ./v1-0001-Document-DSM-registry.patch === patching file doc/src/sgml/xfunc.sgml Hunk #1 FAILED at 3685. Hunk #2 succeeded at 3710 with fuzz 1 (offset 5 lines). 1 out of 2 hunks FAILED -- saving rejects to file doc/src/sgml/xfunc.sgml.rej Unstaged changes after reset: M doc/src/sgml/xfunc.sgml Removing doc/src/sgml/xfunc.sgml.rej === using 'git apply' to apply patch ./v1-0001-Document-DSM-registry.patch === Applied patch to 'doc/src/sgml/xfunc.sgml' with conflicts. U doc/src/sgml/xfunc.sgml diff --cc doc/src/sgml/xfunc.sgml index 70e815b8a2c,e94f472e225..00000000000 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@@ -3687,37 -3685,64 +3687,79 @@@ LWLockRelease(AddinShmemInitLock) - Requesting Shared Memory After Startup + DSM Registry ++<<<<<<< ours + There is another, more flexible method of reserving shared memory that + can be done after server startup and outside a + shmem_request_hook. To do so, each backend that will + use the shared memory should obtain a pointer to it by calling: + +void *GetNamedDSMSegment(const char *name, size_t size, + void (*init_callback) (void *ptr, void *arg), + bool *found, void *arg) + ++======= + Another, more flexible way to reserve shared memory after server startup + (and outside a shmem_request_hook) is to use the dynamic shared memory (DSM) registry. + The registry maps library-defined string keys to DSM handles. + It supports creating named DSM segments with GetNamedDSMSegment, + named dynamic shared memory areas (DSAs) with GetNamedDSA, + and named hash tables backed by a DSA with GetNamedDSHash. + + + + Unlike shared memory reserved at server startup, there is no need to + acquire AddinShmemInitLock or otherwise take action + to avoid race conditions when reserving shared memory with these functions. + They ensure that only one backend allocates and initializes the memory structure and that all other + backends receive an appropriate pointer to the fully allocated and initialized segment, area or hash table. + + + + Consider for example this function to allocate a named DSM segment. + + void *GetNamedDSMSegment(const char *name, size_t size, + void (*init_callback) (void *ptr), + bool *found) + ++>>>>>>> theirs If a dynamic shared memory segment with the given name does not yet exist, this function will allocate it and initialize it with the provided init_callback callback function. If the segment has already been allocated and initialized by another backend, this function simply attaches the existing dynamic shared memory segment to the current - backend. + backend. In the former case, GetNamedDSMSegment + passes the void *arg argument to the + init_callback. This is particularly useful for + reusing an initialization callback function for multiple DSM segments. + The same logic applies to the other functions offered by the registry. + - Unlike shared memory reserved at server startup, there is no need to - acquire AddinShmemInitLock or otherwise take action - to avoid race conditions when reserving shared memory with - GetNamedDSMSegment. This function ensures that only - one backend allocates and initializes the segment and that all other - backends receive a pointer to the fully allocated and initialized - segment. + To allocate a named DSA, one can use + + dsa_area *GetNamedDSA(const char *name, bool *found) + + + Νote that this should be called at most once for a given DSA in each backend. + + + + To allocate a named hash table backed by shared memory, one can use + + dshash_table *GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found) + + + Also note that this should be called at most once for a given table in each backend. + + + + To monitor the allocations of the DSM registry + the pg_dsm_registry_allocations system view + documented in can be used.