From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by dpdk.org (Postfix) with ESMTP id C8020FFA for ; Wed, 9 Mar 2016 03:29:31 +0100 (CET) Received: by mail-pf0-f176.google.com with SMTP id x188so27334286pfb.2 for ; Tue, 08 Mar 2016 18:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=1XuIeTAI+yJr+FS6v0ea+pulN+7TQy8Yrd8gT37Uu8k=; b=nLHzZbMjbDSrZCogF3bgpAmvVAyCTmH6adbOVajJNO+tWkayVYxT+bJhzbv0ag4oSu UzbbP4RxwU/trV4n/fW3BrbcQ6DC6eODU36DzVxEVO2MoRPGKih1LeE2tB4i5+VOoIca Dk0iPTQVnUp1BkxDNJE6RU7l16C0vZeAf+aKoRmMHZmsqvZSBEBOe8Vss3f1lVrkJJ7g tkmhDF4ziDAY5qNHRYzz7xFFTjGENo2FJg75pC7TB8/GfUuOjLdCKXe6ZXxVih2WIF2I GODkFc7sa+zpacPNgnpOID5sO/YnP+8Nv5TafJma24RMf6gicqqXeWIloa+2yCqcdGdg JCJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1XuIeTAI+yJr+FS6v0ea+pulN+7TQy8Yrd8gT37Uu8k=; b=JW0j7pUfkcAb1lv5QInw6AnNIrtHlweH0G2hmygYMbDcXvpwdI59NMxmC+BWTpIpif nQWRb4+vEhwx+VpY5jpxDq8fYptNsPPn2qCdp0KC6DegumjvcgcGemiRdN7GX3YEzlkB doDzlfs9rh/3zRHWeWrbASj46U/KrmNE3/eprVHMdzJwhUs/XhYi0/XucPJPCVLC1koe 0tsdqwqu3mkrPRrPsrXGz17VgcGDz/eZk9R6H1ADOS6TZsyoskSZFx1VbThSEAMT66rS gb1eiQLQFoBF35zog+5C4nw67vYg0GyUfDOMduG9GEolnDgQ43l3+o5Ki3SnHP2WgIw/ mJtA== X-Gm-Message-State: AD7BkJIj+oGlKiyplS6Ozc8tozOi8PXK4RKMU9LvTndbGgQXvmn3nTDMbq3yAOoA9/cDLg== X-Received: by 10.98.42.150 with SMTP id q144mr46779525pfq.73.1457490571098; Tue, 08 Mar 2016 18:29:31 -0800 (PST) Received: from xeon-e3.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by smtp.gmail.com with ESMTPSA id g23sm5477020pfg.35.2016.03.08.18.29.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 18:29:24 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Date: Tue, 8 Mar 2016 18:29:31 -0800 Message-Id: <1457490571-24429-1-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] mempool: avoid memory waste with large pagesize X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2016 02:29:32 -0000 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 --- 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