DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize
Date: Tue,  8 Mar 2016 18:29:31 -0800	[thread overview]
Message-ID: <1457490571-24429-1-git-send-email-stephen@networkplumber.org> (raw)

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

             reply	other threads:[~2016-03-09  2:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09  2:29 Stephen Hemminger [this message]
2016-03-09 17:49 ` Olivier MATZ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457490571-24429-1-git-send-email-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).