When the process address space is insufficient,
mmap will fail, which will cause an infinite loop.
This patch stops attempting mmap if it fails and
the requested size cannot be reduced.

Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory")
Cc: sta...@dpdk.org

Signed-off-by: Dengdui Huang <huangdeng...@huawei.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozl...@gmail.com>
---
 lib/eal/common/eal_common_memory.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/eal/common/eal_common_memory.c 
b/lib/eal/common/eal_common_memory.c
index a185e0b580..0c997201bd 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -101,8 +101,12 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
 
                mapped_addr = eal_mem_reserve(
                        requested_addr, (size_t)map_sz, reserve_flags);
-               if ((mapped_addr == NULL) && allow_shrink)
-                       *size -= page_sz;
+               if (mapped_addr == NULL) {
+                       if (allow_shrink)
+                               *size -= page_sz;
+                       else
+                               break;
+               }
 
                if ((mapped_addr != NULL) && addr_is_hint &&
                                (mapped_addr != requested_addr)) {
-- 
2.33.0

Reply via email to