mm/mbind: Introduce process_mbind() syscall for external memory binding
Subsystems (6)
RFC PATCH 1/1 mm/mbind: Introduce process_mbind() syscall for external memory binding
From: Vinicius Tavares Petrucci <[email protected]>
This patch introduces process_mbind() to enable a userspace orchestrator with an understanding of another process's memory layout to alter its memory policy. As system memory configurations become more and more complex (e.g., DDR+HBM+CXL memories), such a userspace orchestrator can explore more advanced techniques to guide memory placement to individual NUMA nodes across memory tiers. This allows for a more efficient allocation of memory resources, leading to enhanced application performance.
Alternatively, there are existing methods such as LD_PRELOAD (https://pmem.io/memkind/) or syscall_intercept (https://github.com/pmem/syscall_intercept), but these techniques, beyond the lack of portability/universality, can lead to system incompatibility issues, inconsistency in application behavior, potential risks due to global system-wide settings, and increased complexity in implementation.
The concept of an external entity that understands the layout of another process's VM is already present with process_madvise(). Thus, it seems reasonable to introduce the process_mbind variant of mbind. The implementation framework of process_mbind() is akin to process_madvise(). It uses pidfd of an external process to direct the memory policy and supports a vector of memory address ranges.
The general use case here is similar to the prior RFC pidfd_set_mempolicy()
(https://lore.kernel.org/linux-mm/[email protected]/),
but offers a more fine-grained external control by binding specific memory regions (say, heap data structures) to specific NUMA nodes. Another concrete use case was described by a prior work showing up to 2X runtime improvement (compared to AutoNUMA tiering) using memory object/region-based memory placement for workloads with irregular access patterns such as graph analytics: https://iiswc.org/iiswc2022/IISWC2022_42.pdf
The proposed API is as follows:
long process_mbind(int pidfd,
const struct iovec *iovec,
unsigned long vlen,
unsigned long mode,
const unsigned long *nmask,
unsigned int flags);
The pidfd argument is used to select the process that is identified by the PID file descriptor provided in pidfd. (See pidofd_open(2) for more information)
The pointer iovec points to an array of iovec structures (as described in <sys/uio.h>):
struct iovec {
void *iov_base; /* starting address of region */
size_t iov_len; /* size of region (in bytes) */
};
The iovec defines memory regions that start at the address (iov_base) and have a size measured in bytes (iov_len).
The vlen indicates the quantity of elements contained in iovec.
Please note the initial maxnode parameter from mbind was omitted to ensure the API doesn't exceed 6 arguments. Instead, the constant MAX_NUMNODES was utilized.
Please see the mbind(2) man page for more details about other's arguments.
Additionally, it is worth noting the following:
- Using a vector of address ranges as an argument in process_mbind provides more flexibility than the original mbind system call, even when invoked from a current or local process.
- In contrast to move_pages, which requires an array of fixed-size pages, process_mbind (with flags MPOL_MF_MOVE*) offers a more convinient and flexible page migration capability on a per object or region basis.
- Similar to process_madvise, manipulating the memory binding of external processes necessitates CAP_SYS_NICE and PTRACE_MODE_READ_FSCREDS checks (refer to ptrace(2)).
--- arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 4 ++ include/uapi/asm-generic/unistd.h | 4 +- kernel/sys_ni.c | 1 + mm/mempolicy.c | 86 +++++++++++++++++++++++++- 5 files changed, 92 insertions(+), 4 deletions(-)
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -378,6 +378,7 @@ 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait 456 common futex_requeue sys_futex_requeue +457 common process_mbind sys_process_mbind # # Due to a historical design error, certain syscalls are numbered differently
include/linux/syscalls.h +4 -0
@@ -816,6 +816,10 @@ asmlinkage long sys_mbind(unsigned long start, unsigned long len,const unsigned long __user *nmask, unsigned long maxnode, unsigned flags); +asmlinkage long sys_process_mbind (int pidfd,const struct iovec __user *vec, +size_t vlen,unsigned long mode, +const unsigned long __user *nmask, +unsigned flags); asmlinkage long sys_get_mempolicy(int __user *policy, unsigned long __user *nmask, unsigned long maxnode,
include/uapi/asm-generic/unistd.h +3 -1
@@ -828,9 +828,11 @@ __SYSCALL(__NR_futex_wake, sys_futex_wake) __SYSCALL(__NR_futex_wait, sys_futex_wait)#define __NR_futex_requeue 456 __SYSCALL(__NR_futex_requeue, sys_futex_requeue) +#define __NR_process_mbind 457 +__SYSCALL(__NR_process_mbind, sys_process_mbind)#undef __NR_syscalls -#define __NR_syscalls 457 +#define __NR_syscalls 458/* * 32 bit systems traditionally used different
kernel/sys_ni.c +1 -0
@@ -187,6 +187,7 @@ COND_SYSCALL(process_madvise);COND_SYSCALL (process_mrelease);COND_SYSCALL (remap_file_pages);COND_SYSCALL (mbind); +COND_SYSCALL (process_mbind);COND_SYSCALL (get_mempolicy);COND_SYSCALL (set_mempolicy);COND_SYSCALL (migrate_pages);
mm/mempolicy.c +83 -3
117 lines not on this page · raw message
Signature · 1 line
2.41.0