vfio: document multiprocess limitation for container API
[dpdk.git] / lib / librte_eal / common / malloc_elem.c
index fcdb181..658c9b5 100644 (file)
 #include "malloc_elem.h"
 #include "malloc_heap.h"
 
+/*
+ * If debugging is enabled, freed memory is set to poison value
+ * to catch buggy programs. Otherwise, freed memory is set to zero
+ * to avoid having to zero in zmalloc
+ */
+#ifdef RTE_MALLOC_DEBUG
+#define MALLOC_POISON         0x6b
+#else
+#define MALLOC_POISON         0
+#endif
+
 size_t
 malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align)
 {
@@ -38,6 +49,10 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align)
        /* segment must start after header and with specified alignment */
        contig_seg_start = RTE_PTR_ALIGN_CEIL(data_start, align);
 
+       /* return if aligned address is already out of malloc element */
+       if (contig_seg_start > data_end)
+               return 0;
+
        /* if we're in IOVA as VA mode, or if we're in legacy mode with
         * hugepages, all elements are IOVA-contiguous. however, we can only
         * make these assumptions about internal memory - externally allocated
@@ -490,7 +505,7 @@ malloc_elem_join_adjacent_free(struct malloc_elem *elem)
                join_elem(elem, elem->next);
 
                /* erase header, trailer and pad */
-               memset(erase, 0, erase_len);
+               memset(erase, MALLOC_POISON, erase_len);
        }
 
        /*
@@ -514,7 +529,7 @@ malloc_elem_join_adjacent_free(struct malloc_elem *elem)
                join_elem(new_elem, elem);
 
                /* erase header, trailer and pad */
-               memset(erase, 0, erase_len);
+               memset(erase, MALLOC_POISON, erase_len);
 
                elem = new_elem;
        }
@@ -545,7 +560,8 @@ malloc_elem_free(struct malloc_elem *elem)
        /* decrease heap's count of allocated elements */
        elem->heap->alloc_count--;
 
-       memset(ptr, 0, data_len);
+       /* poison memory */
+       memset(ptr, MALLOC_POISON, data_len);
 
        return elem;
 }