From 36320533e1b1b4366bc70a747bfa9d084def1a24 Mon Sep 17 00:00:00 2001 From: GongXun Date: Fri, 16 May 2025 23:51:28 +0800 Subject: [PATCH] Enhancement: change link methd to reduce PLT overhead During TPC-DS testing, we observed that compiling postgres with libpostgres.so introduces PTL function call overhead for some functions. By linking object files (*.o) directly instead, we achieved a 5-8% performance improvement in the TPC-DS 1TB benchmark. This commit added an option enable_link_postgres_with_shared to link libpostgres.so when compiling postgres, and The default value is false, just like greenplum, statically linking all object files when compiling postgres. Additionally, this update fixes a minor bug: the pax extension has a dependency on libpostgres.so. Now, when enabling the pax entension, we check that enable_shared_postgres_backend is set to 'yes' to ensure proper functionality. And the ic-cbdb-parallel test has been migrated to use the release version instead of the debug version. This change was made because running the test on the debug version caused disk space issues. When both libpostgres.so and postgres are compiled in the debug version, disk usage increases by several hundred megabytes compared to the release version. As a result, the ic-cbdb-parallel test failed due to insufficient disk space. By switching to the release version, this issue is resolved, and the test runs faster as well. --- .github/workflows/build-cloudberry.yml | 3 ++ .github/workflows/build-dbg-cloudberry.yml | 3 -- configure | 51 ++++++++++++++++++++++ configure.ac | 23 ++++++++++ src/Makefile.global.in | 1 + src/backend/Makefile | 8 +++- 6 files changed, 85 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-cloudberry.yml b/.github/workflows/build-cloudberry.yml index a6e659596b5..8d04d51a095 100644 --- a/.github/workflows/build-cloudberry.yml +++ b/.github/workflows/build-cloudberry.yml @@ -315,6 +315,9 @@ jobs: }, {"test":"ic-parallel-retrieve-cursor", "make_configs":["src/test/isolation2:installcheck-parallel-retrieve-cursor"] + }, + {"test":"ic-cbdb-parallel", + "make_configs":["src/test/regress:installcheck-cbdb-parallel"] } ] }' diff --git a/.github/workflows/build-dbg-cloudberry.yml b/.github/workflows/build-dbg-cloudberry.yml index 998242efcd7..569e6a350d6 100644 --- a/.github/workflows/build-dbg-cloudberry.yml +++ b/.github/workflows/build-dbg-cloudberry.yml @@ -222,9 +222,6 @@ jobs: # Define base test configurations ALL_TESTS='{ "include": [ - {"test":"ic-cbdb-parallel", - "make_configs":["src/test/regress:installcheck-cbdb-parallel"] - } ] }' diff --git a/configure b/configure index c816899b965..8b65ad8fe81 100755 --- a/configure +++ b/configure @@ -758,6 +758,7 @@ enable_ic_proxy enable_external_fts HAVE_CXX14 enable_gpcloud +enable_link_postgres_with_shared enable_shared_postgres_backend enable_mapreduce enable_serverless @@ -899,6 +900,7 @@ enable_catalog_ext enable_serverless enable_mapreduce enable_shared_postgres_backend +enable_link_postgres_with_shared enable_gpcloud enable_external_fts enable_ic_proxy @@ -1613,6 +1615,9 @@ Optional Features: --enable-mapreduce enable Cloudberry Mapreduce support --disable-shared-postgres-backend enable Cloudberry shared postgres backend support + --enable-link-postgres-with-shared + build postgres using the shared library + libpostgres.so --enable-gpcloud enable gpcloud support --enable-external-fts enable external fts support --enable-ic-proxy enable interconnect proxy mode (requires libuv @@ -8485,6 +8490,45 @@ if test "$enable_shared_postgres_backend" = yes ; then : fi # fi +# +# --enable-link-postgres-with-shared enables linking postgres with shared library libpostgres.so +# + + +# Check whether --enable-link-postgres-with-shared was given. +if test "${enable_link_postgres_with_shared+set}" = set; then : + enableval=$enable_link_postgres_with_shared; + case $enableval in + yes) + +$as_echo "#define USE_LINK_POSTGRES_WITH_SHARED 1" >>confdefs.h + + ;; + no) + : + ;; + *) + as_fn_error $? "no argument expected for --enable-link-postgres-with-shared option" "$LINENO" 5 + ;; + esac + +else + enable_link_postgres_with_shared=no + +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: checking whether to build postgres using the shared library libpostgres.so... $enable_link_postgres_with_shared" >&5 +$as_echo "checking whether to build postgres using the shared library libpostgres.so... $enable_link_postgres_with_shared" >&6; } + + +# check if enable-shared-postgres-backend is yes if enable-link-postgres-with-shared is yes +if test "$enable_link_postgres_with_shared" = yes; then + if test "$enable_shared_postgres_backend" = no; then + as_fn_error $? "--enable-link-postgres-with-shared is yes, but --enable-shared-postgres-backend is no" "$LINENO" 5 + fi +fi + # # gpcloud, enabled by default # @@ -15702,6 +15746,13 @@ fi +# for contrib/pax_storage +if test "$enable_pax" = yes; then + if test "$enable_shared_postgres_backend" = no; then + as_fn_error $? "pax support requires --enable-shared-postgres-backend" "$LINENO" 5 + fi +fi + # for contrib/sepgsql if test "$with_selinux" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for security_compute_create_name in -lselinux" >&5 diff --git a/configure.ac b/configure.ac index 6882c63e207..0834022b8c2 100644 --- a/configure.ac +++ b/configure.ac @@ -880,6 +880,22 @@ AS_IF([test "$enable_shared_postgres_backend" = yes ], CXXFLAGS="$CXXFLAGS -fPIC " ]) # fi +# +# --enable-link-postgres-with-shared enables linking postgres with shared library libpostgres.so +# +PGAC_ARG_BOOL(enable, link-postgres-with-shared, no, [build postgres using the shared library libpostgres.so ], + [AC_DEFINE([USE_LINK_POSTGRES_WITH_SHARED], 1, + [Define to 1 to build postgres using the shared library libpostgres.so (--enable-link-postgres-with-shared)])]) +AC_MSG_RESULT([checking whether to build postgres using the shared library libpostgres.so... $enable_link_postgres_with_shared]) +AC_SUBST(enable_link_postgres_with_shared) + +# check if enable-shared-postgres-backend is yes if enable-link-postgres-with-shared is yes +if test "$enable_link_postgres_with_shared" = yes; then + if test "$enable_shared_postgres_backend" = no; then + AC_MSG_ERROR([--enable-link-postgres-with-shared is yes, but --enable-shared-postgres-backend is no]) + fi +fi + # # gpcloud, enabled by default # @@ -1749,6 +1765,13 @@ fi AC_SUBST(LDAP_LIBS_FE) AC_SUBST(LDAP_LIBS_BE) +# for contrib/pax_storage +if test "$enable_pax" = yes; then + if test "$enable_shared_postgres_backend" = no; then + AC_MSG_ERROR([pax support requires --enable-shared-postgres-backend]) + fi +fi + # for contrib/sepgsql if test "$with_selinux" = yes; then AC_CHECK_LIB(selinux, security_compute_create_name, [], diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 8a195a39856..343eb985c69 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -230,6 +230,7 @@ enable_debug_extensions = @enable_debug_extensions@ enable_orafce = @enable_orafce@ enable_mapreduce = @enable_mapreduce@ enable_shared_postgres_backend = @enable_shared_postgres_backend@ +enable_link_postgres_with_shared = @enable_link_postgres_with_shared@ enable_gpcloud = @enable_gpcloud@ enable_ic_proxy = @enable_ic_proxy@ enable_pax = @enable_pax@ diff --git a/src/backend/Makefile b/src/backend/Makefile index 6c16a9aa9e4..44dbe7f0e15 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -105,16 +105,22 @@ $(SYMBOL_MAP_FILE): $(top_builddir)/src/interfaces/libpq/exports.txt ( echo '{ global: *; '; echo ' local:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $< | grep -v -E $(SAFELY_EXPORTED_SYMBOLS_PATTERN); echo '};' ) >$@ SYMBOL_MAPPING_FLAGS = -Wl,--version-script=$(SYMBOL_MAP_FILE) endif - ifeq ($(enable_shared_postgres_backend),yes) +all: libpostgres.so libpostgres.so: $(OBJS) $(SYMBOL_MAP_FILE) $(CXX) -shared $(CXXFLAGS) $(LDFLAGS) $(LDFLAGS_SL) $(export_dynamic) \ $(filter-out main/main.o, $(call expand_subsys,$(OBJS))) $(LIBS) $(SYMBOL_MAPPING_FLAGS) -o $@ +# if enable-build-postgres-with-shared is yes, link postgres with shared library libpostgres.so +ifeq ($(enable_link_postgres_with_shared),yes) postgres: main/main.o libpostgres.so $(top_builddir)/src/port/libpgport_srv.a $(top_builddir)/src/common/libpgcommon_srv.a $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) \ main/main.o libpostgres.so $(top_builddir)/src/port/libpgport_srv.a \ $(top_builddir)/src/common/libpgcommon_srv.a $(LIBS) -o $@ +else +postgres: $(OBJS) $(SYMBOL_MAP_FILE) + $(CXX) $(CXXFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) $(SYMBOL_MAPPING_FLAGS) -o $@ +endif else postgres: $(OBJS) $(SYMBOL_MAP_FILE)