Message ID | 1457557926-4056-1-git-send-email-stephen@networkplumber.org (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 96D2D2BD9; Wed, 9 Mar 2016 22:11:56 +0100 (CET) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by dpdk.org (Postfix) with ESMTP id 27BCD2BD3 for <dev@dpdk.org>; Wed, 9 Mar 2016 22:11:55 +0100 (CET) Received: by mail-pa0-f47.google.com with SMTP id td3so22473393pab.2 for <dev@dpdk.org>; Wed, 09 Mar 2016 13:11:55 -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=YjdRVXUAhN8r1WE6OMe9g6jrdpnvRbcRC2bD98Bb7sg=; b=XUmVrB0PEBcmn7XPjZzJhB6SKIRlE8Q5iveqFgCDWotJ2DHgfkWrOEdx7zSCuV7/Cl gbSNG+EQtxuOiOug0R04bH+S3L1w0g8yWiT+dbLIX9PMaRB2Yp+rDgkLcR4oMkFaSr8E PNpieRIXfeVT0a9NSpfQ7gnZNibSGn9kvRRKVQs1I7u679tp/IrjQWG+DzeEUgXyOTVN V5Z55c7dlikCxsrnn3MUTi4fqmrjd/zJiQ0sRnKejbgEsuYT7bE8/kxUNaNTg1GH1rwD u5OZWsR3z6eV2FWu/SX1CWLg35jaC7n/ASh8X8EjdmCyLAOp3mJkyNpe6aRukv2LuN4E H+ug== 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=YjdRVXUAhN8r1WE6OMe9g6jrdpnvRbcRC2bD98Bb7sg=; b=cD32HboEGPgtN6oLFdgRfCy+SHMzth6fznqx/qsa+kE7xtKxctOXHVhXPw9AiRTrVg pI2XrLgvyIG0eETiQcAXkMNpa734E/eS+2EJkMBPTnl+U58Uw/XepkCT0l2kdFkFgPyi jyO5Q8kMWeo9KyibQ7Oa2cv6HsHdSrxoESP8Utn4NPTAVATlmHdAhoSUF4loucPbUwWX qeSm444izOv776pNF5oFK/s5F0C+F/JOhzv/s/zrBorp2IHQORPDxqjYdTZtIVV+fo4v Ersud7ODDcCjGt3bMRGXxxoh7xGB0NSOUbT6P5/JCUaQmPNYTnCKtwWzXkfOEahrvAOR sBPA== X-Gm-Message-State: AD7BkJJg6KWD1VPaQd0DRzuOnd3pE8m3qe0XWwWIW0iSYCOHIZrT0mEzv2K1NFLJEhZ3Zg== X-Received: by 10.66.160.7 with SMTP id xg7mr559288pab.10.1457557914455; Wed, 09 Mar 2016 13:11:54 -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 qy7sm302816pab.34.2016.03.09.13.11.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Mar 2016 13:11:53 -0800 (PST) From: Stephen Hemminger <stephen@networkplumber.org> To: dev@dpdk.org Date: Wed, 9 Mar 2016 13:12:06 -0800 Message-Id: <1457557926-4056-1-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH, v2] 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 <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Stephen Hemminger
March 9, 2016, 9:12 p.m. UTC
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.
Also, fix invalid use of printf (versus log) for error reporting.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 - fix trailer_size calculation, and replace printf with log
lib/librte_mempool/rte_mempool.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
Comments
Hello, On 03/09/2016 10:12 PM, 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. > > Also, fix invalid use of printf (versus log) for error reporting. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > --- > v2 - fix trailer_size calculation, and replace printf with log > > lib/librte_mempool/rte_mempool.c | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c > index f8781e1..ff08a1a 100644 > --- a/lib/librte_mempool/rte_mempool.c > +++ b/lib/librte_mempool/rte_mempool.c > @@ -300,18 +300,23 @@ 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) { > - 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); > + unsigned new_size, orig_size, page_size; > + > + page_size = getpagesize(); > + orig_size = sz->header_size + sz->elt_size; > + new_size = rte_align32pow2(orig_size); > + if (new_size > page_size) { > + RTE_LOG(ERR, MEMPOOL, > + "When hugepages are disabled, pool objects " > + "can't exceed PAGE_SIZE: %u + %u + %u > %u\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; > } > > /* this is the size of an object, including header and trailer */ > It still does not work. When CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=y: mp = rte_mempool_create("test", 128, 64, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); rte_mempool_dump(stdout, mp); populated_size=128 header_size=64 elt_size=64 trailer_size=64 total_obj_size=192 Regards, Olivier
On 3/10/2016 8:37 AM, Olivier MATZ wrote: > Hello, > > On 03/09/2016 10:12 PM, 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. >> >> Also, fix invalid use of printf (versus log) for error reporting. >> >> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> >> --- >> v2 - fix trailer_size calculation, and replace printf with log >> >> lib/librte_mempool/rte_mempool.c | 23 ++++++++++++++--------- >> 1 file changed, 14 insertions(+), 9 deletions(-) >> >> diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c >> index f8781e1..ff08a1a 100644 >> --- a/lib/librte_mempool/rte_mempool.c >> +++ b/lib/librte_mempool/rte_mempool.c >> @@ -300,18 +300,23 @@ 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) { >> - 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); >> + unsigned new_size, orig_size, page_size; >> + >> + page_size = getpagesize(); >> + orig_size = sz->header_size + sz->elt_size; >> + new_size = rte_align32pow2(orig_size); >> + if (new_size > page_size) { >> + RTE_LOG(ERR, MEMPOOL, >> + "When hugepages are disabled, pool objects " >> + "can't exceed PAGE_SIZE: %u + %u + %u > %u\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; >> } >> >> /* this is the size of an object, including header and trailer */ >> > > It still does not work. When CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=y: > > mp = rte_mempool_create("test", 128, > 64, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); > rte_mempool_dump(stdout, mp); > > populated_size=128 > header_size=64 > elt_size=64 > trailer_size=64 > total_obj_size=192 > With --no-huge (since patch updates that part), it gives: header_size=64 elt_size=64 trailer_size=0 total_obj_size=128 private_data_size=3904 1- private_data still rounds to page size, not sure if this is a problem. 2- with MEMPOOL_DEBUG=y, trailer_size is 0, comment in code says it should keep cookie, not sure if this is a problem. Regards, ferruh
>> It still does not work. When CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=y: >> >> mp = rte_mempool_create("test", 128, >> 64, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); >> rte_mempool_dump(stdout, mp); >> >> populated_size=128 >> header_size=64 >> elt_size=64 >> trailer_size=64 >> total_obj_size=192 >> > With --no-huge (since patch updates that part), it gives: > header_size=64 > elt_size=64 > trailer_size=0 > total_obj_size=128 > private_data_size=3904 > > 1- private_data still rounds to page size, not sure if this is a problem. > 2- with MEMPOOL_DEBUG=y, trailer_size is 0, comment in code says it > should keep cookie, not sure if this is a problem. Yes the trailer should at least be 8 bytes to store the cookie.
On Thu, 10 Mar 2016 12:12:12 +0100 Olivier MATZ <olivier.matz@6wind.com> wrote: > >> It still does not work. When CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG=y: > >> > >> mp = rte_mempool_create("test", 128, > >> 64, 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); > >> rte_mempool_dump(stdout, mp); > >> > >> populated_size=128 > >> header_size=64 > >> elt_size=64 > >> trailer_size=64 > >> total_obj_size=192 > >> > > With --no-huge (since patch updates that part), it gives: > > header_size=64 > > elt_size=64 > > trailer_size=0 > > total_obj_size=128 > > private_data_size=3904 > > > > 1- private_data still rounds to page size, not sure if this is a problem. > > 2- with MEMPOOL_DEBUG=y, trailer_size is 0, comment in code says it > > should keep cookie, not sure if this is a problem. > > Yes the trailer should at least be 8 bytes to store the cookie. > Ok, will fix. that.
diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f8781e1..ff08a1a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -300,18 +300,23 @@ 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) { - 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); + unsigned new_size, orig_size, page_size; + + page_size = getpagesize(); + orig_size = sz->header_size + sz->elt_size; + new_size = rte_align32pow2(orig_size); + if (new_size > page_size) { + RTE_LOG(ERR, MEMPOOL, + "When hugepages are disabled, pool objects " + "can't exceed PAGE_SIZE: %u + %u + %u > %u\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; } /* this is the size of an object, including header and trailer */