From: Jonas Pfefferle Date: Tue, 31 Oct 2017 09:08:29 +0000 (+0100) Subject: mem: warn if address hint is not respected X-Git-Tag: spdx-start~728 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=7eafccfa9dfbaa82ed5c8622dd64daf34d6ff342;p=dpdk.git mem: warn if address hint is not respected Print a warning if the --base-virtaddr hint is not respected since this might lead to problems when mapping memory in the secondary process. Signed-off-by: Jonas Pfefferle Acked-by: Anatoly Burakov --- diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 16a181c361..a57c912fab 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -261,33 +261,44 @@ static void * get_virtual_area(size_t *size, size_t hugepage_sz) { void *addr; + void *addr_hint; int fd; long aligned_addr; if (internal_config.base_virtaddr != 0) { - addr = (void*) (uintptr_t) (internal_config.base_virtaddr + - baseaddr_offset); + int page_size = sysconf(_SC_PAGE_SIZE); + addr_hint = (void *) (uintptr_t) + (internal_config.base_virtaddr + baseaddr_offset); + addr_hint = RTE_PTR_ALIGN_FLOOR(addr_hint, page_size); + } else { + addr_hint = NULL; } - else addr = NULL; RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zx bytes\n", *size); + fd = open("/dev/zero", O_RDONLY); if (fd < 0){ RTE_LOG(ERR, EAL, "Cannot open /dev/zero\n"); return NULL; } do { - addr = mmap(addr, - (*size) + hugepage_sz, PROT_READ, + addr = mmap(addr_hint, (*size) + hugepage_sz, PROT_READ, #ifdef RTE_ARCH_PPC_64 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, #else MAP_PRIVATE, #endif fd, 0); - if (addr == MAP_FAILED) + if (addr == MAP_FAILED) { *size -= hugepage_sz; + } else if (addr_hint != NULL && addr != addr_hint) { + RTE_LOG(WARNING, EAL, "WARNING! Base virtual address " + "hint (%p != %p) not respected!\n", + addr_hint, addr); + RTE_LOG(WARNING, EAL, " This may cause issues with " + "mapping memory into secondary processes\n"); + } } while (addr == MAP_FAILED && *size > 0); if (addr == MAP_FAILED) {