int32 maxChunksPerProcess = 0; // be set by GUC variable --max_dynamic_memory volatile int32 processMemInChunks = 200; // track the memory used by process --dynamic_used_memory int32 peakChunksPerProcess = 0; // the peak memory of process --dynamic_peak_memory int32 comm_original_memory = 0; // original comm memory int32 maxSharedMemory = 0; // original shared memory int32 backendReservedMemInChunk = 0; // reserved memory for backend threads volatile int32 backendUsedMemInChunk = 0; // the memory usage for backend threads
template <knl_thread_role thread_role> intGaussDbThreadMain(knl_thread_arg* arg) { ... /* Check this thread will use reserved memory or not */ is_memory_backend_reserved(arg); /* Initialize the Memory Protection at the thread level */ gs_memprot_thread_init(); MemoryContextInit();
staticvoidis_memory_backend_reserved(const knl_thread_arg* arg) { if (arg->role == WORKER) { Port port = ((BackendParameters*)(arg->save_para))->port; if (processMemInChunks >= maxChunksPerProcess * 0.8 && IsHAPort(&port)) { t_thrd.utils_cxt.backend_reserved = true; } else { t_thrd.utils_cxt.backend_reserved = false; } return; }
switch (arg->role) { case WALWRITER: case WALRECEIVER: case WALRECWRITE: case DATARECIVER: case DATARECWRITER: t_thrd.utils_cxt.backend_reserved = true; break; default: t_thrd.utils_cxt.backend_reserved = false; break; } }
/* thread level initialization */ voidgs_memprot_thread_init(void) { /* The Process level protection has been triggered */ if (maxChunksPerProcess) { t_thrd.utils_cxt.gs_mp_inited = true; } }
voidMemoryContextInit(void) { CStoreMemAlloc::Init(); if (TopMemoryContext != NULL) { return; }
Datum pv_session_memory_detail(PG_FUNCTION_ARGS) g_threadPoolControler->GetSessionCtrl()->getSessionMemoryDetail(rsinfo->setResult, rsinfo->setDesc, &sess);
Datum pv_thread_memory_detail(PG_FUNCTION_ARGS) getThreadMemoryDetail(rsinfo->setResult, rsinfo->setDesc, &procIdx); Datum pv_total_memory_detail(PG_FUNCTION_ARGS)