From: Olivier Matz Date: Wed, 18 May 2016 11:04:40 +0000 (+0200) Subject: mempool: get memory size with unspecified page size X-Git-Tag: spdx-start~6882 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=df25b24bde5b7c5d3a0693cbd43d09f8855ea503;p=dpdk.git mempool: get memory size with unspecified page size Update rte_mempool_xmem_size() so that when the page_shift argument is set to 0, assume that memory is physically contiguous, allowing to ignore page boundaries. This will be used in the next commits. By the way, rename the variable 'n' as 'obj_per_page' and avoid the affectation inside the if(). Signed-off-by: Olivier Matz --- diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 0d18511e5b..d5278b478e 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -253,18 +253,18 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz, uint32_t pg_shift) { - size_t n, pg_num, pg_sz, sz; + size_t obj_per_page, pg_num, pg_sz; - pg_sz = (size_t)1 << pg_shift; + if (pg_shift == 0) + return total_elt_sz * elt_num; - if ((n = pg_sz / total_elt_sz) > 0) { - pg_num = (elt_num + n - 1) / n; - sz = pg_num << pg_shift; - } else { - sz = RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * elt_num; - } + pg_sz = (size_t)1 << pg_shift; + obj_per_page = pg_sz / total_elt_sz; + if (obj_per_page == 0) + return RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * elt_num; - return sz; + pg_num = (elt_num + obj_per_page - 1) / obj_per_page; + return pg_num << pg_shift; } /* diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 0f900a1bde..53275e44ba 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -1261,7 +1261,7 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, * The size of each element, including header and trailer, as returned * by rte_mempool_calc_obj_size(). * @param pg_shift - * LOG2 of the physical pages size. + * LOG2 of the physical pages size. If set to 0, ignore page boundaries. * @return * Required memory size aligned at page boundary. */