summaryrefslogtreecommitdiff
path: root/src/backend/utils/mmgr/dsa.c
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2025-12-02 10:29:45 -0600
committerNathan Bossart <nathan@postgresql.org>2025-12-02 10:29:45 -0600
commitf894acb24a12cf1f369a45af36c8f4049f9af571 (patch)
tree74809e7b4b473e59fc68b6ced4a4157d658c37bd /src/backend/utils/mmgr/dsa.c
parent758479213d574d6e2fbbdfee5328edef3d60da61 (diff)
Show size of DSAs and dshashes in pg_dsm_registry_allocations.
Presently, this view reports NULL for the size of DSAs and dshash tables because 1) the current backend might not be attached to them and 2) the registry doesn't save the pointers to the dsa_area or dshash_table in local memory. Also, the view doesn't show partially-initialized entries to avoid ambiguity, since those entries would report a NULL size as well. This commit introduces a function that looks up the size of a DSA given its handle (transiently attaching to the control segment if needed) and teaches pg_dsm_registry_allocations to use it to show the size of successfully-initialized DSA and dshash entries. Furthermore, the view now reports partially-initialized entries with a NULL size. Reviewed-by: Rahila Syed <rahilasyed90@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/aSeEDeznAsHR1_YF%40nathan
Diffstat (limited to 'src/backend/utils/mmgr/dsa.c')
-rw-r--r--src/backend/utils/mmgr/dsa.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c
index be43e9351c3..c8a72686177 100644
--- a/src/backend/utils/mmgr/dsa.c
+++ b/src/backend/utils/mmgr/dsa.c
@@ -1051,6 +1051,41 @@ dsa_get_total_size(dsa_area *area)
}
/*
+ * Same as dsa_get_total_size(), but accepts a DSA handle. The area must have
+ * been created with dsa_create (not dsa_create_in_place).
+ */
+size_t
+dsa_get_total_size_from_handle(dsa_handle handle)
+{
+ size_t size;
+ bool already_attached;
+ dsm_segment *segment;
+ dsa_area_control *control;
+
+ already_attached = dsa_is_attached(handle);
+ if (already_attached)
+ segment = dsm_find_mapping(handle);
+ else
+ segment = dsm_attach(handle);
+
+ if (segment == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("could not attach to dynamic shared area")));
+
+ control = (dsa_area_control *) dsm_segment_address(segment);
+
+ LWLockAcquire(&control->lock, LW_EXCLUSIVE);
+ size = control->total_segment_size;
+ LWLockRelease(&control->lock);
+
+ if (!already_attached)
+ dsm_detach(segment);
+
+ return size;
+}
+
+/*
* Aggressively free all spare memory in the hope of returning DSM segments to
* the operating system.
*/