DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize
@ 2016-03-09  2:29 Stephen Hemminger
  2016-03-09 17:49 ` Olivier MATZ
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2016-03-09  2:29 UTC (permalink / raw)
  To: dev

If page size is large (like 64K on ARM) and object size is small
then don't waste lots of memory by rounding up to page size.
Instead, round up so that 1 or more objects all fit in a page.

This preserves the requirement that an object must not a page
or virt2phys would break, and makes sure 62K is not wasted per mbuf.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_mempool/rte_mempool.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index f8781e1..8fa855a 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -300,18 +300,24 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
 	if (! rte_eal_has_hugepages()) {
 		/*
 		 * compute trailer size so that pool elements fit exactly in
-		 * a standard page
+		 * a standard page. If elements are smaller than a page
+		 * then allow multiple elements per page
 		 */
-		int page_size = getpagesize();
-		int new_size = page_size - sz->header_size - sz->elt_size;
-		if (new_size < 0 || (unsigned int)new_size < sz->trailer_size) {
+		unsigned page_size = getpagesize();
+		uint32_t orig_size, new_size;
+
+		orig_size = sz->header_size + sz->elt_size;
+		new_size = rte_align32pow2(orig_size);
+		if (new_size > page_size) {
 			printf("When hugepages are disabled, pool objects "
 			       "can't exceed PAGE_SIZE: %d + %d + %d > %d\n",
 			       sz->header_size, sz->elt_size, sz->trailer_size,
 			       page_size);
 			return 0;
 		}
-		sz->trailer_size = new_size;
+
+		sz->trailer_size = (new_size - orig_size)
+			/ (page_size / new_size);
 	}
 
 	/* this is the size of an object, including header and trailer */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize
  2016-03-09  2:29 [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize Stephen Hemminger
@ 2016-03-09 17:49 ` Olivier MATZ
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier MATZ @ 2016-03-09 17:49 UTC (permalink / raw)
  To: Stephen Hemminger, dev

On 03/09/2016 03:29 AM, Stephen Hemminger wrote:
> If page size is large (like 64K on ARM) and object size is small
> then don't waste lots of memory by rounding up to page size.
> Instead, round up so that 1 or more objects all fit in a page.
> 
> This preserves the requirement that an object must not a page
> or virt2phys would break, and makes sure 62K is not wasted per mbuf.

You should specify that it only affects runs with "--no-huge".


> --- a/lib/librte_mempool/rte_mempool.c
> +++ b/lib/librte_mempool/rte_mempool.c
> @@ -300,18 +300,24 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
>  	if (! rte_eal_has_hugepages()) {
>  		/*
>  		 * compute trailer size so that pool elements fit exactly in
> -		 * a standard page
> +		 * a standard page. If elements are smaller than a page
> +		 * then allow multiple elements per page
>  		 */
> -		int page_size = getpagesize();
> -		int new_size = page_size - sz->header_size - sz->elt_size;
> -		if (new_size < 0 || (unsigned int)new_size < sz->trailer_size) {
> +		unsigned page_size = getpagesize();
> +		uint32_t orig_size, new_size;
> +
> +		orig_size = sz->header_size + sz->elt_size;
> +		new_size = rte_align32pow2(orig_size);
> +		if (new_size > page_size) {
>  			printf("When hugepages are disabled, pool objects "
>  			       "can't exceed PAGE_SIZE: %d + %d + %d > %d\n",
>  			       sz->header_size, sz->elt_size, sz->trailer_size,
>  			       page_size);
>  			return 0;
>  		}
> -		sz->trailer_size = new_size;
> +
> +		sz->trailer_size = (new_size - orig_size)
> +			/ (page_size / new_size);
>  	}

Looks it does not work, did I miss something?

Examples:

# start with --no-huge
mp = rte_mempool_create("test", 128,
	35, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0);
rte_mempool_dump(stdout, mp);

shows:
  header_size=64
  elt_size=40
  trailer_size=0
  total_obj_size=104       <<<<< should be 128?


# start with --no-huge
mp = rte_mempool_create("test", 128,
	191, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY,
	MEMPOOL_F_NO_CACHE_ALIGN);
rte_mempool_dump(stdout, mp);

shows:
  header_size=8
  elt_size=192
  trailer_size=3
  total_obj_size=203       <<<<< should be 256?


The RFC I've just submitted also aims to fix this issue
(but differently).

Regards,
Olivier

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-09 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09  2:29 [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize Stephen Hemminger
2016-03-09 17:49 ` Olivier MATZ

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).