On 4/1/20 6:11 AM, Anatoly Burakov wrote:
Due to the fact that the rte_realloc() test depends on the layout of
underlying memory, it can sometimes fail due to fragmentation of the
memory. To address this, make it so that the realloc autotests are run
using a newly created external memory heap instead of main memory.

Bugzilla ID: 424

Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com>
...
+static int
+test_realloc(void)
+{
+       const char *heap_name = "realloc_heap";
+       int realloc_heap_socket;
+       unsigned int mem_sz = 1U << 13; /* 8K */
+       unsigned int page_sz = sysconf(_SC_PAGESIZE);
+       void *mem;
+       int ret;
+
+       /*
+        * the realloc tests depend on specific layout of underlying memory, so
+        * to prevent accidental failures to do fragmented main heap, we will
+        * do all of our tests on an artificially created memory.
+        */
+       if (rte_malloc_heap_create(heap_name) != 0) {
+               printf("Failed to create external heap\n");
+               ret = -1;
+               goto end;
+       }
+       realloc_heap_socket = rte_malloc_heap_get_socket(heap_name);
+
+       mem = mmap(NULL, mem_sz, PROT_READ | PROT_WRITE,
+                       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+       if (mem == MAP_FAILED) {
+               printf("Failed to allocate memory for external heap\n");
+               ret = -1;
+               goto heap_destroy;
+       }
+
+       if (rte_malloc_heap_memory_add(
+                       heap_name, mem, mem_sz, NULL, 0, page_sz) != 0) {
+               printf("Failed to add memory to external heap\n");
+               ret = -1;
+               goto mem_free;
+       }
+
+       /* run the socket-bound tests */
+       ret = test_realloc_socket(realloc_heap_socket);
+
+       if (ret != 0)
+               goto mem_remove;
+
+       /* now, run the NUMA node tests */
+       ret = test_realloc_numa();
+
+mem_remove:
+       rte_malloc_heap_memory_remove(heap_name, mem, mem_sz);
+mem_free:
+       munmap(mem, mem_sz);
+heap_destroy:
+       rte_malloc_heap_destroy(heap_name);
+end:
        return ret;
  }


Works on an x86_64 Lenovo server which was previously failing. Still fails on a Power 9 system but with a new error:

RTE>>malloc_autotest
test_str_to_size() passed
test_zero_aligned_alloc() passed
test_malloc_bad_params() passed
Failed to add memory to external heap
test_realloc() failed
Test Failed

I'm guessing page_sz is the problem:

(gdb) s
rte_malloc_heap_memory_add (heap_name=0x11bceda0 "realloc_heap", va_addr=0x7ffff4c80000, len=8192, iova_addrs=0x0, n_pages=0, page_sz=65536)
    at ../lib/librte_eal/common/rte_malloc.c:358
358             struct malloc_heap *heap = NULL;
(gdb) n
363             if (heap_name == NULL || va_addr == NULL ||
(gdb) n
364                             page_sz == 0 || !rte_is_power_of_2(page_sz) ||
(gdb) n
365                             RTE_ALIGN(len, page_sz) != len ||
(gdb) n
364                             page_sz == 0 || !rte_is_power_of_2(page_sz) ||
(gdb) n
371                     rte_errno = EINVAL;

When I change page_sz to 4K the test succeeds.

Dave

Reply via email to