Skip to content

Commit cc42a2f

Browse files
committed
linux: add support for numa set_mempolicy(2)
mempolicy.c: - new file - provides libcrun_set_mempolicy as wrapper to set_mempolicy(2) mempolicy.h: - new file - define libcrun_set_mempolicy mempolicy_internal.h: - new file - define memory policy mode and flags maps to be shared and updated in one single place - numa python bindings are not available on most distros. This makes numa features detection challenging for crun test suite without causing false positives. This header provides shared common definitions with tests_mempolicy_helper.c that is used by the test suite and avoid duplicate code around container.c: - add call to libcrun_set_mempolicy in libcrun_container_run_internal tests/tests_mempolicy_helper.c: - new file - print a list of numa features detected during the build - shares info from mempolicy_internal.h tests/test_mempolicy.py: - new file - add both negative and positive tests for mempolicy.c - tests will run if hw supports numa or skip Makefile.am: - update - changes verified also with make distcheck global: add build require on numactl-devel or equivalent Signed-off-by: Fabio M. Di Nitto <[email protected]>
1 parent 92977c0 commit cc42a2f

File tree

28 files changed

+829
-27
lines changed

28 files changed

+829
-27
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
- run: |
3737
sudo apt-get update
38-
sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev
38+
sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev libnuma-dev
3939
./autogen.sh
4040
./configure
4141
make -j $(nproc)

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- run: sudo apt-get update
2121

22-
- run: sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev
22+
- run: sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev libnuma-dev
2323

2424
- run: |
2525
set -ex

.github/workflows/test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
install: |
4242
apt-get update -y
43-
apt-get install -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev clang mawk
43+
apt-get install -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev clang mawk libnuma-dev
4444
4545
run: |
4646
find $(pwd) -name '.git' -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;
@@ -94,7 +94,7 @@ jobs:
9494
9595
sudo add-apt-repository -y ppa:criu/ppa
9696
# add-apt-repository runs apt-get update so we don't have to.
97-
sudo apt-get install -q -y criu automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev containerd runc libasan6 libprotobuf-c-dev mawk
97+
sudo apt-get install -q -y criu automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev containerd runc libasan6 libprotobuf-c-dev mawk libnuma-dev
9898
9999
- name: run autogen.sh
100100
run: |
@@ -210,7 +210,7 @@ jobs:
210210
- name: install dependencies
211211
run: |
212212
sudo apt-get update -q -y
213-
sudo apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev mawk
213+
sudo apt-get install -q -y automake libtool autotools-dev libseccomp-dev git make libcap-dev cmake pkg-config gcc wget go-md2man libsystemd-dev gperf clang-format libyajl-dev libprotobuf-c-dev mawk libnuma-dev
214214
- uses: lumaxis/shellcheck-problem-matchers@v2
215215
- name: shellcheck
216216
run: |

Makefile.am

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ libcrun_SOURCES = src/libcrun/utils.c \
6767
src/libcrun/linux.c \
6868
src/libcrun/mount_flags.c \
6969
src/libcrun/scheduler.c \
70+
src/libcrun/mempolicy.c \
7071
src/libcrun/seccomp.c \
7172
src/libcrun/seccomp_notify.c \
7273
src/libcrun/signals.c \
@@ -160,7 +161,7 @@ EXTRA_DIST = COPYING COPYING.libcrun README.md NEWS SECURITY.md rpm/crun.spec au
160161
src/libcrun/custom-handler.h src/libcrun/io_priority.h \
161162
src/libcrun/handlers/handler-utils.h \
162163
src/libcrun/linux.h src/libcrun/utils.h src/libcrun/error.h src/libcrun/criu.h \
163-
src/libcrun/scheduler.h src/libcrun/status.h src/libcrun/terminal.h \
164+
src/libcrun/scheduler.h src/libcrun/mempolicy.h src/libcrun/mempolicy_internal.h src/libcrun/status.h src/libcrun/terminal.h \
164165
src/libcrun/mount_flags.h src/libcrun/intelrdt.h src/libcrun/ring_buffer.h src/libcrun/string_map.h \
165166
src/libcrun/net_device.h \
166167
crun.1.md crun.1 libcrun.lds \
@@ -179,7 +180,7 @@ noinst_PROGRAMS = crun
179180
endif
180181

181182
if BUILD_TESTS
182-
check_PROGRAMS = tests/init $(UNIT_TESTS) tests/tests_libcrun_fuzzer
183+
check_PROGRAMS = tests/init $(UNIT_TESTS) tests/tests_libcrun_fuzzer tests/tests_mempolicy_helper
183184

184185
TESTS_LDADD = libcrun_testing.la $(FOUND_LIBS) $(maybe_libyajl.la)
185186

@@ -212,6 +213,11 @@ tests_tests_libcrun_errors_SOURCES = tests/tests_libcrun_errors.c
212213
tests_tests_libcrun_errors_LDADD = $(TESTS_LDADD)
213214
tests_tests_libcrun_errors_LDFLAGS = $(crun_LDFLAGS)
214215

