diff --git a/src/common/backend/utils/mmgr/memprot.cpp b/src/common/backend/utils/mmgr/memprot.cpp index 7947c26fc5a3ac14c6dedfcb47b97a74c8545b0e..595b282787656b28e92aebbc9ea2922a779e8c81 100755 --- a/src/common/backend/utils/mmgr/memprot.cpp +++ b/src/common/backend/utils/mmgr/memprot.cpp @@ -580,16 +580,6 @@ static bool memTracker_ReserveMemChunks(int32 numChunksToReserve, bool needProte Assert(0 < numChunksToReserve); - /* query level memory verification */ - if (t_thrd.shemem_ptr_cxt.mySessionMemoryEntry && type != MEM_SHRD) { - /* 1. increase memory in chunk at query level */ - total = gs_atomic_add_32(&(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->queryMemInChunks), numChunksToReserve); - - /* 2. update the peak memory of the query */ - if (t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery < total) - gs_lock_test_and_set(&(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery), total); - } - /* increase chunk quota at global gaussdb process level */ if (t_thrd.utils_cxt.backend_reserved) { currSize = &backendUsedMemInChunk; @@ -611,6 +601,16 @@ static bool memTracker_ReserveMemChunks(int32 numChunksToReserve, bool needProte t_thrd.utils_cxt.beyondChunk = 0; } + /* query level memory verification */ + if (t_thrd.shemem_ptr_cxt.mySessionMemoryEntry && type != MEM_SHRD) { + /* 1. increase memory in chunk at query level */ + total = gs_atomic_add_32(&(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->queryMemInChunks), numChunksToReserve); + + /* 2. update the peak memory of the query */ + if (t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery < total) + gs_lock_test_and_set(&(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery), total); + } + if (peakChunksPerProcess < processMemInChunks + backendUsedMemInChunk) { peakChunksPerProcess = processMemInChunks + backendUsedMemInChunk; diff --git a/src/gausskernel/process/postmaster/autovacuum.cpp b/src/gausskernel/process/postmaster/autovacuum.cpp index 276f5b2f64e2eab45cd6d9bd90461e65c1bb400b..d9564a6803c2b1e3f3014e74f854206e9c34254e 100755 --- a/src/gausskernel/process/postmaster/autovacuum.cpp +++ b/src/gausskernel/process/postmaster/autovacuum.cpp @@ -395,6 +395,14 @@ NON_EXEC_STATIC void AutoVacLauncherMain() t_thrd.autovacuum_cxt.AutoVacuumShmem->av_launcherpid = t_thrd.proc_cxt.MyProcPid; + if (likely(t_thrd.shemem_ptr_cxt.mySessionMemoryEntry != NULL)) { + t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->initMemInChunks = t_thrd.utils_cxt.trackedMemChunks; + t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->queryMemInChunks = t_thrd.utils_cxt.trackedMemChunks; + t_thrd.shemem_ptr_cxt.mySessionMemoryEntry->peakChunksQuery = t_thrd.utils_cxt.trackedMemChunks; + } + t_thrd.utils_cxt.peakedBytesInQueryLifeCycle = 0; + t_thrd.utils_cxt.basedBytesInQueryLifeCycle = 0; + /* * Create the initial database list. The invariant we want this list to * keep is that it's ordered by decreasing next_time. As soon as an entry