Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d5a4371

Browse files
jakubwartakEDBbdrouvotAWS
authored and
Commitfest Bot
committed
Add support for basic NUMA awareness
Add basic NUMA awareness routines, using a minimal src/port/pg_numa.c portability wrapper and an optional build dependency, enabled by --with-libnuma configure option. For now this is Linux-only, other platforms may be supported later. A built-in SQL function pg_numa_available() allows checking NUMA support, i.e. that the server was built/linked with NUMA library. The libnuma library is not available on 32-bit builds (there's no shared object for i386), so we disable it in that case. The i386 is very memory limited anyway, even with PAE, so NUMA is mostly irrelevant. On Linux we use move_pages(2) syscall for speed instead of get_mempolicy(2). Author: Jakub Wartak <jakub.wartak@enterprisedb.com> Co-authored-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/CAKZiRmxh6KWo0aqRqvmcoaX2jUxZYb4kGp3N%3Dq1w%2BDiH-696Xw%40mail.gmail.com
1 parent d9c7911 commit d5a4371

File tree

17 files changed

+442
-2
lines changed

17 files changed

+442
-2
lines changed

.cirrus.tasks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ task:
471471
--enable-cassert --enable-injection-points --enable-debug \
472472
--enable-tap-tests --enable-nls \
473473
--with-segsize-blocks=6 \
474+
--with-libnuma \
474475
--with-liburing \
475476
\
476477
${LINUX_CONFIGURE_FEATURES} \
@@ -523,6 +524,7 @@ task:
523524
-Dllvm=disabled \
524525
--pkg-config-path /usr/lib/i386-linux-gnu/pkgconfig/ \
525526
-DPERL=perl5.36-i386-linux-gnu \
527+
-Dlibnuma=disabled \
526528
build-32
527529
EOF
528530

configure

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ XML2_LIBS
708708
XML2_CFLAGS
709709
XML2_CONFIG
710710
with_libxml
711+
LIBNUMA_LIBS
712+
LIBNUMA_CFLAGS
713+
with_libnuma
711714
LIBCURL_LIBS
712715
LIBCURL_CFLAGS
713716
with_libcurl
@@ -872,6 +875,7 @@ with_liburing
872875
with_uuid
873876
with_ossp_uuid
874877
with_libcurl
878+
with_libnuma
875879
with_libxml
876880
with_libxslt
877881
with_system_tzdata
@@ -906,6 +910,8 @@ LIBURING_CFLAGS
906910
LIBURING_LIBS
907911
LIBCURL_CFLAGS
908912
LIBCURL_LIBS
913+
LIBNUMA_CFLAGS
914+
LIBNUMA_LIBS
909915
XML2_CONFIG
910916
XML2_CFLAGS
911917
XML2_LIBS
@@ -1588,6 +1594,7 @@ Optional Packages:
15881594
--with-uuid=LIB build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)
15891595
--with-ossp-uuid obsolete spelling of --with-uuid=ossp
15901596
--with-libcurl build with libcurl support
1597+
--with-libnuma build with libnuma support
15911598
--with-libxml build with XML support
15921599
--with-libxslt use XSLT support when building contrib/xml2
15931600
--with-system-tzdata=DIR
@@ -1629,6 +1636,10 @@ Some influential environment variables:
16291636
C compiler flags for LIBCURL, overriding pkg-config
16301637
LIBCURL_LIBS
16311638
linker flags for LIBCURL, overriding pkg-config
1639+
LIBNUMA_CFLAGS
1640+
C compiler flags for LIBNUMA, overriding pkg-config
1641+
LIBNUMA_LIBS
1642+
linker flags for LIBNUMA, overriding pkg-config
16321643
XML2_CONFIG path to xml2-config utility
16331644
XML2_CFLAGS C compiler flags for XML2, overriding pkg-config
16341645
XML2_LIBS linker flags for XML2, overriding pkg-config
@@ -9063,6 +9074,182 @@ $as_echo "$as_me: WARNING: *** OAuth support tests require --with-python to run"
90639074
fi
90649075

