aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux/mem.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-02-07 23:28:41 +0000
committerDave Barach <openvpp@barachs.net>2020-02-11 15:53:13 +0000
commit6fe8998fefdc900af714a23d4152ffef9edbd3b4 (patch)
treee47f62a10b8d2d5f5c1316b091f6809b46f3f893 /src/vppinfra/linux/mem.c
parentfa2a316663e622a2feeecf8ad7d32b242370a70a (diff)
svm: numa awareness for ssvm segments
Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I999836a7893a89aac5243b111eac35fddd03e2a6
Diffstat (limited to 'src/vppinfra/linux/mem.c')
-rw-r--r--src/vppinfra/linux/mem.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 69ac871567c..3b7294f038a 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -386,21 +386,59 @@ done:
clib_error_t *
clib_mem_vm_ext_map (clib_mem_vm_map_t * a)
{
+ long unsigned int old_mask[16] = { 0 };
int mmap_flags = MAP_SHARED;
+ clib_error_t *err = 0;
+ int old_mpol = -1;
void *addr;
+ int rv;
+
+ if (a->numa_node)
+ {
+ rv = get_mempolicy (&old_mpol, old_mask, sizeof (old_mask) * 8 + 1, 0,
+ 0);
+
+ if (rv == -1)
+ {
+ err = clib_error_return_unix (0, "get_mempolicy");
+ goto done;
+ }
+ }
if (a->requested_va)
mmap_flags |= MAP_FIXED;
+ if (old_mpol != -1)
+ {
+ long unsigned int mask[16] = { 0 };
+ mask[0] = 1 << a->numa_node;
+ rv = set_mempolicy (MPOL_BIND, mask, sizeof (mask) * 8 + 1);
+ if (rv == -1)
+ {
+ err = clib_error_return_unix (0, "set_mempolicy");
+ goto done;
+ }
+ }
+
addr = (void *) mmap (uword_to_pointer (a->requested_va, void *), a->size,
PROT_READ | PROT_WRITE, mmap_flags, a->fd, 0);
if (addr == MAP_FAILED)
return clib_error_return_unix (0, "mmap");
+ /* re-apply old numa memory policy */
+ if (old_mpol != -1 &&
+ set_mempolicy (old_mpol, old_mask, sizeof (old_mask) * 8 + 1) == -1)
+ {
+ err = clib_error_return_unix (0, "set_mempolicy");
+ goto done;
+ }
+
a->addr = addr;
CLIB_MEM_UNPOISON (addr, a->size);
- return 0;
+
+done:
+ return err;
}
/*