New upstream version 17.08
[deb_dpdk.git] / lib / librte_eal / common / eal_common_memory.c
index 6155752..996877e 100644 (file)
@@ -35,7 +35,9 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <unistd.h>
 #include <inttypes.h>
+#include <sys/mman.h>
 #include <sys/queue.h>
 
 #include <rte_memory.h>
@@ -135,6 +137,16 @@ rte_eal_memdevice_init(void)
        return 0;
 }
 
+/* Lock page in physical memory and prevent from swapping. */
+int
+rte_mem_lock_page(const void *virt)
+{
+       unsigned long virtual = (unsigned long)virt;
+       int page_size = getpagesize();
+       unsigned long aligned = (virtual & ~(page_size - 1));
+       return mlock((void *)aligned, page_size);
+}
+
 /* init memory subsystem */
 int
 rte_eal_memory_init(void)