aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2025-04-10 22:40:27 +0200
committerDaniel Gustafsson <dgustafsson@postgresql.org>2025-04-10 22:40:27 +0200
commit55ef7abf88c07e9f716846e645e1628c667c54a7 (patch)
tree23a40ab9d8670c83944772e92531aa47a4d17d3f /src
parent22cb6d289500ef22163a9d7cf2afa496f41b4d4c (diff)
downloadpostgresql-55ef7abf88c07e9f716846e645e1628c667c54a7.tar.gz
postgresql-55ef7abf88c07e9f716846e645e1628c667c54a7.zip
Rename global variable backing DSA area
The global variable backing the DSA area for Memory Context stats reporting had a too generic name, rename to be more descriptive. Independently reported by Peter and Laurenz. Author: Daniel Gustafsson <daniel@yesql.se> Reported-by: Peter Eisentraut <peter@eisentraut.org> Reported-by: Laurenz Albe <laurenz.albe@cybertec.at> Discussion: https://postgr.es/m/d51172bd4e7f4b07a18a0288ca1b1c28a71a5f6a.camel@cybertec.at Discussion: https://postgr.es/m/25095db5-b595-4b85-9100-d358907c25b5@eisentraut.org
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/mcxtfuncs.c14
-rw-r--r--src/backend/utils/mmgr/mcxt.c40
-rw-r--r--src/include/utils/memutils.h2
3 files changed, 28 insertions, 28 deletions
diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index 3ede88e5036..254cdd34fba 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -533,21 +533,21 @@ pg_get_process_memory_contexts(PG_FUNCTION_ARGS)
*/
Assert(memCxtArea->memstats_dsa_handle != DSA_HANDLE_INVALID);
/* Attach to the dsa area if we have not already done so */
- if (area == NULL)
+ if (MemoryStatsDsaArea == NULL)
{
MemoryContext oldcontext = CurrentMemoryContext;
MemoryContextSwitchTo(TopMemoryContext);
- area = dsa_attach(memCxtArea->memstats_dsa_handle);
+ MemoryStatsDsaArea = dsa_attach(memCxtArea->memstats_dsa_handle);
MemoryContextSwitchTo(oldcontext);
- dsa_pin_mapping(area);
+ dsa_pin_mapping(MemoryStatsDsaArea);
}
/*
* Backend has finished publishing the stats, project them.
*/
memcxt_info = (MemoryStatsEntry *)
- dsa_get_address(area, memCxtState[procNumber].memstats_dsa_pointer);
+ dsa_get_address(MemoryStatsDsaArea, memCxtState[procNumber].memstats_dsa_pointer);
#define PG_GET_PROCESS_MEMORY_CONTEXTS_COLS 12
for (int i = 0; i < memCxtState[procNumber].total_stats; i++)
@@ -566,7 +566,7 @@ pg_get_process_memory_contexts(PG_FUNCTION_ARGS)
if (DsaPointerIsValid(memcxt_info[i].name))
{
- name = (char *) dsa_get_address(area, memcxt_info[i].name);
+ name = (char *) dsa_get_address(MemoryStatsDsaArea, memcxt_info[i].name);
values[0] = CStringGetTextDatum(name);
}
else
@@ -574,7 +574,7 @@ pg_get_process_memory_contexts(PG_FUNCTION_ARGS)
if (DsaPointerIsValid(memcxt_info[i].ident))
{
- ident = (char *) dsa_get_address(area, memcxt_info[i].ident);
+ ident = (char *) dsa_get_address(MemoryStatsDsaArea, memcxt_info[i].ident);
values[1] = CStringGetTextDatum(ident);
}
else
@@ -586,7 +586,7 @@ pg_get_process_memory_contexts(PG_FUNCTION_ARGS)
path_datum = (Datum *) palloc(path_length * sizeof(Datum));
if (DsaPointerIsValid(memcxt_info[i].path))
{
- path_int = (int *) dsa_get_address(area, memcxt_info[i].path);
+ path_int = (int *) dsa_get_address(MemoryStatsDsaArea, memcxt_info[i].path);
for (int j = 0; j < path_length; j++)
path_datum[j] = Int32GetDatum(path_int[j]);
path_array = construct_array_builtin(path_datum, path_length, INT4OID);
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index cf4e22bf1cc..677ee42596f 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -172,7 +172,7 @@ MemoryContext CurTransactionContext = NULL;
/* This is a transient link to the active portal's memory context: */
MemoryContext PortalContext = NULL;
-dsa_area *area = NULL;
+dsa_area *MemoryStatsDsaArea = NULL;
static void MemoryContextDeleteOnly(MemoryContext context);
static void MemoryContextCallResetCallbacks(MemoryContext context);
@@ -1499,19 +1499,19 @@ ProcessGetMemoryContextInterrupt(void)
MemoryContextSwitchTo(TopMemoryContext);
- area = dsa_create(memCxtArea->lw_lock.tranche);
+ MemoryStatsDsaArea = dsa_create(memCxtArea->lw_lock.tranche);
- handle = dsa_get_handle(area);
+ handle = dsa_get_handle(MemoryStatsDsaArea);
MemoryContextSwitchTo(oldcontext);
- dsa_pin_mapping(area);
+ dsa_pin_mapping(MemoryStatsDsaArea);
/*
* Pin the DSA area, this is to make sure the area remains attachable
* even if current backend exits. This is done so that the statistics
* are published even if the process exits while a client is waiting.
*/
- dsa_pin(area);
+ dsa_pin(MemoryStatsDsaArea);
/* Set the handle in shared memory */
memCxtArea->memstats_dsa_handle = handle;
@@ -1521,14 +1521,14 @@ ProcessGetMemoryContextInterrupt(void)
* If DSA exists, created by another process publishing statistics, attach
* to it.
*/
- else if (area == NULL)
+ else if (MemoryStatsDsaArea == NULL)
{
MemoryContext oldcontext = CurrentMemoryContext;
MemoryContextSwitchTo(TopMemoryContext);
- area = dsa_attach(memCxtArea->memstats_dsa_handle);
+ MemoryStatsDsaArea = dsa_attach(memCxtArea->memstats_dsa_handle);
MemoryContextSwitchTo(oldcontext);
- dsa_pin_mapping(area);
+ dsa_pin_mapping(MemoryStatsDsaArea);
}
LWLockRelease(&memCxtArea->lw_lock);
@@ -1545,7 +1545,7 @@ ProcessGetMemoryContextInterrupt(void)
* Free any previous allocations, free the name, ident and path
* pointers before freeing the pointer that contains them.
*/
- free_memorycontextstate_dsa(area, memCxtState[idx].total_stats,
+ free_memorycontextstate_dsa(MemoryStatsDsaArea, memCxtState[idx].total_stats,
memCxtState[idx].memstats_dsa_pointer);
}
@@ -1556,10 +1556,10 @@ ProcessGetMemoryContextInterrupt(void)
*/
memCxtState[idx].total_stats = stats_num;
memCxtState[idx].memstats_dsa_pointer =
- dsa_allocate0(area, stats_num * sizeof(MemoryStatsEntry));
+ dsa_allocate0(MemoryStatsDsaArea, stats_num * sizeof(MemoryStatsEntry));
meminfo = (MemoryStatsEntry *)
- dsa_get_address(area, memCxtState[idx].memstats_dsa_pointer);
+ dsa_get_address(MemoryStatsDsaArea, memCxtState[idx].memstats_dsa_pointer);
if (summary)
{
@@ -1572,7 +1572,7 @@ ProcessGetMemoryContextInterrupt(void)
&stat, true);
path = lcons_int(1, path);
PublishMemoryContext(meminfo, cxt_id, TopMemoryContext, path, stat,
- 1, area, 100);
+ 1, MemoryStatsDsaArea, 100);
cxt_id = cxt_id + 1;
/*
@@ -1602,7 +1602,7 @@ ProcessGetMemoryContextInterrupt(void)
*/
memCxtState[idx].total_stats = cxt_id++;
PublishMemoryContext(meminfo, cxt_id, c, path,
- grand_totals, num_contexts, area, 100);
+ grand_totals, num_contexts, MemoryStatsDsaArea, 100);
}
memCxtState[idx].total_stats = cxt_id;
@@ -1632,7 +1632,7 @@ ProcessGetMemoryContextInterrupt(void)
if (context_id < (max_stats - 1) || stats_count <= max_stats)
{
/* Copy statistics to DSA memory */
- PublishMemoryContext(meminfo, context_id, cur, path, stat, 1, area, 100);
+ PublishMemoryContext(meminfo, context_id, cur, path, stat, 1, MemoryStatsDsaArea, 100);
}
else
{
@@ -1657,8 +1657,8 @@ ProcessGetMemoryContextInterrupt(void)
int namelen = strlen("Remaining Totals");
num_individual_stats = context_id + 1;
- meminfo[max_stats - 1].name = dsa_allocate(area, namelen + 1);
- nameptr = dsa_get_address(area, meminfo[max_stats - 1].name);
+ meminfo[max_stats - 1].name = dsa_allocate(MemoryStatsDsaArea, namelen + 1);
+ nameptr = dsa_get_address(MemoryStatsDsaArea, meminfo[max_stats - 1].name);
strncpy(nameptr, "Remaining Totals", namelen);
meminfo[max_stats - 1].ident = InvalidDsaPointer;
meminfo[max_stats - 1].path = InvalidDsaPointer;
@@ -1921,18 +1921,18 @@ AtProcExit_memstats_cleanup(int code, Datum arg)
}
/* If the dsa mapping could not be found, attach to the area */
- if (area == NULL)
- area = dsa_attach(memCxtArea->memstats_dsa_handle);
+ if (MemoryStatsDsaArea == NULL)
+ MemoryStatsDsaArea = dsa_attach(memCxtArea->memstats_dsa_handle);
/*
* Free the memory context statistics, free the name, ident and path
* pointers before freeing the pointer that contains these pointers and
* integer statistics.
*/
- free_memorycontextstate_dsa(area, memCxtState[idx].total_stats,
+ free_memorycontextstate_dsa(MemoryStatsDsaArea, memCxtState[idx].total_stats,
memCxtState[idx].memstats_dsa_pointer);
- dsa_detach(area);
+ dsa_detach(MemoryStatsDsaArea);
LWLockRelease(&memCxtState[idx].lw_lock);
}
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h
index d328270fafc..c0987dca155 100644
--- a/src/include/utils/memutils.h
+++ b/src/include/utils/memutils.h
@@ -394,11 +394,11 @@ typedef struct MemoryStatsContextId
extern PGDLLIMPORT MemoryStatsBackendState *memCxtState;
extern PGDLLIMPORT MemoryStatsCtl *memCxtArea;
+extern PGDLLIMPORT dsa_area *MemoryStatsDsaArea;
extern void ProcessGetMemoryContextInterrupt(void);
extern const char *ContextTypeToString(NodeTag type);
extern void HandleGetMemoryContextInterrupt(void);
extern Size MemoryContextReportingShmemSize(void);
extern void MemoryContextReportingShmemInit(void);
extern void AtProcExit_memstats_cleanup(int code, Datum arg);
-extern dsa_area *area;
#endif /* MEMUTILS_H */