[dpdk-dev] [PATCH v2 2/2] memzone: allow IOVA-contiguous memzones with zero size

Anatoly Burakov anatoly.burakov at intel.com
Thu Apr 26 10:06:47 CEST 2018


Previously, reserving IOVA-contiguous memzones with zero
size (which would reserve biggest available memzone) was
not allowed. Now that we can have biggest IOVA-contiguous
malloc element statistic exposed through a malloc stats
call, this now becomes possible.

Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---

Notes:
    v2:
    - Fixed checkpatch warning for unsigned

 lib/librte_eal/common/eal_common_memzone.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c
index bce3321..9cc9961 100644
--- a/lib/librte_eal/common/eal_common_memzone.c
+++ b/lib/librte_eal/common/eal_common_memzone.c
@@ -57,7 +57,7 @@ memzone_lookup_thread_unsafe(const char *name)
  * specified. If no heap has been specified, it will return the heap and
  * length of the greatest free block available in all heaps */
 static size_t
-find_heap_max_free_elem(int *s, unsigned align)
+find_heap_max_free_elem(int *s, unsigned int align, bool contig)
 {
 	struct rte_mem_config *mcfg;
 	struct rte_malloc_socket_stats stats;
@@ -68,12 +68,16 @@ find_heap_max_free_elem(int *s, unsigned align)
 	mcfg = rte_eal_get_configuration()->mem_config;
 
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
+		size_t found_len;
 		if ((socket != SOCKET_ID_ANY) && (socket != i))
 			continue;
 
 		malloc_heap_get_stats(&mcfg->malloc_heaps[i], &stats);
-		if (stats.greatest_free_size > len) {
-			len = stats.greatest_free_size;
+		found_len = contig ?
+				stats.greatest_free_iova_contig_size :
+				stats.greatest_free_size;
+		if (found_len > len) {
+			len = found_len;
 			*s = i;
 		}
 	}
@@ -166,16 +170,11 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
 	flags &= ~RTE_MEMZONE_IOVA_CONTIG;
 
 	if (len == 0) {
-		/* len == 0 is only allowed for non-contiguous zones */
-		if (contig) {
-			RTE_LOG(DEBUG, EAL, "Reserving zero-length contiguous memzones is not supported\n");
-			rte_errno = EINVAL;
-			return NULL;
-		}
 		if (bound != 0)
 			requested_len = bound;
 		else {
-			requested_len = find_heap_max_free_elem(&socket_id, align);
+			requested_len = find_heap_max_free_elem(&socket_id,
+					align, contig);
 			if (requested_len == 0) {
 				rte_errno = ENOMEM;
 				return NULL;
-- 
2.7.4


More information about the dev mailing list