From 02f1b91e6148679ac40d93b9d20a3af0e2b879eb Mon Sep 17 00:00:00 2001 From: ZigSmith Date: Fri, 21 May 2021 19:42:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8F=AF=E9=80=9A=E8=BF=87configure?= =?UTF-8?q?=E9=80=89=E9=A1=B9--disable-llvm=E5=B1=8F=E8=94=BDllvm=E5=BA=93?= =?UTF-8?q?=E7=9A=84=E9=93=BE=E6=8E=A5=EF=BC=8C=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configure | 9 +++++++++ contrib/hdfs_fdw/hdfs_fdw.cpp | 2 ++ src/Makefile.global.in | 9 ++++++++- src/common/port/gs_thread.cpp | 2 ++ src/gausskernel/process/postmaster/postmaster.cpp | 4 ++++ src/gausskernel/process/stream/streamMain.cpp | 2 ++ src/gausskernel/process/tcop/postgres.cpp | 2 ++ src/gausskernel/runtime/Makefile | 6 +++++- src/gausskernel/runtime/codegen/gscodegen.cpp | 1 + src/gausskernel/runtime/executor/execMain.cpp | 6 ++++++ src/gausskernel/runtime/vecexecutor/vecnode/vecagg.cpp | 2 ++ .../runtime/vecexecutor/vecnode/veccstore.cpp | 4 ++++ .../runtime/vecexecutor/vecnode/veccstoreindexscan.cpp | 2 ++ src/gausskernel/runtime/vecexecutor/vecnode/vecgroup.cpp | 2 ++ .../runtime/vecexecutor/vecnode/vechashjoin.cpp | 6 ++++++ .../runtime/vecexecutor/vecnode/vecmergejoin.cpp | 2 ++ .../runtime/vecexecutor/vecnode/vecnestloop.cpp | 2 ++ src/gausskernel/runtime/vecexecutor/vecnode/vecsort.cpp | 2 ++ src/gausskernel/storage/access/dfs/dfs_query_reader.cpp | 3 ++- src/gausskernel/storage/access/transam/xact.cpp | 4 ++++ src/include/codegen/gscodegen.h | 7 ++++++- src/include/codegen/vecexprcodegen.h | 2 ++ src/include/codegen/vechashaggcodegen.h | 2 ++ src/include/codegen/vechashjoincodegen.h | 2 ++ src/include/codegen/vecsortcodegen.h | 2 ++ src/include/utils/dfs_vector.h | 2 ++ 26 files changed, 85 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 422997f4d..fe1c27c4f 100755 --- a/configure +++ b/configure @@ -2869,6 +2869,14 @@ if test "${enable_mot+set}" = set; then $as_echo "$as_me: error: --enable-mot option is not supported with --enable-multiple-nodes option" >&2;} { (exit 1); exit 1; }; } + fi + + if test "$enable_llvm" = no; then + + { { $as_echo "$as_me:$LINENO: error: --enable-mot option is not supported with --disable-llvm option" >&5 + $as_echo "$as_me: error: --enable-mot option is not supported with --disable-llvm option" >&2;} + { (exit 1); exit 1; }; } + fi ;; no) @@ -5774,6 +5782,7 @@ else cat >>confdefs.h <<\_ACEOF #define ENABLE_LLVM_COMPILE 1 _ACEOF +enable_llvm=yes fi diff --git a/contrib/hdfs_fdw/hdfs_fdw.cpp b/contrib/hdfs_fdw/hdfs_fdw.cpp index 59fcb7dc1..0ab4b8af4 100755 --- a/contrib/hdfs_fdw/hdfs_fdw.cpp +++ b/contrib/hdfs_fdw/hdfs_fdw.cpp @@ -1434,6 +1434,7 @@ static void HdfsEndForeignScan(ForeignScanState* scanState) } } +#ifdef ENABLE_LLVM_COMPILE /* * LLVM optimization information should be shown. We check the query * uses LLVM optimization or not. @@ -1502,6 +1503,7 @@ static void HdfsEndForeignScan(ForeignScanState* scanState) } } } +#endif /* clears all file related memory */ if (NULL != executionState->fileReader) { diff --git a/src/Makefile.global.in b/src/Makefile.global.in index fcdc631ae..a25fb4078 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -173,6 +173,7 @@ enable_jemalloc_debug = @enable_jemalloc_debug@ enable_privategauss = @enable_privategauss@ enable_multiple_nodes = @enable_multiple_nodes@ enable_mot = @enable_mot@ +enable_llvm = @enable_llvm@ enable_mysql_fdw = @enable_mysql_fdw@ enable_oracle_fdw = @enable_oracle_fdw@ enable_pldebugger = @enable_pldebugger@ @@ -506,7 +507,9 @@ LIBLLVM_BIN = $(LIBLLVM_HOME)/bin LIBLLVM_INCLUDE_PATH = $(LIBLLVM_HOME)/include LIBLLVM_LIB_PATH = $(LIBLLVM_HOME)/lib LLVM_CONFIG = $(LIBLLVM_BIN)/llvm-config -LLVM_LIBS = $(shell $(LLVM_CONFIG) --libs) +ifeq ($(enable_llvm), yes) + LLVM_LIBS = $(shell $(LLVM_CONFIG) --libs) +endif ############################################################################# # event component @@ -753,6 +756,10 @@ ifeq ($(enable_mot), yes) override CPPFLAGS := $(CPPFLAGS) -I$(MASSTREE_INCLUDE_PATH) endif +ifeq ($(enable_llvm), yes) + override CPPFLAGS := $(CPPFLAGS) -DENABLE_LLVM_COMPILE +endif + CC = @CC@ GCC = @GCC@ C = gcc diff --git a/src/common/port/gs_thread.cpp b/src/common/port/gs_thread.cpp index 8957053f1..3deb6ce78 100644 --- a/src/common/port/gs_thread.cpp +++ b/src/common/port/gs_thread.cpp @@ -471,8 +471,10 @@ void gs_thread_exit(int code) /* free the locale cache */ freeLocaleCache(true); +#ifdef ENABLE_LLVM_COMPILE /* release llvm context memory */ CodeGenThreadTearDown(); +#endif CancelAutoAnalyze(); diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 28026179c..36db1f4e6 100755 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -1049,10 +1049,12 @@ int PostmasterMain(int argc, char* argv[]) cJSON_Hooks hooks = {cJSON_internal_malloc, cJSON_internal_free}; cJSON_InitHooks(&hooks); +#ifdef ENABLE_LLVM_COMPILE /* * Prepare codegen enviroment. */ CodeGenProcessInitialize(); +#endif /* Initialize paths to installation files */ getInstallationPaths(argv[0]); @@ -7070,7 +7072,9 @@ void ExitPostmaster(int status) TermMOT(); /* shutdown memory engine before codegen is destroyed */ #endif +#ifdef ENABLE_LLVM_COMPILE CodeGenProcessTearDown(); +#endif /* Save llt data to disk before postmaster exit */ #ifdef ENABLE_LLT diff --git a/src/gausskernel/process/stream/streamMain.cpp b/src/gausskernel/process/stream/streamMain.cpp index 85bd8247d..3fb8decdf 100644 --- a/src/gausskernel/process/stream/streamMain.cpp +++ b/src/gausskernel/process/stream/streamMain.cpp @@ -103,7 +103,9 @@ int StreamMain() MemoryContext oldMemory = MemoryContextSwitchTo( THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR)); +#ifdef ENABLE_LLVM_COMPILE CodeGenThreadInitialize(); +#endif (void)MemoryContextSwitchTo(oldMemory); /* We can now handle ereport(ERROR) */ diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index 409b09555..afe5fbf13 100644 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -7791,7 +7791,9 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam u_sess->attr.attr_sql.explain_allow_multinode = false; MemoryContext oldMemory = MemoryContextSwitchTo(THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR)); +#ifdef ENABLE_LLVM_COMPILE CodeGenThreadInitialize(); +#endif (void)MemoryContextSwitchTo(oldMemory); u_sess->exec_cxt.single_shard_stmt = false; /* Set statement_timestamp */ diff --git a/src/gausskernel/runtime/Makefile b/src/gausskernel/runtime/Makefile index cf5123621..53843ed4b 100644 --- a/src/gausskernel/runtime/Makefile +++ b/src/gausskernel/runtime/Makefile @@ -8,6 +8,10 @@ subdir = src/gausskernel/runtime top_builddir = ../../.. include $(top_builddir)/src/Makefile.global -SUBDIRS = codegen executor vecexecutor +SUBDIRS = executor vecexecutor + +ifeq ($(enable_llvm), yes) +SUBDIRS += codegen +endif include $(top_srcdir)/src/gausskernel/common.mk diff --git a/src/gausskernel/runtime/codegen/gscodegen.cpp b/src/gausskernel/runtime/codegen/gscodegen.cpp index 93230079d..a18f0e2a5 100644 --- a/src/gausskernel/runtime/codegen/gscodegen.cpp +++ b/src/gausskernel/runtime/codegen/gscodegen.cpp @@ -940,6 +940,7 @@ void CodeGenProcessInitialize() } } + /** * @Description : Clean up LLVM enviroment resource * before exit postmaster. diff --git a/src/gausskernel/runtime/executor/execMain.cpp b/src/gausskernel/runtime/executor/execMain.cpp index ad2422ea9..622ee9832 100644 --- a/src/gausskernel/runtime/executor/execMain.cpp +++ b/src/gausskernel/runtime/executor/execMain.cpp @@ -307,8 +307,10 @@ void standard_ExecutorStart(QueryDesc *queryDesc, int eflags) old_context = MemoryContextSwitchTo(estate->es_query_cxt); +#ifdef ENABLE_LLVM_COMPILE /* Initialize the actual CodeGenObj */ CodeGenThreadRuntimeSetup(); +#endif /* * Fill in external parameters, if any, from queryDesc; and allocate @@ -550,6 +552,7 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co */ old_context = MemoryContextSwitchTo(estate->es_query_cxt); +#ifdef ENABLE_LLVM_COMPILE /* * Generate machine code for this query. */ @@ -562,6 +565,7 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co CodeGenThreadRuntimeCodeGenerate(); } } +#endif /* Allow instrumentation of Executor overall runtime */ if (queryDesc->totaltime) { @@ -772,9 +776,11 @@ void standard_ExecutorEnd(QueryDesc *queryDesc) UnregisterSnapshot(estate->es_snapshot); UnregisterSnapshot(estate->es_crosscheck_snapshot); +#ifdef ENABLE_LLVM_COMPILE if (!t_thrd.codegen_cxt.g_runningInFmgr) { CodeGenThreadTearDown(); } +#endif /* * Must switch out of context before destroying it diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vecagg.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vecagg.cpp index a27ab2020..b8c528fe0 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vecagg.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vecagg.cpp @@ -727,6 +727,7 @@ VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags) aggstate->numaggs = aggno + 1; aggstate->aggRun = NULL; +#ifdef ENABLE_LLVM_COMPILE /* * Generate IR function for HashAggRunner::BuildAggTbl function, which * contains hashing part, allocate hashcell and agg part @@ -741,6 +742,7 @@ VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags) dorado::VecHashAggCodeGen::HashAggCodeGen(aggstate); } } +#endif return aggstate; } diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/veccstore.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/veccstore.cpp index ee10163b7..f403bce62 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/veccstore.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/veccstore.cpp @@ -677,6 +677,7 @@ CStoreScanState* ExecInitCStoreScan( InitCStoreRelation(scan_stat, estate, idx_flag, parent_heap_rel); scan_stat->ps.ps_TupFromTlist = false; +#ifdef ENABLE_LLVM_COMPILE /* * First, not only consider the LLVM native object, but also consider the cost of * the LLVM compilation time. We will not use LLVM optimization if there is @@ -702,6 +703,7 @@ CStoreScanState* ExecInitCStoreScan( llvm_code_gen->addFunctionToMCJit(jitted_vecqual, reinterpret_cast(&(scan_stat->jitted_vecqual))); } } +#endif /* * Initialize result tuple type and projection info. @@ -758,6 +760,7 @@ CStoreScanState* ExecInitCStoreScan( scan_stat->m_pScanBatch->CreateSysColContainer(CurrentMemoryContext, plan_stat->ps_ProjInfo->pi_sysAttrList); } +#ifdef ENABLE_LLVM_COMPILE /** * Since we separate the target list elements into simple var references and * generic expression, we only need to deal the generic expression with LLVM @@ -776,6 +779,7 @@ CStoreScanState* ExecInitCStoreScan( llvm_code_gen->addFunctionToMCJit( jitted_vectarget, reinterpret_cast(&(plan_stat->ps_ProjInfo->jitted_vectarget))); } +#endif scan_stat->m_pScanRunTimeKeys = NULL; scan_stat->m_ScanRunTimeKeysNum = 0; diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/veccstoreindexscan.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/veccstoreindexscan.cpp index 8aeccda95..f93363e18 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/veccstoreindexscan.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/veccstoreindexscan.cpp @@ -295,6 +295,7 @@ CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* est rc = memcpy_s(indexstate, sizeof(CStoreScanState), scanstate, sizeof(CStoreScanState)); securec_check(rc, "\0", "\0"); +#ifdef ENABLE_LLVM_COMPILE /* * First, not only consider the LLVM native object, but also consider the cost of * the LLVM compilation time. We will not use LLVM optimization if there is @@ -315,6 +316,7 @@ CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* est if (jitted_vecqual != NULL) llvmCodeGen->addFunctionToMCJit(jitted_vecqual, reinterpret_cast(&(indexstate->jitted_vecqual))); } +#endif indexstate->ps.plan = (Plan*)node; indexstate->ps.state = estate; diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vecgroup.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vecgroup.cpp index 7840a8248..3ab93bfdc 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vecgroup.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vecgroup.cpp @@ -170,6 +170,7 @@ VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags) grp_state->ss.ps.targetlist = (List*)ExecInitVecExpr((Expr*)node->plan.targetlist, (PlanState*)grp_state); grp_state->ss.ps.qual = (List*)ExecInitVecExpr((Expr*)node->plan.qual, (PlanState*)grp_state); +#ifdef ENABLE_LLVM_COMPILE /* * Check if nlstate->js.joinqual and nlstate->js.ps.qual expr list could be * codegened or not. @@ -184,6 +185,7 @@ VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags) if (grp_vecqual != NULL) llvm_code_gen->addFunctionToMCJit(grp_vecqual, reinterpret_cast(&(grp_state->jitted_vecqual))); } +#endif // initialize child nodes outerPlanState(grp_state) = ExecInitNode(outerPlan(node), estate, eflags); diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vechashjoin.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vechashjoin.cpp index 673175773..eec044be0 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vechashjoin.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vechashjoin.cpp @@ -128,10 +128,12 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl * Since most of the expression information will be used * later, we still need to initialize these expression. */ +#ifdef ENABLE_LLVM_COMPILE dorado::GsCodeGen* llvmCodeGen = (dorado::GsCodeGen*)t_thrd.codegen_cxt.thr_codegen_obj; bool consider_codegen = CodeGenThreadObjectReady() && CodeGenPassThreshold(((Plan*)outer_node)->plan_rows, estate->es_plannedstmt->num_nodes, ((Plan*)outer_node)->dop); +#endif if (hash_state->js.ps.targetlist) { hash_state->js.ps.ps_ProjInfo = ExecBuildVecProjectionInfo(hash_state->js.ps.targetlist, @@ -140,6 +142,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl hash_state->js.ps.ps_ResultTupleSlot, NULL); +#ifdef ENABLE_LLVM_COMPILE bool saved_codegen = consider_codegen; if (isIntergratedMachine) { consider_codegen = @@ -169,6 +172,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl } consider_codegen = saved_codegen; +#endif ExecAssignVectorForExprEval(hash_state->js.ps.ps_ProjInfo->pi_exprContext); } else { @@ -210,6 +214,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl hash_state->eqfunctions = eqfunctions; hash_state->js.ps.ps_TupFromTlist = false; +#ifdef ENABLE_LLVM_COMPILE /* Initialize runtime bloomfilter. */ hash_state->bf_runtime.bf_var_list = hash_state->js.ps.plan->var_list; hash_state->bf_runtime.bf_filter_index = hash_state->js.ps.plan->filterIndexList; @@ -221,6 +226,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl if (consider_codegen && !node->isSonicHash) { dorado::VecHashJoinCodeGen::HashJoinCodeGen(hash_state); } +#endif return hash_state; } diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vecmergejoin.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vecmergejoin.cpp index f7b2e2034..577652bf6 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vecmergejoin.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vecmergejoin.cpp @@ -1899,6 +1899,7 @@ VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int node->mergeNullsFirst, (PlanState*)mergestate); +#ifdef ENABLE_LLVM_COMPILE /* * After all of the expressions have been decided, check if the following * exprs can be codegened or not. @@ -1922,6 +1923,7 @@ VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int jitted_vectarget, reinterpret_cast(&(mergestate->js.ps.ps_ProjInfo->jitted_vectarget))); } } +#endif for (i = 0; i < mergestate->mj_NumClauses; i++) { VecMergeJoinClause clause = &mergestate->mj_Clauses[i]; diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vecnestloop.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vecnestloop.cpp index 36fecee27..bdb781019 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vecnestloop.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vecnestloop.cpp @@ -473,6 +473,7 @@ VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int efl nlstate->js.joinqual = (List*)ExecInitVecExpr((Expr*)node->join.joinqual, (PlanState*)nlstate); Assert(node->join.nulleqqual == NIL); +#ifdef ENABLE_LLVM_COMPILE /* * Check if nlstate->js.joinqual and nlstate->js.ps.qual expr list could be * codegened or not. @@ -492,6 +493,7 @@ VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int efl if (nl_joinqual != NULL) llvm_code_gen->addFunctionToMCJit(nl_joinqual, reinterpret_cast(&(nlstate->jitted_joinqual))); } +#endif /* * initialize child nodes diff --git a/src/gausskernel/runtime/vecexecutor/vecnode/vecsort.cpp b/src/gausskernel/runtime/vecexecutor/vecnode/vecsort.cpp index 79a4fc55e..cfba6c3f0 100644 --- a/src/gausskernel/runtime/vecexecutor/vecnode/vecsort.cpp +++ b/src/gausskernel/runtime/vecexecutor/vecnode/vecsort.cpp @@ -331,6 +331,7 @@ VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags) SO1_printf("ExecInitVecSort: %s\n", "sort node initialized"); +#ifdef ENABLE_LLVM_COMPILE /* * Consider codegeneration for sort node. In fact, CompareMultiColumn is the * hotest function in sort node. @@ -363,6 +364,7 @@ VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags) } } } +#endif return sort_stat; } diff --git a/src/gausskernel/storage/access/dfs/dfs_query_reader.cpp b/src/gausskernel/storage/access/dfs/dfs_query_reader.cpp index 4ef509f5f..9f8df6979 100644 --- a/src/gausskernel/storage/access/dfs/dfs_query_reader.cpp +++ b/src/gausskernel/storage/access/dfs/dfs_query_reader.cpp @@ -141,11 +141,12 @@ bool HdfsScanPredicate::BuildHdfsScanPredicateFromClause(Expr *expr return runningTimeSet; } +#ifdef ENABLE_LLVM_COMPILE /* Build IR according to expr node. */ if (CodeGenThreadObjectReady()) { (void)ForeignScanExprCodeGen(expr, NULL, &m_jittedFunc); } - +#endif if (IsA(rightop, Const)) { datumValue = ((Const *)rightop)->constvalue; datumType = ((Const *)rightop)->consttype; diff --git a/src/gausskernel/storage/access/transam/xact.cpp b/src/gausskernel/storage/access/transam/xact.cpp index 62d309122..0f11a05d8 100644 --- a/src/gausskernel/storage/access/transam/xact.cpp +++ b/src/gausskernel/storage/access/transam/xact.cpp @@ -3816,6 +3816,7 @@ static void AbortTransaction(bool PerfectRollback, bool STP_rollback) } } +#ifdef ENABLE_LLVM_COMPILE /* * @llvm * when the query is abnormal exited, the (GsCodeGen *)t_thrd.codegen_cxt.thr_codegen_obj->codeGenState @@ -3824,6 +3825,7 @@ static void AbortTransaction(bool PerfectRollback, bool STP_rollback) * function. */ CodeGenThreadTearDown(); +#endif CancelAutoAnalyze(); lightProxy::setCurrentProxy(NULL); @@ -6438,8 +6440,10 @@ void AbortSubTransaction(bool STP_rollback) delete_ec_ctrl(); #endif +#ifdef ENABLE_LLVM_COMPILE /* reset machine code */ CodeGenThreadReset(); +#endif /* Reset the compatible illegal chars import flag */ u_sess->mb_cxt.insertValuesBind_compatible_illegal_chars = false; diff --git a/src/include/codegen/gscodegen.h b/src/include/codegen/gscodegen.h index 1f1ec971a..b1d2a2d04 100644 --- a/src/include/codegen/gscodegen.h +++ b/src/include/codegen/gscodegen.h @@ -32,7 +32,7 @@ #ifndef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS #endif - +#ifdef ENABLE_LLVM_COMPILE #include "llvm/IR/Verifier.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/ObjectCache.h" @@ -53,6 +53,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_os_ostream.h" +#endif #undef __STDC_LIMIT_MACROS #include "c.h" @@ -155,6 +156,7 @@ const int llvm_smul_with_overflow = 236; const int llvm_ssub_with_overflow = 241; +#ifdef ENABLE_LLVM_COMPILE /* * Declare related LLVM classes to avoid namespace pollution. */ @@ -181,6 +183,7 @@ class IRBuilder; class IRBuilderDefaultInserter; } // namespace llvm +#endif namespace dorado { @@ -196,6 +199,7 @@ bool canInitCodegenInvironment(); */ bool canInitThreadCodeGen(); +#ifdef ENABLE_LLVM_COMPILE class GsCodeGen : public BaseObject { public: void initialize(); @@ -583,6 +587,7 @@ private: /* Records the c-function calls in codegen IR fucntion of expression tree */ List* m_cfunction_calls; }; +#endif /* * Macros used to define the variables diff --git a/src/include/codegen/vecexprcodegen.h b/src/include/codegen/vecexprcodegen.h index 1994f6896..b0ddfac6a 100644 --- a/src/include/codegen/vecexprcodegen.h +++ b/src/include/codegen/vecexprcodegen.h @@ -33,6 +33,7 @@ #include "codegen/gscodegen.h" namespace dorado { +#ifdef ENABLE_LLVM_COMPILE /* * @Description : Arguments used for Vectorized Expression CodeGen Engine. */ @@ -464,5 +465,6 @@ public: */ static llvm::Value* MemCxtSwitToCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* context); }; +#endif } // namespace dorado #endif diff --git a/src/include/codegen/vechashaggcodegen.h b/src/include/codegen/vechashaggcodegen.h index 00c1ff191..42dc84f2f 100644 --- a/src/include/codegen/vechashaggcodegen.h +++ b/src/include/codegen/vechashaggcodegen.h @@ -36,6 +36,7 @@ namespace dorado { /* * VecHashAggCodeGen class implements specific optimization by using LLVM */ +#ifdef ENABLE_LLVM_COMPILE class VecHashAggCodeGen : public BaseObject { public: /* @@ -225,6 +226,7 @@ public: */ static void WrapResetEContextCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext); }; +#endif } // namespace dorado #endif diff --git a/src/include/codegen/vechashjoincodegen.h b/src/include/codegen/vechashjoincodegen.h index a30836724..01597ee2a 100644 --- a/src/include/codegen/vechashjoincodegen.h +++ b/src/include/codegen/vechashjoincodegen.h @@ -38,6 +38,7 @@ namespace dorado { /* * VecHashJoinCodeGen class implements specific optimization by using LLVM */ +#ifdef ENABLE_LLVM_COMPILE class VecHashJoinCodeGen : public BaseObject { public: /* @@ -168,5 +169,6 @@ public: */ static llvm::Function* HashJoinCodeGen_bf_includeLong(VecHashJoinState* node); }; +#endif } // namespace dorado #endif diff --git a/src/include/codegen/vecsortcodegen.h b/src/include/codegen/vecsortcodegen.h index 55197c804..3e1c2e3bb 100644 --- a/src/include/codegen/vecsortcodegen.h +++ b/src/include/codegen/vecsortcodegen.h @@ -39,6 +39,7 @@ namespace dorado { /* * VecSortCodeGen class implements specific optimization by using LLVM */ +#ifdef ENABLE_LLVM_COMPILE class VecSortCodeGen : public BaseObject { public: /* @@ -151,5 +152,6 @@ public: */ static llvm::Function* SortAggTexteqCodeGen(); }; +#endif } // namespace dorado #endif diff --git a/src/include/utils/dfs_vector.h b/src/include/utils/dfs_vector.h index 521be14a3..484a237c1 100644 --- a/src/include/utils/dfs_vector.h +++ b/src/include/utils/dfs_vector.h @@ -30,6 +30,8 @@ #include "securec.h" #include "securec_check.h" +#include + /* stands for non-int type */ struct __type_true {}; From 163b12b762c98d1e56e6295196392b3acb77c870 Mon Sep 17 00:00:00 2001 From: ZigSmith Date: Mon, 31 May 2021 17:09:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0GUC=E5=8F=82=E6=95=B0wal?= =?UTF-8?q?=5Finsert=5Fstatus=5Fentries=E7=94=A8=E4=BA=8E=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEWal=E6=8F=92=E5=85=A5=E7=8A=B6=E6=80=81=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/utils/misc/guc.cpp | 14 +++++++++++++ .../storage/access/transam/xlog.cpp | 21 +++++++++++++++++++ src/include/access/xlog.h | 2 +- .../knl/knl_guc/knl_instance_attr_storage.h | 1 + src/include/utils/guc.h | 1 + 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 4a3289cb0..37bbc4773 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -542,6 +542,7 @@ vacuum_defer_cleanup_age|int64|0,1000000|NULL|NULL| vacuum_freeze_min_age|int64|0,576460752303423487|NULL|NULL| vacuum_freeze_table_age|int64|0,576460752303423487|NULL|NULL| hll_default_expthresh|int64|-1,7|NULL|NULL| +wal_insert_status_entries|int|131072,4194304|NULL|Sets the size of wal insert status array for WAL.| wal_buffers|int|-1,262144|kB|Every time a transaction is committed, the contents of WAL buffers are written to disk, it is set to a large value will not bring significant performance gains. If you set it to hundreds of megabytes, you may have written to the disk to improve performance on the server a lot of real-time transaction commits. According to experience, the default value is sufficient for most situations.| wal_keep_segments|int|2,2147483647|NULL| When the server is turned on or archive log recovery from the checkpoint, the number of reserved log files may be larger than the set value wal_keep_segments. If this parameter is set too low, at the time of the transaction log backup requests, the new transaction log may have been produced coverage request fails, disconnect the master and slave relationship.| wal_level|enum|minimal,archive,hot_standby,logical|NULL|If you need to copy the data stream for WAL log archiving and standby machine. You must be set to the parameter with archive or hot_standby. If this parameter is setted to archive. The hot_standby must be setted to off, otherwise it will cause the database can not be started, at the same time the max_wal_senders must be set at least 1.| diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 29d1a1278..45d7372c2 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -4960,6 +4960,20 @@ static void InitConfigureNamesInt() NULL, NULL}, + {{"wal_insert_status_entries", + PGC_POSTMASTER, + WAL_SETTINGS, + gettext_noop("Sets the size of wal insert status array for WAL."), + NULL, + }, + &g_instance.attr.attr_storage.wal_insert_status_entries, + 4194304, + 131072, + 4194304, + check_wal_insert_status_entries, + NULL, + NULL}, + {{"wal_writer_delay", PGC_SIGHUP, WAL_SETTINGS, diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 0be00740f..cc687137d 100644 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -6648,6 +6648,27 @@ bool check_wal_buffers(int *newval, void **extra, GucSource source) return true; } +/* + * GUC check_hook for wal_insert_status_entries + */ +bool check_wal_insert_status_entries(int *newval, void **extra, GucSource source) +{ + // if newval not power of 2 + if (!((*newval != 0) && ((*newval & (*newval - 1)) == 0))) { + // get next Power Of 2 form newval + unsigned count = 0; + unsigned n = *newval; + while( n != 0) + { + n >>= 1; + count += 1; + } + *newval = 1 << count; + } + + return true; +} + /* * Initialization of shared memory for XLOG */ diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 845f691bb..2e12caa05 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -151,7 +151,7 @@ typedef struct { PGSemaphoreData sem; } WALBufferInitWaitLock; -#define WAL_INSERT_STATUS_ENTRIES 4194304 +#define WAL_INSERT_STATUS_ENTRIES g_instance.attr.attr_storage.wal_insert_status_entries #define WAL_NOT_COPIED 0 #define WAL_COPIED 1 #define WAL_COPY_SUSPEND (-1) diff --git a/src/include/knl/knl_guc/knl_instance_attr_storage.h b/src/include/knl/knl_guc/knl_instance_attr_storage.h index f82f8c566..292c3dad8 100644 --- a/src/include/knl/knl_guc/knl_instance_attr_storage.h +++ b/src/include/knl/knl_guc/knl_instance_attr_storage.h @@ -66,6 +66,7 @@ typedef struct knl_instance_attr_storage { int wal_writer_cpu; int wal_file_init_num; int XLOGbuffers; + int wal_insert_status_entries; int max_wal_senders; int max_replication_slots; int replication_type; diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index e34701bc6..38bab81d4 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -316,6 +316,7 @@ extern bool check_asp_flush_mode(char** newval, void** extra, GucSource source); /* in access/transam/xlog.c */ extern bool check_wal_buffers(int* newval, void** extra, GucSource source); +extern bool check_wal_insert_status_entries(int* newval, void** extra, GucSource source); extern void assign_xlog_sync_method(int new_sync_method, void* extra); /* in tcop/stmt_retry.cpp */ From 940b0dbf3ef31860acf568dac28d685c212dd10b Mon Sep 17 00:00:00 2001 From: ZigSmith Date: Thu, 10 Jun 2021 11:10:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0guc=E5=8F=82=E6=95=B0num?= =?UTF-8?q?=5Finternal=5Flock=5Fpartitions,=20=E8=BF=9B=E8=A1=8C=E9=94=81?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/utils/misc/guc.cpp | 41 ++++++ src/gausskernel/bootstrap/bootstrap.cpp | 5 +- .../instruments/statement/instr_statement.cpp | 18 --- src/gausskernel/optimizer/commands/async.cpp | 2 +- src/gausskernel/optimizer/commands/copy.cpp | 19 +++ .../process/postmaster/postmaster.cpp | 2 + src/gausskernel/process/tcop/postgres.cpp | 1 + .../process/threadpool/knl_thread.cpp | 4 +- .../storage/access/transam/clog.cpp | 4 +- .../storage/access/transam/csnlog.cpp | 2 +- .../storage/access/transam/multixact.cpp | 4 +- .../storage/access/transam/slru.cpp | 3 +- src/gausskernel/storage/lmgr/lwlock.cpp | 121 +++++++++++++++++- src/gausskernel/storage/lmgr/predicate.cpp | 2 +- src/gausskernel/storage/lmgr/proc.cpp | 12 +- src/include/access/slru.h | 2 +- src/include/commands/copy.h | 1 + .../knl/knl_guc/knl_instance_attr_storage.h | 11 ++ src/include/storage/lock/lwlock.h | 120 +++++++++++------ src/include/storage/proc.h | 14 +- src/include/utils/guc.h | 1 + 22 files changed, 306 insertions(+), 84 deletions(-) diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 37bbc4773..bf17fac60 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -481,6 +481,7 @@ standard_conforming_strings|bool|0,0|NULL|NULL| standby_shared_buffers_fraction|real|0.1,1|NULL|NULL| statement_timeout|int|0,2147483647|ms|NULL| stats_temp_directory|string|0,0|NULL|NULL| +num_internal_lock_partitions|string|0,0|NULL|NULL| stream_multiple|real|0,1.79769e+308|NULL|NULL| string_hash_compatible|bool|0,0|NULL|NULL| enable_slow_query_log|bool|0,0|NULL|NULL| diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 45d7372c2..5e3e106cf 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -43,6 +43,7 @@ #include "catalog/pgxc_group.h" #include "catalog/storage_gtt.h" #include "commands/async.h" +#include "commands/copy.h" #include "commands/prepare.h" #include "commands/vacuum.h" #include "commands/variable.h" @@ -8554,6 +8555,19 @@ static void InitConfigureNamesString() check_inplace_upgrade_next_oids, NULL, NULL}, + + {{"num_internal_lock_partitions", + PGC_POSTMASTER, + LOCK_MANAGEMENT, + gettext_noop("num of csnlog clog and locktable lwlock partitions."), + NULL, + GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY}, + &g_instance.attr.attr_storage.num_internal_lock_partitions_str, + "CLOG_PART=256,CSNLOG_PART=512,LOG2_LOCKTABLE_PART=4,TWOPHASE_PART=1", + NULL, + NULL, + NULL}, + /* analysis options for dfx */ {{"analysis_options", PGC_USERSET, @@ -19870,4 +19884,31 @@ bool check_numa_distribute_mode(char** newval, void** extra, GucSource source) return false; } +/* Initialize storage critical lwlock partition num */ +void InitializeNumLwLockPartitions(void) +{ + /* set default values */ + SetLWLockPartDefaultNum(); + /* Do str copy and remove space. */ + char* attr = TrimStr(g_instance.attr.attr_storage.num_internal_lock_partitions_str); + if (attr == NULL || attr[0] == '\0') { /* use default values */ + return; + } + const char* pdelimiter = ","; + List *res = NULL; + char* nextToken = NULL; + char* token = strtok_s(attr, pdelimiter, &nextToken); + while (token != NULL) { + res = lappend(res, TrimStr(token)); + token = strtok_s(NULL, pdelimiter, &nextToken); + } + pfree(attr); + /* check input string and set lwlock num */ + CheckAndSetLWLockPartInfo(res); + /* check range */ + CheckLWLockPartNumRange(); + + list_free_deep(res); +} + #include "guc-file.inc" diff --git a/src/gausskernel/bootstrap/bootstrap.cpp b/src/gausskernel/bootstrap/bootstrap.cpp index fc4fa394f..844de53c5 100644 --- a/src/gausskernel/bootstrap/bootstrap.cpp +++ b/src/gausskernel/bootstrap/bootstrap.cpp @@ -300,8 +300,11 @@ void BootStrapProcessMain(int argc, char* argv[]) /* Acquire configuration parameters, unless inherited from postmaster */ if (!IsUnderPostmaster) { - if (!SelectConfigFiles(userDoption, progName)) + if (!SelectConfigFiles(userDoption, progName)) { proc_exit(1); + } + + InitializeNumLwLockPartitions(); } /* Validate we have been given a reasonable-looking t_thrd.proc_cxt.DataDir */ diff --git a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp index 58462c159..7c6d6707b 100644 --- a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp +++ b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp @@ -384,24 +384,6 @@ static RangeVar* InitStatementRel() return relrv; } -static bool StrToInt32(const char* s, int *val) -{ - int base = 10; - const char* ptr = s; - /* process digits */ - while (*ptr != '\0') { - if (isdigit((unsigned char)*ptr) == 0) - return false; - int8 digit = (*ptr++ - '0'); - *val = *val * base + digit; - if (*val > PG_INT32_MAX || *val < PG_INT32_MIN) { - return false; - } - } - return true; -} - - bool check_statement_retention_time(char** newval, void** extra, GucSource source) { /* Do str copy and remove space. */ diff --git a/src/gausskernel/optimizer/commands/async.cpp b/src/gausskernel/optimizer/commands/async.cpp index 2fbbab5ca..67e938e77 100644 --- a/src/gausskernel/optimizer/commands/async.cpp +++ b/src/gausskernel/optimizer/commands/async.cpp @@ -1781,7 +1781,7 @@ static void asyncQueueAdvanceTail(void) * SimpleLruTruncate() will ask for AsyncCtlLock but will also release * the lock again. */ - SimpleLruTruncate(AsyncCtl, newtailpage, false, NUM_SLRU_DEFAULT_PARTITION); + SimpleLruTruncate(AsyncCtl, newtailpage, NUM_SLRU_DEFAULT_PARTITION); } } diff --git a/src/gausskernel/optimizer/commands/copy.cpp b/src/gausskernel/optimizer/commands/copy.cpp index a30b0fbde..f60841dcf 100644 --- a/src/gausskernel/optimizer/commands/copy.cpp +++ b/src/gausskernel/optimizer/commands/copy.cpp @@ -7491,6 +7491,25 @@ char* scan_dir(DIR* dir, const char* dirpath, const char* pattern, long* filesiz return NULL; } +bool StrToInt32(const char* s, int *val) +{ + /* set val to zero */ + *val = 0; + int base = 10; + const char* ptr = s; + /* process digits */ + while (*ptr != '\0') { + if (isdigit((unsigned char)*ptr) == 0) + return false; + int8 digit = (*ptr++ - '0'); + *val = *val * base + digit; + if (*val > PG_INT32_MAX || *val < PG_INT32_MIN) { + return false; + } + } + return true; +} + char* TrimStr(const char* str) { if (str == NULL) { diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 36db1f4e6..1367e7e6d 100755 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -1388,6 +1388,8 @@ int PostmasterMain(int argc, char* argv[]) ExitPostmaster(0); } + InitializeNumLwLockPartitions(); + noProcLogicTid = GLOBAL_ALL_PROCS; /* Run as FencedUDF master */ diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index afe5fbf13..68259f312 100644 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -6929,6 +6929,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam gstrace_exit(GS_TRC_ID_PostgresMain); proc_exit(1); } + InitializeNumLwLockPartitions(); } /* initialize guc variables which need to be sended to stream threads */ diff --git a/src/gausskernel/process/threadpool/knl_thread.cpp b/src/gausskernel/process/threadpool/knl_thread.cpp index 3405d333d..7cc764e2d 100644 --- a/src/gausskernel/process/threadpool/knl_thread.cpp +++ b/src/gausskernel/process/threadpool/knl_thread.cpp @@ -223,8 +223,8 @@ static void knl_t_shemem_ptr_init(knl_t_shemem_ptr_context* shemem_ptr_cxt) shemem_ptr_cxt->MultiXactState = NULL; shemem_ptr_cxt->OldestMemberMXactId = NULL; shemem_ptr_cxt->OldestVisibleMXactId = NULL; - shemem_ptr_cxt->ClogCtl = (SlruCtlData*)palloc0(NUM_CLOG_PARTITIONS * sizeof(SlruCtlData)); - shemem_ptr_cxt->CsnlogCtlPtr = (SlruCtlData*)palloc0(NUM_CSNLOG_PARTITIONS * sizeof(SlruCtlData)); + shemem_ptr_cxt->ClogCtl = (SlruCtlData*)palloc0(MAX_NUM_CLOG_PARTITIONS * sizeof(SlruCtlData)); + shemem_ptr_cxt->CsnlogCtlPtr = (SlruCtlData*)palloc0(MAX_NUM_CSNLOG_PARTITIONS * sizeof(SlruCtlData)); shemem_ptr_cxt->XLogCtl = NULL; shemem_ptr_cxt->GlobalWALInsertLocks = NULL; shemem_ptr_cxt->LocalGroupWALInsertLocks = NULL; diff --git a/src/gausskernel/storage/access/transam/clog.cpp b/src/gausskernel/storage/access/transam/clog.cpp index a2c62e8b8..4e31815f8 100644 --- a/src/gausskernel/storage/access/transam/clog.cpp +++ b/src/gausskernel/storage/access/transam/clog.cpp @@ -1050,7 +1050,7 @@ void TruncateCLOG(TransactionId oldestXact) WriteTruncateXlogRec(cutoffPage); /* Now we can remove the old CLOG segment(s) */ - SimpleLruTruncate(ClogCtl(0), cutoffPage, true, NUM_CLOG_PARTITIONS); + SimpleLruTruncate(ClogCtl(0), cutoffPage, NUM_CLOG_PARTITIONS); ereport(LOG, (errmsg("Truncate CLOG at xid %lu", oldestXact))); } @@ -1118,7 +1118,7 @@ void clog_redo(XLogReaderState *record) */ ClogCtl(pageno)->shared->latest_page_number = pageno; - SimpleLruTruncate(ClogCtl(0), pageno, true, NUM_CLOG_PARTITIONS); + SimpleLruTruncate(ClogCtl(0), pageno, NUM_CLOG_PARTITIONS); } else ereport(PANIC, (errmsg("clog_redo: unknown op code %u", (uint32)info))); } diff --git a/src/gausskernel/storage/access/transam/csnlog.cpp b/src/gausskernel/storage/access/transam/csnlog.cpp index 2d88c8d31..e2e0388f4 100644 --- a/src/gausskernel/storage/access/transam/csnlog.cpp +++ b/src/gausskernel/storage/access/transam/csnlog.cpp @@ -883,7 +883,7 @@ void TruncateCSNLOG(TransactionId oldestXact) */ cutoffPage = TransactionIdToCSNPage(oldestXact); - SimpleLruTruncate(CsnlogCtl(0), cutoffPage, true, NUM_CSNLOG_PARTITIONS); + SimpleLruTruncate(CsnlogCtl(0), cutoffPage, NUM_CSNLOG_PARTITIONS); elog(LOG, "truncate CSN log oldestXact %lu, next xid %lu", oldestXact, t_thrd.xact_cxt.ShmemVariableCache->nextXid); } diff --git a/src/gausskernel/storage/access/transam/multixact.cpp b/src/gausskernel/storage/access/transam/multixact.cpp index 06188df17..db85cda55 100644 --- a/src/gausskernel/storage/access/transam/multixact.cpp +++ b/src/gausskernel/storage/access/transam/multixact.cpp @@ -1738,14 +1738,14 @@ static void TruncateMultiXact(void) */ cutoffPage = (int)MultiXactIdToOffsetPage(oldestMXact); - SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactOffsetCtl, cutoffPage, false, NUM_SLRU_DEFAULT_PARTITION); + SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactOffsetCtl, cutoffPage, NUM_SLRU_DEFAULT_PARTITION); /* * Also truncate MultiXactMember at the previously determined offset. */ cutoffPage = (int)MXOffsetToMemberPage(oldestOffset); - SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactMemberCtl, cutoffPage, false, NUM_SLRU_DEFAULT_PARTITION); + SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactMemberCtl, cutoffPage, NUM_SLRU_DEFAULT_PARTITION); /* * Set the last known truncation point. We don't need a lock for this diff --git a/src/gausskernel/storage/access/transam/slru.cpp b/src/gausskernel/storage/access/transam/slru.cpp index f5a9b8cba..106d97646 100644 --- a/src/gausskernel/storage/access/transam/slru.cpp +++ b/src/gausskernel/storage/access/transam/slru.cpp @@ -1076,11 +1076,12 @@ int SimpleLruFlush(SlruCtl ctl, bool checkpoint) /* * Remove all segments before the one holding the passed page number */ -void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, bool isPart, int partitionNum) +void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, int partitionNum) { SlruShared shared = NULL; int64 slotno; bool isCsnLogCtl = strcmp(ctl->dir, "pg_csnlog") == 0; + bool isPart = (partitionNum > NUM_SLRU_DEFAULT_PARTITION); /* * The cutoff point is the start of the segment containing cutoffPage. diff --git a/src/gausskernel/storage/lmgr/lwlock.cpp b/src/gausskernel/storage/lmgr/lwlock.cpp index 827d9ae21..e9539ee94 100644 --- a/src/gausskernel/storage/lmgr/lwlock.cpp +++ b/src/gausskernel/storage/lmgr/lwlock.cpp @@ -76,6 +76,7 @@ #include "access/multixact.h" #include "access/subtrans.h" #include "commands/async.h" +#include "commands/copy.h" #include "lib/ilist.h" #include "miscadmin.h" #include "pg_trace.h" @@ -90,6 +91,7 @@ #include "storage/spin.h" #include "storage/cucache_mgr.h" #include "utils/atomic.h" +#include "utils/builtins.h" #include "instruments/instr_event.h" #include "instruments/instr_statement.h" #include "tsan_annotation.h" @@ -137,12 +139,17 @@ static const char *BuiltinTrancheNames[] = { "UniqueSQLMappingLock", "InstrUserLockId", "GPCMappingLock", - "GPCPrepareMappingLock", + "UspagrpMappingLock", + "ProcXactMappingLock", "ASPMappingLock", "GlobalSeqLock", + "GlobalWorkloadLock", "NormalizedSqlLock", + "StartBlockMappingLock", "BufferIOLock", "BufferContentLock", + "UndoPerZoneLock", + "UndoSpaceLock", "DataCacheLock", "MetaCacheLock", "PGPROCLock", @@ -169,7 +176,9 @@ static const char *BuiltinTrancheNames[] = { "IOStatLock", "WALFlushWait", "WALBufferInitWait", - "WALInitSegment" + "WALInitSegment", + "SegmentHeadPartitionLock", + "TwoPhaseStatePartLock" }; static void RegisterLWLockTranches(void); @@ -539,10 +548,6 @@ static void InitializeLWLocks(int numLocks) LWLockInitialize(&lock->lock, LWTRANCHE_GPC_MAPPING); } - for (id = 0; id < NUM_GPC_PARTITIONS; id++, lock++) { - LWLockInitialize(&lock->lock, LWTRANCHE_GPC_PREPARE_MAPPING); - } - for (id = 0; id < NUM_UNIQUE_SQL_PARTITIONS; id++, lock++) { LWLockInitialize(&lock->lock, LWTRANCHE_ASP_MAPPING); } @@ -551,6 +556,10 @@ static void InitializeLWLocks(int numLocks) LWLockInitialize(&lock->lock, LWTRANCHE_GlobalSeq); } + for (id = 0; id < NUM_GWC_PARTITIONS; id++, lock++) { + LWLockInitialize(&lock->lock, LWTRANCHE_GWC_MAPPING); + } + for (id = 0; id < NUM_NORMALIZED_SQL_PARTITIONS; id++, lock++) { LWLockInitialize(&lock->lock, LWTRANCHE_NORMALIZED_SQL); } @@ -567,6 +576,22 @@ static void InitializeLWLocks(int numLocks) LWLockInitialize(&lock->lock, LWTRANCHE_IO_STAT); } + for (id = 0; id < NUM_PROCXACT_PARTITIONS; id++, lock++) { + LWLockInitialize(&lock->lock, LWTRANCHE_PROC_XACT_MAPPING); + } + + for (id = 0; id < NUM_STARTBLOCK_PARTITIONS; id++, lock++) { + LWLockInitialize(&lock->lock, LWTRANCHE_START_BLOCK_MAPPING); + } + + for (id = 0; id < NUM_TWOPHASE_PARTITIONS; id++, lock++) { + LWLockInitialize(&lock->lock, LWTRANCHE_TWOPHASE_STATE); + } + + for (id = 0; id < NUM_SEGMENT_HEAD_PARTITIONS; id++, lock++) { + LWLockInitialize(&lock->lock, LWTRANCHE_SEGHEAD_PARTITION); + } + Assert((lock - t_thrd.shemem_ptr_cxt.mainLWLockArray) == NumFixedLWLocks); for (id = NumFixedLWLocks; id < numLocks; id++, lock++) { @@ -2035,3 +2060,87 @@ LWLockMode GetHeldLWLockMode(LWLock *lock) return (LWLockMode)0; /* keep compiler silence */ } + +static int FindLWLockPartIndex(const char* name) +{ + int i; + for (i = 0; i < LWLOCK_PART_KIND; i++) { + if (pg_strcasecmp(name, LWLockPartInfo[i].name) == 0) { + return i; + } + } + return -1; +} + +static bool CheckAndSetLWLockPartNum(const char* input) +{ + const int pairNum = 2; + /* Do str copy and remove space. */ + char* strs = TrimStr(input); + if (strs == NULL || strs[0] == '\0') { + return false; + } + const char* delim = "="; + List *res = NULL; + char* nextToken = NULL; + + /* Get name and num */ + char* token = strtok_s(strs, delim, &nextToken); + while (token != NULL) { + res = lappend(res, TrimStr(token)); + token = strtok_s(NULL, delim, &nextToken); + } + pfree(strs); + if (res->length != pairNum) { + list_free_deep(res); + return false; + } + int index = FindLWLockPartIndex((char*)linitial(res)); + if (index != -1) { + if (!StrToInt32((char*)lsecond(res), &g_instance.attr.attr_storage.num_internal_lock_partitions[index])) { + ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM), + errmsg("num_internal_lock_partitions attr has invalid lwlock num:%s.", (char*)lsecond(res)))); + } + list_free_deep(res); + return true; + } else { + ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM), + errmsg("num_internal_lock_partitions attr has invalid lwlock name: %s.", (char*)linitial(res)))); + return false; /* keep compiler silence */ + } +} + +void SetLWLockPartDefaultNum(void) +{ + int i; + for (i = 0; i < LWLOCK_PART_KIND; i++) { + g_instance.attr.attr_storage.num_internal_lock_partitions[i] = LWLockPartInfo[i].defaultNumPartition; + } +} + +void CheckAndSetLWLockPartInfo(const List* res) +{ + ListCell* cell = NULL; + foreach (cell, res) { + char* input = (char*)lfirst(cell); + if (!CheckAndSetLWLockPartNum(input)) { + ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM), + errmsg("num_internal_lock_partitions attr has invalid input syntax."))); + } + } +} + +void CheckLWLockPartNumRange(void) +{ + int i; + for (i = 0; i < LWLOCK_PART_KIND; i++) { + if (g_instance.attr.attr_storage.num_internal_lock_partitions[i] < LWLockPartInfo[i].minNumPartition || + g_instance.attr.attr_storage.num_internal_lock_partitions[i] > LWLockPartInfo[i].maxNumPartition) { + ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM), + errmsg("Invalid attribute for internal lock partitions."), + errdetail("Current %s lock partition num %d is out of range [%d, %d].", + LWLockPartInfo[i].name, g_instance.attr.attr_storage.num_internal_lock_partitions[i], + LWLockPartInfo[i].minNumPartition, LWLockPartInfo[i].maxNumPartition))); + } + } +} diff --git a/src/gausskernel/storage/lmgr/predicate.cpp b/src/gausskernel/storage/lmgr/predicate.cpp index 5d6e82094..39122148a 100644 --- a/src/gausskernel/storage/lmgr/predicate.cpp +++ b/src/gausskernel/storage/lmgr/predicate.cpp @@ -891,7 +891,7 @@ void CheckPointPredicate(void) LWLockRelease(OldSerXidLock); /* Truncate away pages that are no longer required */ - SimpleLruTruncate(t_thrd.shemem_ptr_cxt.OldSerXidSlruCtl, tailPage, false, NUM_SLRU_DEFAULT_PARTITION); + SimpleLruTruncate(t_thrd.shemem_ptr_cxt.OldSerXidSlruCtl, tailPage, NUM_SLRU_DEFAULT_PARTITION); /* * Flush dirty SLRU pages to disk diff --git a/src/gausskernel/storage/lmgr/proc.cpp b/src/gausskernel/storage/lmgr/proc.cpp index be18fb02d..704a78106 100644 --- a/src/gausskernel/storage/lmgr/proc.cpp +++ b/src/gausskernel/storage/lmgr/proc.cpp @@ -277,6 +277,8 @@ void InitProcGlobal(void) PGPROC *initProcs[MAX_NUMA_NODE] = {0}; int nNumaNodes = g_instance.shmem_cxt.numaNodeNum; + /* since myProcLocks is a various array, need palloc actrual size */ + Size actrualPgProcSize = offsetof(PGPROC, myProcLocks) + NUM_LOCK_PARTITIONS * sizeof(SHM_QUEUE); #ifdef __USE_NUMA if (nNumaNodes > 1) { ereport(INFO, (errmsg("InitProcGlobal nNumaNodes: %d, inheritThreadPool: %d, groupNum: %d", @@ -284,7 +286,7 @@ void InitProcGlobal(void) (g_threadPoolControler ? g_threadPoolControler->GetGroupNum() : 0)))); int groupProcCount = (TotalProcs + nNumaNodes - 1) / nNumaNodes; - size_t allocSize = groupProcCount * sizeof(PGPROC); + size_t allocSize = groupProcCount * actrualPgProcSize; for (int nodeNo = 0; nodeNo < nNumaNodes; nodeNo++) { initProcs[nodeNo] = (PGPROC *)numa_alloc_onnode(allocSize, nodeNo); if (!initProcs[nodeNo]) { @@ -292,13 +294,13 @@ void InitProcGlobal(void) errmsg("InitProcGlobal NUMA memory allocation in node %d failed.", nodeNo))); } add_numa_alloc_info(initProcs[nodeNo], allocSize); - int ret = memset_s(initProcs[nodeNo], groupProcCount * sizeof(PGPROC), 0, groupProcCount * sizeof(PGPROC)); + int ret = memset_s(initProcs[nodeNo], allocSize, 0, allocSize); securec_check_c(ret, "\0", "\0"); } } else { #endif if (needPalloc) { - initProcs[0] = (PGPROC *)CACHELINEALIGN(palloc0(TotalProcs * sizeof(PGPROC) + PG_CACHE_LINE_SIZE)); + initProcs[0] = (PGPROC *)CACHELINEALIGN(palloc0(TotalProcs * actrualPgProcSize + PG_CACHE_LINE_SIZE)); } else { initProcs[0] = g_instance.proc_base->allProcs[0]; errno_t rc = memset_s(initProcs[0], TotalProcs * sizeof(PGPROC), 0, TotalProcs * sizeof(PGPROC)); @@ -326,8 +328,8 @@ void InitProcGlobal(void) if (procs == NULL) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"))); - for (i = 0; (unsigned int)(i) < TotalProcs; i++) { - procs[i] = &initProcs[i % nNumaNodes][i / nNumaNodes]; + for (i = 0; (unsigned int)(i) < TotalProcs; i++) { /* set proc pointer to actural position */ + procs[i] = (PGPROC *)((char*)(initProcs[i % nNumaNodes]) + (i / nNumaNodes) * actrualPgProcSize); } if (needPalloc) { diff --git a/src/include/access/slru.h b/src/include/access/slru.h index bbf0175b0..6790669a4 100644 --- a/src/include/access/slru.h +++ b/src/include/access/slru.h @@ -154,7 +154,7 @@ extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId x extern int SimpleLruReadPage_ReadOnly_Locked(SlruCtl ctl, int64 pageno, TransactionId xid); extern void SimpleLruWritePage(SlruCtl ctl, int slotno); extern int SimpleLruFlush(SlruCtl ctl, bool checkpoint); -extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, bool isPart, int partitionNum); +extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, int partitionNum); typedef bool (*SlruScanCallback)(SlruCtl ctl, const char* filename, int64 segpage, const void* data); extern bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, const void* data); diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h index 9b33804d2..7b7d56fcc 100644 --- a/src/include/commands/copy.h +++ b/src/include/commands/copy.h @@ -378,6 +378,7 @@ extern bool IsCharType(Oid attr_type); extern int GetDecimalFromHex(char hex); extern char* limit_printout_length(const char* str); +extern bool StrToInt32(const char* s, int *val); extern char* TrimStr(const char* str); #endif /* COPY_H */ diff --git a/src/include/knl/knl_guc/knl_instance_attr_storage.h b/src/include/knl/knl_guc/knl_instance_attr_storage.h index 292c3dad8..c8bac1dd5 100644 --- a/src/include/knl/knl_guc/knl_instance_attr_storage.h +++ b/src/include/knl/knl_guc/knl_instance_attr_storage.h @@ -40,6 +40,15 @@ #include "knl/knl_guc/knl_guc_common.h" +/* order should same as lwlock part num desc, see lwlock.h */ +enum LWLOCK_PARTITION_ID { + CLOG_PART = 0, + CSNLOG_PART = 1, + LOG2_LOCKTABLE_PART = 2, + TWOPHASE_PART = 3, + LWLOCK_PART_KIND +}; + typedef struct knl_instance_attr_storage { bool wal_log_hints; bool EnableHotStandby; @@ -96,6 +105,8 @@ typedef struct knl_instance_attr_storage { int max_concurrent_autonomous_transactions; #endif char* available_zone; + int num_internal_lock_partitions[LWLOCK_PART_KIND]; + char* num_internal_lock_partitions_str; } knl_instance_attr_storage; #endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ */ diff --git a/src/include/storage/lock/lwlock.h b/src/include/storage/lock/lwlock.h index 146946ee2..01a541f34 100644 --- a/src/include/storage/lock/lwlock.h +++ b/src/include/storage/lock/lwlock.h @@ -15,6 +15,7 @@ #define LWLOCK_H #include "lib/ilist.h" +#include "nodes/pg_list.h" #include "storage/lock/s_lock.h" #include "utils/atomic.h" #include "gs_thread.h" @@ -28,6 +29,22 @@ typedef volatile uint64 pg_atomic_uint64; #endif extern const char *const MainLWLockNames[]; +const int MAX_LWLOCK_NAME_LENTH = 64; + +typedef struct LWLOCK_PARTITION_DESC { + char name[MAX_LWLOCK_NAME_LENTH]; + int defaultNumPartition; + int minNumPartition; + int maxNumPartition; +} LWLOCK_PARTITION_DESC; + +const struct LWLOCK_PARTITION_DESC LWLockPartInfo[] = { + {"CLOG_PART", 256, 1, 256}, + {"CSNLOG_PART", 512, 1, 512}, + {"LOG2_LOCKTABLE_PART", 4, 4, 16}, /* lock table partition range is 2^4 to 2^16 */ + {"TWOPHASE_PART", 1, 1, 64}, +}; + /* * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS * here, but we need them to figure out offsets within MainLWLockArray, and having @@ -54,13 +71,19 @@ extern const char *const MainLWLockNames[]; #define NUM_INSTANCE_REALTIME_PARTITIONS 32 /* CSN log partitions */ -#define NUM_CSNLOG_PARTITIONS 512 +#define MAX_NUM_CSNLOG_PARTITIONS (LWLockPartInfo[CSNLOG_PART].maxNumPartition) +#define NUM_CSNLOG_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[CSNLOG_PART]) /* Clog partitions */ -#define NUM_CLOG_PARTITIONS 256 +#define MAX_NUM_CLOG_PARTITIONS (LWLockPartInfo[CLOG_PART].maxNumPartition) +#define NUM_CLOG_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[CLOG_PART]) + +/* Twophase State partitions */ +#define NUM_TWOPHASE_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[TWOPHASE_PART]) /* Number of partitions the shared lock tables are divided into */ -#define LOG2_NUM_LOCK_PARTITIONS 4 +#define LOG2_NUM_LOCK_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[LOG2_LOCKTABLE_PART]) + #define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS) /* Number of partitions the shared predicate lock tables are divided into */ @@ -88,50 +111,65 @@ extern const char *const MainLWLockNames[]; /* Number of partions the io state hashtable */ #define NUM_IO_STAT_PARTITIONS 128 +/* Number of partitions the xid => procid hashtable */ +#define NUM_PROCXACT_PARTITIONS 128 + /* Number of partions the global sequence hashtable */ #define NUM_GS_PARTITIONS 1024 +/* Number of partions the global workload cache hashtable */ +#define NUM_GWC_PARTITIONS 64 + +#define NUM_STARTBLOCK_PARTITIONS 128 + +/* Number of partions of the segment head buffer */ +#define NUM_SEGMENT_HEAD_PARTITIONS 128 + #ifdef WIN32 -#define NUM_INDIVIDUAL_LWLOCKS 100 +#define NUM_INDIVIDUAL_LWLOCKS 113 #endif /* * WARNING---Please keep the order of LWLockTrunkOffset and BuiltinTrancheIds consistent!!! */ /* Offsets for various chunks of preallocated lwlocks in main array. */ -enum LWLockTrunkOffset { - FirstBufMappingLock = NUM_INDIVIDUAL_LWLOCKS, - FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, - FirstPredicateLockMgrLock = FirstLockMgrLock + NUM_LOCK_PARTITIONS, - FirstOperatorRealTLock = FirstPredicateLockMgrLock+ NUM_PREDICATELOCK_PARTITIONS, - FirstOperatorHistLock = FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS, - FirstSessionRealTLock = FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS, - FirstSessionHistLock = FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS, - FirstInstanceRealTLock = FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS, - /* Cache Mgr lock IDs */ - FirstCacheSlotMappingLock = FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS, - FirstCSNBufMappingLock = FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS, - FirstCBufMappingLock = FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS, - /* Instrumentaion */ - FirstUniqueSQLMappingLock = FirstCBufMappingLock + NUM_CLOG_PARTITIONS, - FirstInstrUserLock = FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS, - /* global plan cache */ - FirstGPCMappingLock = FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS, - FirstGPCPrepareMappingLock = FirstGPCMappingLock + NUM_GPC_PARTITIONS, - /* ASP */ - FirstASPMappingLock = FirstGPCPrepareMappingLock + NUM_GPC_PARTITIONS, - /* global sequence */ - FirstGlobalSeqLock = FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS, +#define FirstBufMappingLock (NUM_INDIVIDUAL_LWLOCKS) +#define FirstLockMgrLock (FirstBufMappingLock + NUM_BUFFER_PARTITIONS) +#define FirstPredicateLockMgrLock (FirstLockMgrLock + NUM_LOCK_PARTITIONS) +#define FirstOperatorRealTLock (FirstPredicateLockMgrLock + NUM_PREDICATELOCK_PARTITIONS) +#define FirstOperatorHistLock (FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS) +#define FirstSessionRealTLock (FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS) +#define FirstSessionHistLock (FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS) +#define FirstInstanceRealTLock (FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS) +/* Cache Mgr lock IDs */ +#define FirstCacheSlotMappingLock (FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS) +#define FirstCSNBufMappingLock (FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS) +#define FirstCBufMappingLock (FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS) +/* Instrumentaion */ +#define FirstUniqueSQLMappingLock (FirstCBufMappingLock + NUM_CLOG_PARTITIONS) +#define FirstInstrUserLock (FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS) +/* global plan cache */ +#define FirstGPCMappingLock (FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS) +/* ASP */ +#define FirstASPMappingLock (FirstGPCMappingLock + NUM_GPC_PARTITIONS) +/* global sequence */ +#define FirstGlobalSeqLock (FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS) +/* global workload cache */ +#define FirstGWCMappingLock (FirstGlobalSeqLock + NUM_GS_PARTITIONS) - FirstNormalizedSqlLock = FirstGlobalSeqLock + NUM_GS_PARTITIONS, - FirstMPFLLock = FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS, +#define FirstNormalizedSqlLock (FirstGWCMappingLock + NUM_GWC_PARTITIONS) +#define FirstMPFLLock (FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS) +#define FirstNGroupMappingLock (FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS) +#define FirstIOStatLock (FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS) +/* undo space & trans group mapping */ +#define FirstProcXactMappingLock (FirstIOStatLock + NUM_IO_STAT_PARTITIONS) +#define FirstStartBlockMappingLock (FirstProcXactMappingLock + NUM_PROCXACT_PARTITIONS) +/* segment head */ +#define FirstSegmentHeadLock (FirstStartBlockMappingLock + NUM_STARTBLOCK_PARTITIONS) +#define FirstTwoPhaseStateLock (FirstSegmentHeadLock + NUM_SEGMENT_HEAD_PARTITIONS) - FirstNGroupMappingLock = FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS, - FirstIOStatLock = FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS, - - /* must be last: */ - NumFixedLWLocks = FirstIOStatLock + NUM_IO_STAT_PARTITIONS -}; +/* must be last: */ +#define NumFixedLWLocks (FirstTwoPhaseStateLock + NUM_TWOPHASE_PARTITIONS) /* * WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!! @@ -157,12 +195,17 @@ enum BuiltinTrancheIds LWTRANCHE_UNIQUE_SQLMAPPING, LWTRANCHE_INSTR_USER, LWTRANCHE_GPC_MAPPING, - LWTRANCHE_GPC_PREPARE_MAPPING, + LWTRANCHE_USPACE_TRANSGRP_MAPPING, + LWTRANCHE_PROC_XACT_MAPPING, LWTRANCHE_ASP_MAPPING, LWTRANCHE_GlobalSeq, + LWTRANCHE_GWC_MAPPING, LWTRANCHE_NORMALIZED_SQL, + LWTRANCHE_START_BLOCK_MAPPING, LWTRANCHE_BUFFER_IO_IN_PROGRESS, LWTRANCHE_BUFFER_CONTENT, + LWTRANCHE_UNDO_ZONE, + LWTRANCHE_UNDO_SPACE, LWTRANCHE_DATA_CACHE, LWTRANCHE_META_CACHE, LWTRANCHE_PROC, @@ -190,6 +233,8 @@ enum BuiltinTrancheIds LWTRANCHE_WAL_FLUSH_WAIT, LWTRANCHE_WAL_BUFFER_INIT_WAIT, LWTRANCHE_WAL_INIT_SEGMENT, + LWTRANCHE_SEGHEAD_PARTITION, + LWTRANCHE_TWOPHASE_STATE, /* * Each trancheId above should have a corresponding item in BuiltinTrancheNames; */ @@ -318,6 +363,9 @@ extern void CreateLWLocks(void); extern void RequestAddinLWLocks(int n); extern const char* GetBuiltInTrancheName(int trancheId); +extern void SetLWLockPartDefaultNum(void); +extern void CheckAndSetLWLockPartInfo(const List* res); +extern void CheckLWLockPartNumRange(void); /* * There is another, more flexible method of obtaining lwlocks. First, call diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 58482c2ef..6a8d73bad 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -183,13 +183,6 @@ struct PGPROC { pg_time_t myStartTime; syscalllock deleMemContextMutex; - /* - * All PROCLOCK objects for locks held or awaited by this backend are - * linked into one of these lists, according to the partition number of - * their lock. - */ - SHM_QUEUE myProcLocks[NUM_LOCK_PARTITIONS]; - /* Support for group XID clearing. */ /* true, if member of ProcArray group waiting for XID clear */ bool procArrayGroupMember; @@ -264,6 +257,13 @@ struct PGPROC { char *dw_unaligned_buf; char *dw_buf; volatile int32 dw_pos; + + /* + * All PROCLOCK objects for locks held or awaited by this backend are + * linked into one of these lists, according to the partition number of + * their lock. + */ + SHM_QUEUE myProcLocks[1]; }; /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock/lock.h. */ diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index 38bab81d4..f83589767 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -433,5 +433,6 @@ extern void set_qunit_case_number_hook(int newval, void* extra); #endif extern GucContext get_guc_context(); +extern void InitializeNumLwLockPartitions(void); #endif /* GUC_H */