216+
tests_tests_mempolicy_helper_CFLAGS = -I $(abs_top_builddir)/libocispec/src -I $(abs_top_srcdir)/libocispec/src -I $(abs_top_builddir)/src/libcrun -I $(abs_top_srcdir)/src/libcrun
217+
tests_tests_mempolicy_helper_SOURCES = tests/tests_mempolicy_helper.c
218+
tests_tests_mempolicy_helper_LDADD = $(TESTS_LDADD)
219+
tests_tests_mempolicy_helper_LDFLAGS = $(crun_LDFLAGS)
220+
215221
endif
216222
TEST_EXTENSIONS = .py
217223
PY_LOG_COMPILER = $(PYTHON)
@@ -225,6 +231,7 @@ PYTHON_TESTS = tests/test_capabilities.py \
225231
tests/test_hostname.py \
226232
tests/test_limits.py \
227233
tests/test_oci_features.py \
234+
tests/test_mempolicy.py \
228235
tests/test_mounts.py \
229236
tests/test_paths.py \
230237
tests/test_pid.py \

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ These dependencies are required for the build:
5959
$ sudo dnf install -y \
6060
autoconf automake gcc git-core glibc-static go-md2man \
6161
libcap-devel libseccomp-devel libtool make pkg-config \
62-
python python-libmount systemd-devel yajl-devel
62+
python python-libmount systemd-devel yajl-devel \
63+
numactl-devel
6364
```
6465

6566
### RHEL/CentOS Stream 9
@@ -69,7 +70,8 @@ $ sudo dnf config-manager --set-enabled crb
6970
$ sudo dnf install -y \
7071
autoconf automake gcc git-core glibc-static go-md2man \
7172
libcap-devel libseccomp-devel libtool make pkg-config \
72-
python python-libmount systemd-devel yajl-devel
73+
python python-libmount systemd-devel yajl-devel \
74+
numactl-devel
7375
```
7476

7577
### RHEL/CentOS Stream 10
@@ -79,7 +81,7 @@ $ sudo dnf config-manager --set-enabled crb
7981
$ sudo dnf install -y \
8082
autoconf automake gcc git-core glibc-static go-md2man \
8183
libcap-devel libseccomp-devel libtool make pkg-config \
82-
python python-libmount systemd-devel
84+
python python-libmount systemd-devel numactl-devel
8385
```
8486

8587
NOTE that you need to add `--enable-embedded-yajl` to `./configure` flags below.
@@ -89,22 +91,23 @@ NOTE that you need to add `--enable-embedded-yajl` to `./configure` flags below.
8991
```console
9092
$ sudo apt-get install -y make git gcc build-essential pkgconf libtool \
9193
libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev \
92-
go-md2man autoconf python3 automake
94+
go-md2man autoconf python3 automake libnuma-dev
9395
```
9496

9597
### Alpine
9698

9799
```console
98100
# apk add gcc automake autoconf libtool gettext pkgconf git make musl-dev \
99-
python3 libcap-dev libseccomp-dev yajl-dev argp-standalone go-md2man
101+
python3 libcap-dev libseccomp-dev yajl-dev argp-standalone go-md2man \
102+
numactl-dev
100103
```
101104

102105
### Tumbleweed
103106

104107
```console
105108
# zypper install make automake autoconf gettext libtool gcc libcap-devel \
106109
systemd-devel libyajl-devel libseccomp-devel python3 go-md2man \
107-
glibc-static;
110+
glibc-static libnuma-devel;
108111
```
109112

110113
Note that Tumbleweed requires you to specify libseccomp's header file location

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ AS_IF([test "x$enable_systemd" != "xno"], [
173173
])
174174
])
175175

176+
dnl numa
177+
AC_ARG_ENABLE([numa],
178+
AS_HELP_STRING([--disable-numa], [Ignore numa and disable support]))
179+
AS_IF([test "x$enable_numa" != "xno"], [
180+
AC_CHECK_HEADERS([numaif.h], [], [AC_MSG_ERROR([*** Missing numa interface headers])])
181+
])
182+
176183
dnl ebpf
177184
AC_ARG_ENABLE([bpf],
178185
AS_HELP_STRING([--disable-bpf], [Ignore eBPF and disable support]))

nix/derivation.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with pkgs; stdenv.mkDerivation {
3030
libseccomp
3131
libsystemd
3232
yajl
33+
numactl
3334
] ++ lib.optionals enableCriu [ criu ];
3435
configureFlags = [ "--enable-static" ] ++ lib.optional (!enableSystemd) [ "--disable-systemd" ];
3536
prePatch = ''

nix/overlay.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ self: super:
2828
libassuan = (static super.libassuan);
2929
libgpgerror = (static super.libgpgerror);
3030
libseccomp = (static super.libseccomp);
31+
numactl = (static super.numactl);
3132
libcap = (static super.libcap).overrideAttrs (x: {
3233
postInstall = ''
3334
mkdir -p "$doc/share/doc/${x.pname}-${x.version}"

rpm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif
1010
srpm-dep:
1111
$(SUDO_CMD) dnf -y install autoconf automake git git-archive-all \
1212
libcap-devel libseccomp-devel libtool m4 rpm-build systemd-devel \
13-
yajl-devel
13+
yajl-devel numactl-devel
1414

1515
.ONESHELL:
1616
tarball-prep: srpm-dep

rpm/crun.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ BuildRequires: wasmedge-devel
7474
%endif
7575
BuildRequires: python
7676
BuildRequires: glibc-static
77+
BuildRequires: numactl-devel
7778
Provides: oci-runtime
7879

7980
%description

0 commit comments

Comments
 (0)