Skip to content

Commit

Permalink
memory: remove libnuma dependency
Browse files Browse the repository at this point in the history
Seastar is currently pulling in all of libnuma to just invoke a single
syscall. Additionally since libnuma being LGPL licensed, it's simpler
to not include it as a dependency. Replace the call in numaif.h with
a direct syscall.

I'm assuming that once libnuma was depended on because it was a
dependency of hwloc, however, hwloc version 2 removed the dependency
on libnuma, so Seastar can too:
https://github.com/open-mpi/hwloc/blob/263908a2c1f21c0e221a8d1f6472daf3a1fc07b9/NEWS#L291
  • Loading branch information
rockwotj committed Feb 17, 2025
1 parent a3a22eb commit 56a28fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cooking_recipe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cooking_ingredient (nettle
BUILD_COMMAND <DISABLE>
INSTALL_COMMAND ${make_command} install)

# Also a direct dependency of Seastar.
# A dependency of DPDK.
cooking_ingredient (numactl
EXTERNAL_PROJECT_ARGS
URL https://github.com/numactl/numactl/releases/download/v2.0.12/numactl-2.0.12.tar.gz
Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ target_link_libraries (seastar-module
yaml-cpp::yaml-cpp
"$<BUILD_INTERFACE:Valgrind::valgrind>"
Threads::Threads)
if (Seastar_NUMA)
target_link_libraries (seastar-module
PRIVATE numactl::numactl)
endif ()
if (Seastar_HWLOC)
target_link_libraries (seastar-module
PRIVATE hwloc::hwloc)
Expand Down
34 changes: 25 additions & 9 deletions src/core/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ module;
#include <utility>
#include <boost/intrusive/list.hpp>
#include <sys/mman.h>
#include <sys/syscall.h>

#ifdef SEASTAR_HAVE_NUMA
#include <numaif.h>
#endif
#endif // !defined(SEASTAR_DEFAULT_ALLOCATOR)

#ifdef SEASTAR_MODULE
Expand Down Expand Up @@ -1832,6 +1830,23 @@ void configure_minimal() {
init_cpu_mem();
}

static long mbind(void *addr,
unsigned long len,
int mode,
const unsigned long *nodemask,
unsigned long maxnode,
unsigned flags) {
return syscall(
SYS_mbind,
reinterpret_cast<long>(addr),
len,
mode,
reinterpret_cast<long>(nodemask),
maxnode,
flags
);
}

internal::numa_layout
configure(std::vector<resource::memory> m, bool mbind,
bool transparent_hugepages,
Expand Down Expand Up @@ -1865,16 +1880,18 @@ configure(std::vector<resource::memory> m, bool mbind,
get_cpu_mem().replace_memory_backing(sys_alloc);
}
get_cpu_mem().resize(total, sys_alloc);
#ifdef SEASTAR_HAVE_NUMA
size_t pos = 0;
for (auto&& x : m) {
unsigned long nodemask = 1UL << x.nodeid;
if (mbind) {
auto start = get_cpu_mem().mem() + pos;
auto r = ::mbind(start, x.bytes,
MPOL_PREFERRED,
&nodemask, std::numeric_limits<unsigned long>::digits,
MPOL_MF_MOVE);
static constexpr int mpol_preferred = 1;
static constexpr unsigned int mpol_mf_move = 2;
auto r = seastar::memory::mbind(
start, x.bytes,
mpol_preferred,
&nodemask, std::numeric_limits<unsigned long>::digits,
mpol_mf_move);

if (r == -1) {
char err[1000] = {};
Expand All @@ -1890,7 +1907,6 @@ configure(std::vector<resource::memory> m, bool mbind,
}
pos += x.bytes;
}
#endif
return ret_layout;
}

Expand Down

0 comments on commit 56a28fa

Please sign in to comment.