90659076

9077+
#
9078+
# libnuma
9079+
#
9080+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with libnuma support" >&5
9081+
$as_echo_n "checking whether to build with libnuma support... " >&6; }
9082+
9083+
9084+
9085+
# Check whether --with-libnuma was given.
9086+
if test "${with_libnuma+set}" = set; then :
9087+
withval=$with_libnuma;
9088+
case $withval in
9089+
yes)
9090+
9091+
$as_echo "#define USE_LIBNUMA 1" >>confdefs.h
9092+
9093+
;;
9094+
no)
9095+
:
9096+
;;
9097+
*)
9098+
as_fn_error $? "no argument expected for --with-libnuma option" "$LINENO" 5
9099+
;;
9100+
esac
9101+
9102+
else
9103+
with_libnuma=no
9104+
9105+
fi
9106+
9107+
9108+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_libnuma" >&5
9109+
$as_echo "$with_libnuma" >&6; }
9110+
9111+
9112+
if test "$with_libnuma" = yes ; then
9113+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for numa_available in -lnuma" >&5
9114+
$as_echo_n "checking for numa_available in -lnuma... " >&6; }
9115+
if ${ac_cv_lib_numa_numa_available+:} false; then :
9116+
$as_echo_n "(cached) " >&6
9117+
else
9118+
ac_check_lib_save_LIBS=$LIBS
9119+
LIBS="-lnuma $LIBS"
9120+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9121+
/* end confdefs.h. */
9122+
9123+
/* Override any GCC internal prototype to avoid an error.
9124+
Use char because int might match the return type of a GCC
9125+
builtin and then its argument prototype would still apply. */
9126+
#ifdef __cplusplus
9127+
extern "C"
9128+
#endif
9129+
char numa_available ();
9130+
int
9131+
main ()
9132+
{
9133+
return numa_available ();
9134+
;
9135+
return 0;
9136+
}
9137+
_ACEOF
9138+
if ac_fn_c_try_link "$LINENO"; then :
9139+
ac_cv_lib_numa_numa_available=yes
9140+
else
9141+
ac_cv_lib_numa_numa_available=no
9142+
fi
9143+
rm -f core conftest.err conftest.$ac_objext \
9144+
conftest$ac_exeext conftest.$ac_ext
9145+
LIBS=$ac_check_lib_save_LIBS
9146+
fi
9147+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_numa_numa_available" >&5
9148+
$as_echo "$ac_cv_lib_numa_numa_available" >&6; }
9149+
if test "x$ac_cv_lib_numa_numa_available" = xyes; then :
9150+
cat >>confdefs.h <<_ACEOF
9151+
#define HAVE_LIBNUMA 1
9152+
_ACEOF
9153+
9154+
LIBS="-lnuma $LIBS"
9155+
9156+
else
9157+
as_fn_error $? "library 'libnuma' is required for NUMA support" "$LINENO" 5
9158+
fi
9159+
9160+
9161+
pkg_failed=no
9162+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for numa" >&5
9163+
$as_echo_n "checking for numa... " >&6; }
9164+
9165+
if test -n "$LIBNUMA_CFLAGS"; then
9166+
pkg_cv_LIBNUMA_CFLAGS="$LIBNUMA_CFLAGS"
9167+
elif test -n "$PKG_CONFIG"; then
9168+
if test -n "$PKG_CONFIG" && \
9169+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"numa\""; } >&5
9170+
($PKG_CONFIG --exists --print-errors "numa") 2>&5
9171+
ac_status=$?
9172+
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
9173+
test $ac_status = 0; }; then
9174+
pkg_cv_LIBNUMA_CFLAGS=`$PKG_CONFIG --cflags "numa" 2>/dev/null`
9175+
test "x$?" != "x0" && pkg_failed=yes
9176+
else
9177+
pkg_failed=yes
9178+
fi
9179+
else
9180+
pkg_failed=untried
9181+
fi
9182+
if test -n "$LIBNUMA_LIBS"; then
9183+
pkg_cv_LIBNUMA_LIBS="$LIBNUMA_LIBS"
9184+
elif test -n "$PKG_CONFIG"; then
9185+
if test -n "$PKG_CONFIG" && \
9186+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"numa\""; } >&5
9187+
($PKG_CONFIG --exists --print-errors "numa") 2>&5
9188+
ac_status=$?
9189+
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
9190+
test $ac_status = 0; }; then
9191+
pkg_cv_LIBNUMA_LIBS=`$PKG_CONFIG --libs "numa" 2>/dev/null`
9192+
test "x$?" != "x0" && pkg_failed=yes
9193+
else
9194+
pkg_failed=yes
9195+
fi
9196+
else
9197+
pkg_failed=untried
9198+
fi
9199+
9200+
9201+
9202+
if test $pkg_failed = yes; then
9203+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9204+
$as_echo "no" >&6; }
9205+
9206+
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
9207+
_pkg_short_errors_supported=yes
9208+
else
9209+
_pkg_short_errors_supported=no
9210+
fi
9211+
if test $_pkg_short_errors_supported = yes; then
9212+
LIBNUMA_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "numa" 2>&1`
9213+
else
9214+
LIBNUMA_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "numa" 2>&1`
9215+
fi
9216+
# Put the nasty error message in config.log where it belongs
9217+
echo "$LIBNUMA_PKG_ERRORS" >&5
9218+
9219+
as_fn_error $? "Package requirements (numa) were not met:
9220+
9221+
$LIBNUMA_PKG_ERRORS
9222+
9223+
Consider adjusting the PKG_CONFIG_PATH environment variable if you
9224+
installed software in a non-standard prefix.
9225+
9226+
Alternatively, you may set the environment variables LIBNUMA_CFLAGS
9227+
and LIBNUMA_LIBS to avoid the need to call pkg-config.
9228+
See the pkg-config man page for more details." "$LINENO" 5
9229+
elif test $pkg_failed = untried; then
9230+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9231+
$as_echo "no" >&6; }
9232+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
9233+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
9234+
as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
9235+
is in your PATH or set the PKG_CONFIG environment variable to the full
9236+
path to pkg-config.
9237+
9238+
Alternatively, you may set the environment variables LIBNUMA_CFLAGS
9239+
and LIBNUMA_LIBS to avoid the need to call pkg-config.
9240+
See the pkg-config man page for more details.
9241+
9242+
To get pkg-config, see <http://pkg-config.freedesktop.org/>.
9243+
See \`config.log' for more details" "$LINENO" 5; }
9244+
else
9245+
LIBNUMA_CFLAGS=$pkg_cv_LIBNUMA_CFLAGS
9246+
LIBNUMA_LIBS=$pkg_cv_LIBNUMA_LIBS
9247+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9248+
$as_echo "yes" >&6; }
9249+
9250+
fi
9251+
fi
9252+
90669253
#
90679254
# XML
90689255
#

configure.ac

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,20 @@ if test "$with_libcurl" = yes ; then
10531053
fi
10541054

10551055

1056+
#
1057+
# libnuma
1058+
#
1059+
AC_MSG_CHECKING([whether to build with libnuma support])
1060+
PGAC_ARG_BOOL(with, libnuma, no, [build with libnuma support],
1061+
[AC_DEFINE([USE_LIBNUMA], 1, [Define to build with NUMA support. (--with-libnuma)])])
1062+
AC_MSG_RESULT([$with_libnuma])
1063+
AC_SUBST(with_libnuma)
1064+
1065+
if test "$with_libnuma" = yes ; then
1066+
AC_CHECK_LIB(numa, numa_available, [], [AC_MSG_ERROR([library 'libnuma' is required for NUMA support])])
1067+
PKG_CHECK_MODULES(LIBNUMA, numa)
1068+
fi
1069+
10561070
#
10571071
# XML
10581072
#

doc/src/sgml/func.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25143,6 +25143,19 @@ SELECT * FROM pg_ls_dir('.') WITH ORDINALITY AS t(ls,n);
2514325143
</para></entry>
2514425144
</row>
2514525145

25146+
<row>
25147+
<entry role="func_table_entry"><para role="func_signature">
25148+
<indexterm>
25149+
<primary>pg_numa_available</primary>
25150+
</indexterm>
25151+
<function>pg_numa_available</function> ()
25152+
<returnvalue>boolean</returnvalue>
25153+
</para>
25154+
<para>
25155+
Returns true if the server has been compiled with <acronym>NUMA</acronym> support.
25156+
</para></entry>
25157+
</row>
25158+
2514625159
<row>
2514725160
<entry role="func_table_entry"><para role="func_signature">
2514825161
<indexterm>

doc/src/sgml/installation.sgml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,16 @@ build-postgresql:
11561156
</listitem>
11571157
</varlistentry>
11581158

1159+
<varlistentry id="configure-option-with-libnuma">
1160+
<term><option>--with-libnuma</option></term>
1161+
<listitem>
1162+
<para>
1163+
Build with libnuma support for basic NUMA support.
1164+
Only supported on platforms for which the <productname>libnuma</productname> library is implemented.
1165+
</para>
1166+
</listitem>
1167+
</varlistentry>
1168+
11591169
<varlistentry id="configure-option-with-liburing">
11601170
<term><option>--with-liburing</option></term>
11611171
<listitem>
@@ -2645,6 +2655,17 @@ ninja install
26452655
</listitem>
26462656
</varlistentry>
26472657

2658+
<varlistentry id="configure-with-libnuma-meson">
2659+
<term><option>-Dlibnuma={ auto | enabled | disabled }</option></term>
2660+
<listitem>
2661+
<para>
2662+
Build with libnuma support for basic NUMA support.
2663+
Only supported on platforms for which the <productname>libnuma</productname> library is implemented.
2664+
The default for this option is auto.
2665+
</para>
2666+
</listitem>
2667+
</varlistentry>
2668+
26482669
<varlistentry id="configure-with-libxml-meson">
26492670
<term><option>-Dlibxml={ auto | enabled | disabled }</option></term>
26502671
<listitem>

meson.build

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,27 @@ else
943943
endif
944944

945945

946+
###############################################################
947+
# Library: libnuma
948+
###############################################################
949+
950+
libnumaopt = get_option('libnuma')
951+
if not libnumaopt.disabled()
952+
# via pkg-config
953+
libnuma = dependency('numa', required: libnumaopt)
954+
if not libnuma.found()
955+
libnuma = cc.find_library('numa', required: libnumaopt)
956+
endif
957+
if not cc.has_header('numa.h', dependencies: libnuma, required: libnumaopt)
958+
libnuma = not_found_dep
959+
endif
960+
if libnuma.found()
961+
cdata.set('USE_LIBNUMA', 1)
962+
endif
963+
else
964+
libnuma = not_found_dep
965+
endif
966+
946967

947968
###############################################################
948969
# Library: liburing
@@ -3243,6 +3264,7 @@ backend_both_deps += [
32433264
icu_i18n,
32443265
ldap,
32453266
libintl,
3267+
libnuma,
32463268
liburing,
32473269
libxml,
32483270
lz4,
@@ -3899,6 +3921,7 @@ if meson.version().version_compare('>=0.57')
38993921
'icu': icu,
39003922
'ldap': ldap,
39013923
'libcurl': libcurl,
3924+
'libnuma': libnuma,
39023925
'liburing': liburing,
39033926
'libxml': libxml,
39043927
'libxslt': libxslt,

meson_options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ option('libcurl', type : 'feature', value: 'auto',
106106
option('libedit_preferred', type: 'boolean', value: false,
107107
description: 'Prefer BSD Libedit over GNU Readline')
108108

109+
option('libnuma', type: 'feature', value: 'auto',
110+
description: 'NUMA support')
111+
109112
option('liburing', type : 'feature', value: 'auto',
110113
description: 'io_uring support, for asynchronous I/O')
111114

0 commit comments

Comments
 (0)