From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1on0094.outbound.protection.outlook.com [157.56.112.94]) by dpdk.org (Postfix) with ESMTP id 09D505A52 for ; Mon, 6 Jul 2015 10:53:13 +0200 (CEST) Received: from AMSPR02CA0045.eurprd02.prod.outlook.com (10.242.225.173) by VI1PR02MB0815.eurprd02.prod.outlook.com (10.162.14.152) with Microsoft SMTP Server (TLS) id 15.1.207.19; Mon, 6 Jul 2015 08:53:12 +0000 Received: from DB3FFO11FD008.protection.gbl (2a01:111:f400:7e04::163) by AMSPR02CA0045.outlook.office365.com (2a01:111:e400:8028::45) with Microsoft SMTP Server (TLS) id 15.1.207.19 via Frontend Transport; Mon, 6 Jul 2015 08:53:12 +0000 Authentication-Results: spf=fail (sender IP is 124.207.145.166) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of ezchip.com does not designate 124.207.145.166 as permitted sender) receiver=protection.outlook.com; client-ip=124.207.145.166; helo=bjgfarm-1.internal.tilera.com; Received: from bjgfarm-1.internal.tilera.com (124.207.145.166) by DB3FFO11FD008.mail.protection.outlook.com (10.47.216.97) with Microsoft SMTP Server (TLS) id 15.1.201.10 via Frontend Transport; Mon, 6 Jul 2015 08:53:10 +0000 Received: (from zlu@localhost) by bjgfarm-1.internal.tilera.com (8.14.4/8.14.4/Submit) id t668r6B2024551; Mon, 6 Jul 2015 16:53:06 +0800 From: Zhigang Lu To: Date: Mon, 6 Jul 2015 16:51:32 +0800 Message-ID: <1436172698-21749-8-git-send-email-zlu@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1436172698-21749-1-git-send-email-zlu@ezchip.com> References: <1436172698-21749-1-git-send-email-zlu@ezchip.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD008; 1:pho3dJ7c2mOvZck0jExTxM6PhQoyp35ttVn5EVl7G50e+bsnQbWG+HPaN0hDMQfu/U6fw9ss0nx0QzTZDSdpev/wffx4fikefl4BsuUMfv5/dsOZCJhe6MZpRonCf3eJOLFxy6oZ6f0zRB5it92uT1EhZGYZ2JicVMjoLMdiuSOYF0A/BpApE8RUgsDfRvAy7d6CphwDQ/vIrAw+FBN5tO0LASZJdwDEQUEDEx3vg9PkNhb0uYwyjglq9fWoHzWmyOH1Xzgh74olUU4K16dTHSy4PoZ3Xxf45feSTfj2MRrX7AQtb6bWPQKwGZgEXsXIS0kLv68cVXCE6Y3PTN/t3w== X-Forefront-Antispam-Report: CIP:124.207.145.166; CTRY:CN; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(339900001)(189002)(199003)(104016003)(5001960100002)(107886002)(575784001)(110136002)(86362001)(2351001)(2950100001)(76176999)(50986999)(106466001)(19580405001)(87936001)(6806004)(229853001)(189998001)(19580395003)(33646002)(50226001)(46102003)(36756003)(92566002)(105606002)(85426001)(62966003)(77156002)(42186005)(450100001)(47776003)(50466002)(48376002)(4001430100001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR02MB0815; H:bjgfarm-1.internal.tilera.com; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB0815; 2:2pxptVLpgTIU+alS5sjzPHQ8ZJgrj82bxRolinrK1VLUhtTy/1qOJxdUFNYZBCKE; 3:sjLyhiMV++Y7qAdeKopblDyea1WPkTOA2AIWb/n4DsE/FNeDmuztDq0wQnMOwlJTn/WChbxKXM7eDOJNoDluM1iByH3RpcmHyIOkjlslaxwWuiOOdr53nROEeDhg4kZTApgdTgdEDW6yTHnE/70RohdmswjwanxhiBCUDUrYb4dOifD+bSDRgxP7NN7Eajmg+b6AHTTd+b7ZberTM0HedI+mRsxoVOieSfZQ7JReE9R8vtULbXIhJY+4HBwcvdBc; 25:I+BIMj56Y0WhNtmnVSs3n2+67yH+ctlKcpj7AJuTWvds41KbHNzWUNli80Na2QDVyIBhYlSiZltHCB1gkguCpY07PkqxwsyEvmKP6lKgfFZsfa9qDKEigL+8CpILezZrCsGSmlfn5ZccBwORDFmCnkQAo3oXMCoLyYX5qg04RvCntqu1iIFGc09atxBegZVozTjceKZp60G0pewRRHy9D4VsAMJkeX//zKF38epIZF+bdQOr3Z6XTYabHPkArRw7X2sd2+tjpwYmp8r3OuJkbw==; 20:K0FAfyIfcFvxRpDvArfrEq4H8DE5ci6N5ZYrA4QMfI380EF0IsisOC/yWxxa/4inxMBB3z2WU79mCwbBo8r498rhhULoQhc1mkcupCdbA/zV+nn6qCb0KHxtOq8bhM0Wqlxx2QrjOjjuqyJ3vbvQ3BqCpNocZNNM/n+d7vaaEKg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB0815; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:VI1PR02MB0815; BCL:0; PCL:0; RULEID:; SRVR:VI1PR02MB0815; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB0815; 4:bX+QgQGX960Jn7EAfDnU0ednSaDg9sivupjOtp1NsYrSWcm1ZMwezGfrjjrEgvH2HlKGLHisCBGkmMoDYMMgwtyRJT5nQ9eYh5KMLjTBOPRzCX+6TfCgG8NYavIc9p0cidbNWFY66bz2dYM+9CPWo5fAHGFBEsHjYInFvlZMKV5UDIzWXJKsa+twep+/AmZmGtNDq+1Ga38TVopaV/RLtn3MyeMgaosmZxPd4dilaiT26GGj/taZ1OV11qLNUpTp+oTGlKvR3jsMv4p3QgZeS1Jk+vYIBiasQE0Oe6fbdGo= X-Forefront-PRVS: 06290ECA9D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR02MB0815; 23:HQ/sBtNkZiHoVIBM3EErr9NblKW+gWK5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qAw98rtQVjvQuKNWHzoUKl1nOz97a3BQAojLecVcQ?= =?us-ascii?Q?B9cMozopy0UeF+6dLZ9KnQXeBVdEuxmJMbWxs8S09KlUOTD0XqwIIUt1Ynum?= =?us-ascii?Q?Bo=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB0815; 5:+1RPAzH4OPXKJzb6av+99v723jZnUXhTVh2yGT6N8EzTouTV44qCD5GK4BmhIOZJufsLU5hgevCczpl8qlH7yTxm1Yc5Q8GluXUfLj1pBpzkK2ZeQz+W6GAkJOtH6p0C9QGvMJpCEMZGT03uKfMuzA==; 24:Gr0xu6/G5hu2TH3U9rUC8qjFALnoTPc3x01YWgHg0Hpn0dEyc5wOmTtDuWaNg7jqlhicg1slyCcP0B60UZCerbqVGPGaoEoHCxwQRTN42Es=; 20:aSAhrucgdXYgy2cuJxUg9PmHbVjoQA6bMWxRKijHwWJXP5MOQPZS76XghRi0roPiC6KS1RxlhqNDLndM/yIoDQ== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2015 08:53:10.6686 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3; Ip=[124.207.145.166]; Helo=[bjgfarm-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB0815 Subject: [dpdk-dev] [PATCH v3 07/12] memzone: allow multiple pagesizes to be requested 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: Mon, 06 Jul 2015 08:53:13 -0000 This patch extends the memzone allocator to remove the restriction that prevented callers from specifying multiple page sizes in the flags argument. In doing so, we also sanitize the free segment matching logic to get rid of architecture specific disjunctions (2MB vs 1GB on x86, and 16MB vs 16GB on PPC), thereby allowing for a broader range of hugepages on architectures that support it. Change-Id: Ic3713f61da49629a570fe4de34a8aaf5e2e0a19b Signed-off-by: Zhigang Lu --- lib/librte_eal/common/eal_common_memzone.c | 58 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 1ea502b..76bae72 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -113,7 +113,8 @@ align_phys_boundary(const struct rte_memseg *ms, size_t len, size_t align, static const struct rte_memzone * memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) + int socket_id, uint64_t size_mask, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; unsigned i = 0; @@ -201,18 +202,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, if ((requested_len + addr_offset) > free_memseg[i].len) continue; - /* check flags for hugepage sizes */ - if ((flags & RTE_MEMZONE_2MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_1G) - continue; - if ((flags & RTE_MEMZONE_1GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_2M) - continue; - if ((flags & RTE_MEMZONE_16MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16G) - continue; - if ((flags & RTE_MEMZONE_16GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16M) + if ((size_mask & free_memseg[i].hugepage_sz) == 0) continue; /* this segment is the best until now */ @@ -244,16 +234,6 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* no segment found */ if (memseg_idx == -1) { - /* - * If RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, - * try allocating again without the size parameter otherwise -fail. - */ - if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) && - ((flags & RTE_MEMZONE_1GB) || (flags & RTE_MEMZONE_2MB) - || (flags & RTE_MEMZONE_16MB) || (flags & RTE_MEMZONE_16GB))) - return memzone_reserve_aligned_thread_unsafe(name, - len, socket_id, 0, align, bound); - rte_errno = ENOMEM; return NULL; } @@ -302,13 +282,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } + uint64_t size_mask = 0; + + if (flags & RTE_MEMZONE_2MB) + size_mask |= RTE_PGSIZE_2M; + if (flags & RTE_MEMZONE_16MB) + size_mask |= RTE_PGSIZE_16M; + if (flags & RTE_MEMZONE_1GB) + size_mask |= RTE_PGSIZE_1G; + if (flags & RTE_MEMZONE_16GB) + size_mask |= RTE_PGSIZE_16G; + if (!size_mask) + size_mask = UINT64_MAX; /* get pointer to global configuration */ mcfg = rte_eal_get_configuration()->mem_config; @@ -316,7 +301,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, rte_rwlock_write_lock(&mcfg->mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); + name, len, socket_id, size_mask, align, bound); + + /* + * If we failed to allocate the requested page size, and the + * RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, try allocating + * again. + */ + if (!mz && rte_errno == ENOMEM && size_mask != UINT64_MAX && + flags & RTE_MEMZONE_SIZE_HINT_ONLY) { + mz = memzone_reserve_aligned_thread_unsafe( + name, len, socket_id, UINT64_MAX, align, bound); + } rte_rwlock_write_unlock(&mcfg->mlock); -- 2.1.2