问题
DPDK 18.11 在使用 GCC 4.8.5 的 ASAN内存检测工具时,
程序会被卡住不动.
影响范围
解决 DPDK[18.11.rc1 – 19.02] 与 ASAN 4.8.5 内存冲突问题
#原因
ASAN 申请了地址空间 与 DPDK 申请的内存地址空间有重叠.
导致 DPDK 一直在 mmap/unmmap, 得不到期望的内存地址空间.
解决机制,如果得不到期望的地址空间, 就这样使用, 不再继续换地址空间.
解决办法
asan.diff1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index d47ea49..43f7828 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -24,7 +24,7 @@
#include "eal_memalloc.h"
#include "eal_private.h"
#include "eal_internal_cfg.h"
-
+#define MAX_MMAP_WITH_DEFINED_ADDR_TRIES 5
/*
* Try to mmap *size bytes in /dev/zero. If it is successful, return the
* pointer to the mmap'd area and keep *size unmodified. Else, retry
@@ -37,7 +37,7 @@
static void *next_baseaddr;
static uint64_t system_page_sz;
-
+static int warning_already = 0;
#ifdef RTE_ARCH_64
/*
* Linux kernel uses a really high address as starting address for serving
@@ -61,6 +61,7 @@
{
bool addr_is_hint, allow_shrink, unmap, no_align;
uint64_t map_sz;
+ uint32_t try = 0;
void *mapped_addr, *aligned_addr;
if (system_page_sz == 0)
@@ -112,16 +113,19 @@
mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ,
mmap_flags, -1, 0);
+ //printf("%s %d requested_addr:%p mapped_addr:%p\n", __func__, __LINE__, requested_addr, mapped_addr);
if (mapped_addr == MAP_FAILED && allow_shrink)
*size -= page_sz;
if (mapped_addr != MAP_FAILED && addr_is_hint &&
mapped_addr != requested_addr) {
- /* hint was not used. Try with another offset */
- munmap(mapped_addr, map_sz);
- mapped_addr = MAP_FAILED;
- next_baseaddr = RTE_PTR_ADD(next_baseaddr, page_sz);
- requested_addr = next_baseaddr;
+ try++;
+ next_baseaddr = RTE_PTR_ADD(next_baseaddr, page_sz);
+ if (try <= MAX_MMAP_WITH_DEFINED_ADDR_TRIES) {
+ munmap(mapped_addr, map_sz);
+ mapped_addr = MAP_FAILED;
+ requested_addr = next_baseaddr;
+ }
}
} while ((allow_shrink || addr_is_hint) &&
mapped_addr == MAP_FAILED && *size > 0);
@@ -152,9 +156,16 @@
return NULL;
} else if (requested_addr != NULL && addr_is_hint &&
aligned_addr != requested_addr) {
- RTE_LOG(WARNING, EAL, "WARNING! Base virtual address hint (%p != %p) not respected!\n",
- requested_addr, aligned_addr);
- RTE_LOG(WARNING, EAL, " This may cause issues with mapping memory into secondary processes\n");
+
+ if(0 == warning_already)
+ {
+ printf("ASAN 与 DPDK[18.11.rc1 -- 19.02] 的内存映射空间有冲突, 这个警告不用管.\n");
+ warning_already = 1;
+ }
+
+ //RTE_LOG(WARNING, EAL, "WARNING! Base virtual address hint (%p != %p) not respected!\n",
+ // requested_addr, aligned_addr);
+ //RTE_LOG(WARNING, EAL, " This may cause issues with mapping memory into secondary processes\n");
} else if (next_baseaddr != NULL) {
next_baseaddr = RTE_PTR_ADD(aligned_addr, *size);
}