From patchwork Fri Dec 9 17:55:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikolova, Tatyana E" X-Patchwork-Id: 9468819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D185460586 for ; Fri, 9 Dec 2016 17:55:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7C0E285A1 for ; Fri, 9 Dec 2016 17:55:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC9D828683; Fri, 9 Dec 2016 17:55:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5048E285A1 for ; Fri, 9 Dec 2016 17:55:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752609AbcLIRzk (ORCPT ); Fri, 9 Dec 2016 12:55:40 -0500 Received: from mga02.intel.com ([134.134.136.20]:5784 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752591AbcLIRzi (ORCPT ); Fri, 9 Dec 2016 12:55:38 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP; 09 Dec 2016 09:55:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,324,1477983600"; d="scan'208";a="40919153" Received: from tenikolo-mobl2.amr.corp.intel.com ([10.122.41.238]) by fmsmga006.fm.intel.com with ESMTP; 09 Dec 2016 09:55:37 -0800 From: Tatyana Nikolova To: jgunthorpe@obsidianresearch.com, dledford@redhat.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, e1000-rdma@lists.sourceforge.net Subject: [PATCH 09/10] i40iw: Use 2M huge pages for CQ/QP memory if available Date: Fri, 9 Dec 2016 11:55:03 -0600 Message-Id: <1481306104-19352-10-git-send-email-tatyana.e.nikolova@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481306104-19352-1-git-send-email-tatyana.e.nikolova@intel.com> References: <1481306104-19352-1-git-send-email-tatyana.e.nikolova@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shiraz Saleem Attempt to allocate a 2M huge page from the pool for QP/CQ memory if its size is > 4K and < 2M. This will lead to physically contiguous QP/CQ memory and avoid the use of PBLs. The total number of 2M huge pages available for this feature is controlled by a user environment variable, I40IW_MAX_HUGEPGCNT, with an upper limit of 100, and 0 if invalid values are used. Signed-off-by: Shiraz Saleem Signed-off-by: Tatyana Nikolova --- providers/i40iw/i40iw_umain.c | 10 +++++++++ providers/i40iw/i40iw_umain.h | 4 ++++ providers/i40iw/i40iw_uverbs.c | 46 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/providers/i40iw/i40iw_umain.c b/providers/i40iw/i40iw_umain.c index a204859..b2e6236 100644 --- a/providers/i40iw/i40iw_umain.c +++ b/providers/i40iw/i40iw_umain.c @@ -47,6 +47,7 @@ #include "i40iw-abi.h" unsigned int i40iw_dbg; +unsigned int i40iw_max_hugepgcnt; #include #include @@ -241,6 +242,15 @@ found: if (env_val) i40iw_dbg = atoi(env_val); + env_val = getenv("I40IW_MAX_HUGEPGCNT"); + if (env_val) { + if ((atoi(env_val) < 0) || (atoi(env_val) > 100)) + fprintf(stderr, PFX "%s: Valid range for Max Huge Page Count is 0 to 100. Setting to 0\n", + __func__); + else + i40iw_max_hugepgcnt = atoi(env_val); + } + dev = malloc(sizeof(*dev)); if (!dev) { i40iw_debug("failed to allocate memory for device object\n"); diff --git a/providers/i40iw/i40iw_umain.h b/providers/i40iw/i40iw_umain.h index 889c006..7bcd197 100644 --- a/providers/i40iw/i40iw_umain.h +++ b/providers/i40iw/i40iw_umain.h @@ -72,6 +72,8 @@ #define I40E_DB_SHADOW_AREA_SIZE 64 #define I40E_DB_CQ_OFFSET 0x40 +#define I40IW_HPAGE_SIZE_2M (2 * 1024 * 1024) + extern unsigned int i40iw_dbg; #define i40iw_debug(fmt, args...) \ do { \ @@ -120,6 +122,7 @@ struct i40iw_ucq { int comp_vector; struct i40iw_uqp *udqp; struct i40iw_cq_uk cq; + bool is_hugetlb; }; struct i40iw_uqp { @@ -138,6 +141,7 @@ struct i40iw_uqp { uint32_t wq_size; struct ibv_recv_wr *pend_rx_wr; struct i40iw_qp_uk qp; + bool is_hugetlb; }; diff --git a/providers/i40iw/i40iw_uverbs.c b/providers/i40iw/i40iw_uverbs.c index 464900b..85ed77c 100644 --- a/providers/i40iw/i40iw_uverbs.c +++ b/providers/i40iw/i40iw_uverbs.c @@ -51,6 +51,9 @@ #include "i40iw_umain.h" #include "i40iw-abi.h" +unsigned int i40iw_hugepgcnt; +extern unsigned int i40iw_max_hugepgcnt; + /** * i40iw_uquery_device - call driver to query device for max resources * @context: user context for the device @@ -248,11 +251,24 @@ struct ibv_cq *i40iw_ucreate_cq(struct ibv_context *context, int cqe, cq_pages = i40iw_num_of_pages(info.cq_size * cqe_struct_size); totalsize = (cq_pages << 12) + I40E_DB_SHADOW_AREA_SIZE; + if ((totalsize > I40IW_HW_PAGE_SIZE) && (totalsize <= I40IW_HPAGE_SIZE_2M)) { + if (i40iw_hugepgcnt < i40iw_max_hugepgcnt) { + info.cq_base = mmap(NULL, I40IW_HPAGE_SIZE_2M, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, 0, 0); + if (info.cq_base != MAP_FAILED) { + iwucq->is_hugetlb = true; + i40iw_hugepgcnt++; + goto cqmem_alloc_done; + } + } + } + info.cq_base = memalign(I40IW_HW_PAGE_SIZE, totalsize); if (!info.cq_base) goto err; +cqmem_alloc_done: memset(info.cq_base, 0, totalsize); info.shadow_area = (u64 *)((u8 *)info.cq_base + (cq_pages << 12)); reg_mr_cmd.reg_type = I40IW_UMEMREG_TYPE_CQ; @@ -315,7 +331,13 @@ int i40iw_udestroy_cq(struct ibv_cq *cq) ibv_cmd_dereg_mr(&iwucq->mr); - free(iwucq->cq.cq_base); + if (iwucq->is_hugetlb) { + munmap(iwucq->cq.cq_base, I40IW_HPAGE_SIZE_2M); + i40iw_hugepgcnt--; + } else { + free(iwucq->cq.cq_base); + } + free(iwucq); return 0; @@ -481,7 +503,13 @@ static int i40iw_destroy_vmapped_qp(struct i40iw_uqp *iwuqp, munmap(iwuqp->push_wqe, I40IW_HW_PAGE_SIZE); ibv_cmd_dereg_mr(&iwuqp->mr); - free((void *)sq_base); + + if (iwuqp->is_hugetlb) { + munmap((void *)sq_base, I40IW_HPAGE_SIZE_2M); + i40iw_hugepgcnt--; + } else { + free((void *)sq_base); + } return 0; } @@ -519,6 +547,19 @@ static int i40iw_vmapped_qp(struct i40iw_uqp *iwuqp, struct ibv_pd *pd, sqsize = sq_pages << 12; rqsize = rq_pages << 12; totalqpsize = rqsize + sqsize + I40E_DB_SHADOW_AREA_SIZE; + + if ((totalqpsize > I40IW_HW_PAGE_SIZE) && (totalqpsize <= I40IW_HPAGE_SIZE_2M)) { + if (i40iw_hugepgcnt < i40iw_max_hugepgcnt) { + info->sq = mmap(NULL, I40IW_HPAGE_SIZE_2M, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, 0, 0); + if (info->sq != MAP_FAILED) { + iwuqp->is_hugetlb = true; + i40iw_hugepgcnt++; + goto qpmem_alloc_done; + } + } + } + info->sq = memalign(I40IW_HW_PAGE_SIZE, totalqpsize); if (!info->sq) { @@ -526,6 +567,7 @@ static int i40iw_vmapped_qp(struct i40iw_uqp *iwuqp, struct ibv_pd *pd, return 0; } +qpmem_alloc_done: memset(info->sq, 0, totalqpsize); info->rq = &info->sq[sqsize / I40IW_QP_WQE_MIN_SIZE]; info->shadow_area = info->rq[rqsize / I40IW_QP_WQE_MIN_SIZE].elem;