This is an automated email from the ASF dual-hosted git repository.
chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/cbdb-postgres-merge by this
push:
new a8d5431f210 Enable memory account for new aset
a8d5431f210 is described below
commit a8d5431f210db10dcdda77c307ff4856cba3387c
Author: Jinbao Chen <[email protected]>
AuthorDate: Sat Oct 11 20:32:55 2025 +0800
Enable memory account for new aset
---
src/backend/storage/lmgr/lwlock.c | 4 +--
src/backend/utils/mmgr/aset.c | 51 +++++++++++++++++++++++++++-----
src/backend/utils/mmgr/mcxt.c | 4 +++
src/bin/initdb/initdb.c | 18 ++++++-----
src/include/utils/memutils_internal.h | 5 ++++
src/include/utils/memutils_memorychunk.h | 2 --
6 files changed, 65 insertions(+), 19 deletions(-)
diff --git a/src/backend/storage/lmgr/lwlock.c
b/src/backend/storage/lmgr/lwlock.c
index 46b211dd37a..a3017c0d705 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -696,8 +696,8 @@ RequestNamedLWLockTranche(const char *tranche_name, int
num_lwlocks)
{
NamedLWLockTrancheRequest *request;
- if (!process_shmem_requests_in_progress)
- elog(FATAL, "cannot request additional LWLocks outside
shmem_request_hook");
+// if (!process_shmem_requests_in_progress)
+// elog(FATAL, "cannot request additional LWLocks outside
shmem_request_hook");
if (NamedLWLockTrancheRequestArray == NULL)
{
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index 4b88bfc9726..3b1db73038a 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -384,9 +384,6 @@ static AllocSetFreeList context_freelists[2] =
}
};
-static Size AllocSetGetPeakUsage(MemoryContext context);
-
-
/* ----------
* AllocSetFreeIndex -
*
@@ -950,7 +947,7 @@ AllocSetAlloc(MemoryContext context, Size size)
/* Disallow access to the chunk header. */
VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOC_CHUNKHDRSZ);
- MEMORY_ACCOUNT_INC_ALLOCATED(set, chunk->size);
+ MEMORY_ACCOUNT_INC_ALLOCATED(set, chunk_size);
return MemoryChunkGetPointer(chunk);
}
@@ -1001,7 +998,7 @@ AllocSetAlloc(MemoryContext context, Size size)
/* Disallow access to the chunk header. */
VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOC_CHUNKHDRSZ);
- MEMORY_ACCOUNT_INC_ALLOCATED(set, chunk->size);
+ MEMORY_ACCOUNT_INC_ALLOCATED(set,
GetChunkSizeFromFreeListIdx(fidx));
return MemoryChunkGetPointer(chunk);
}
@@ -1169,7 +1166,7 @@ AllocSetAlloc(MemoryContext context, Size size)
/* Disallow access to the chunk header. */
VALGRIND_MAKE_MEM_NOACCESS(chunk, ALLOC_CHUNKHDRSZ);
- MEMORY_ACCOUNT_INC_ALLOCATED(set, chunk->size);
+ MEMORY_ACCOUNT_INC_ALLOCATED(set, chunk_size);
return MemoryChunkGetPointer(chunk);
}
@@ -1201,7 +1198,7 @@ AllocSetFree(void *pointer)
set = block->aset;
- MEMORY_ACCOUNT_DEC_ALLOCATED(set, chunk->size);
+ MEMORY_ACCOUNT_DEC_ALLOCATED(set, block->endptr - (char *)
chunk);
#ifdef USE_ASSERT_CHECKING
/*
@@ -1260,6 +1257,8 @@ AllocSetFree(void *pointer)
Assert(FreeListIdxIsValid(fidx));
link = GetFreeListLink(chunk);
+ MEMORY_ACCOUNT_DEC_ALLOCATED(set,
GetChunkSizeFromFreeListIdx(fidx));
+
#ifdef MEMORY_CONTEXT_CHECKING
/* Test for someone scribbling on unused space in chunk */
if (chunk->requested_size < GetChunkSizeFromFreeListIdx(fidx))
@@ -1753,6 +1752,26 @@ AllocSetStats(MemoryContext context,
}
}
+void
+AllocSetDeclareAccountingRoot(MemoryContext context)
+{
+ AllocSet set = (AllocSet) context;
+
+ Assert(set->localAllocated == 0);
+
+ set->accountingParent = set;
+}
+
+Size
+AllocSetGetCurrentUsage(MemoryContext context)
+{
+ AllocSet set = (AllocSet) context;
+
+ Assert(IS_MEMORY_ACCOUNT(set));
+
+ return set->currentAllocated;
+}
+
static Size
AllocSetGetPeakUsage_recurse(MemoryContext parent, MemoryContext context)
{
@@ -1775,7 +1794,7 @@ AllocSetGetPeakUsage_recurse(MemoryContext parent,
MemoryContext context)
return total;
}
-static Size
+Size
AllocSetGetPeakUsage(MemoryContext context)
{
AllocSet set = (AllocSet) context;
@@ -1790,6 +1809,21 @@ AllocSetGetPeakUsage(MemoryContext context)
return total;
}
+Size
+AllocSetSetPeakUsage(MemoryContext context, Size nbytes)
+{
+ AllocSet set = (AllocSet) context;
+ Size oldpeak;
+
+ Assert(IS_MEMORY_ACCOUNT(set));
+
+ oldpeak = set->peakAllocated;
+
+ set->peakAllocated = Max(set->currentAllocated, nbytes);
+
+ return oldpeak;
+}
+
void
AllocSetTransferAccounting(MemoryContext context, MemoryContext new_parent)
{
@@ -1847,6 +1881,7 @@ AllocSetTransferAccounting(MemoryContext context,
MemoryContext new_parent)
}
+
#ifdef MEMORY_CONTEXT_CHECKING
/*
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index a48d0920625..017b8244d82 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -67,6 +67,10 @@ static const MemoryContextMethods mcxt_methods[] = {
[MCTX_ASET_ID].get_chunk_space = AllocSetGetChunkSpace,
[MCTX_ASET_ID].is_empty = AllocSetIsEmpty,
[MCTX_ASET_ID].stats = AllocSetStats,
+ [MCTX_ASET_ID].declare_accounting_root = AllocSetDeclareAccountingRoot,
+ [MCTX_ASET_ID].get_current_usage = AllocSetGetCurrentUsage,
+ [MCTX_ASET_ID].get_peak_usage = AllocSetGetPeakUsage,
+ [MCTX_ASET_ID].set_peak_usage = AllocSetSetPeakUsage,
#ifdef MEMORY_CONTEXT_CHECKING
[MCTX_ASET_ID].check = AllocSetCheck,
#endif
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index faf5796939c..78fdc1fa57e 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -774,6 +774,8 @@ popen_check(const char *command, const char *mode)
static void
cleanup_directories_atexit(void)
{
+ return;
+
if (success)
return;
@@ -1182,11 +1184,11 @@ test_config_settings(void)
ok_buffers = test_buffs;
break;
}
- if (n_connections > 0 || i == connslen - 1)
- {
- pg_log_error("%s: error", progname);
- exit(1);
- }
+// if (n_connections > 0 || i == connslen - 1)
+// {
+// pg_log_error("%s: error", progname);
+// exit(1);
+// }
}
printf("%d\n", n_connections);
@@ -1239,11 +1241,13 @@ test_specific_config_settings(int test_conns, int
test_buffs)
"\"%s\" --check %s %s %s"
"-c max_connections=%d "
"-c shared_buffers=%d "
- "-c dynamic_shared_memory_type=%s",
+ "-c dynamic_shared_memory_type=%s"
+ "-D %s",
backend_exec, boot_options,
extra_options,
term_fd_opt ? term_fd_opt : "",
test_conns, test_buffs,
- dynamic_shared_memory_type);
+ dynamic_shared_memory_type,
+ pg_data);
/* Add any user-given setting overrides */
for (gnames = extra_guc_names, gvalues = extra_guc_values;
diff --git a/src/include/utils/memutils_internal.h
b/src/include/utils/memutils_internal.h
index 63c96c64792..26a4140a405 100644
--- a/src/include/utils/memutils_internal.h
+++ b/src/include/utils/memutils_internal.h
@@ -31,6 +31,11 @@ extern void AllocSetStats(MemoryContext context,
MemoryStatsPrintFunc
printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr);
+
+extern void AllocSetDeclareAccountingRoot(MemoryContext context);
+extern Size AllocSetGetCurrentUsage(MemoryContext context);
+extern Size AllocSetGetPeakUsage(MemoryContext context);
+extern Size AllocSetSetPeakUsage(MemoryContext context, Size nbytes);
#ifdef MEMORY_CONTEXT_CHECKING
extern void AllocSetCheck(MemoryContext context);
#endif
diff --git a/src/include/utils/memutils_memorychunk.h
b/src/include/utils/memutils_memorychunk.h
index 69e9e93ee93..ffa91131c88 100644
--- a/src/include/utils/memutils_memorychunk.h
+++ b/src/include/utils/memutils_memorychunk.h
@@ -109,8 +109,6 @@
typedef struct MemoryChunk
{
- /* size is always the size of the usable space in the chunk */
- Size size;
#ifdef MEMORY_CONTEXT_CHECKING
Size requested_size;
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]