mem: fix page fault trigger
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_memalloc.c
index 6f0eda5..f94f388 100644 (file)
@@ -146,7 +146,7 @@ resotre_numa(int *oldpolicy, struct bitmask *oldmask)
 {
        RTE_LOG(DEBUG, EAL,
                "Restoring previous memory policy: %d\n", *oldpolicy);
-       if (oldpolicy == MPOL_DEFAULT) {
+       if (*oldpolicy == MPOL_DEFAULT) {
                numa_set_localalloc();
        } else if (set_mempolicy(*oldpolicy, oldmask->maskp,
                                 oldmask->size + 1) < 0) {
@@ -466,7 +466,8 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
        }
        if (va != addr) {
                RTE_LOG(DEBUG, EAL, "%s(): wrong mmap() address\n", __func__);
-               goto mapped;
+               munmap(va, alloc_sz);
+               goto resized;
        }
 
        rte_iova_t iova = rte_mem_virt2iova(addr);
@@ -503,7 +504,12 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
        if (!internal_config.single_file_segments)
                close(fd);
 
-       *(int *)addr = *(int *)addr;
+       /* we need to trigger a write to the page to enforce page fault and
+        * ensure that page is accessible to us, but we can't overwrite value
+        * that is already there, so read the old value, and write itback.
+        * kernel populates the page with zeroes initially.
+        */
+       *(volatile int *)addr = *(volatile int *)addr;
 
        ms->addr = addr;
        ms->hugepage_sz = alloc_sz;