From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 0DBE75B2A for ; Thu, 28 Jun 2018 13:41:51 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2018 04:41:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,283,1526367600"; d="scan'208";a="50579577" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.fm.intel.com with ESMTP; 28 Jun 2018 04:41:51 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w5SBfnXs010613; Thu, 28 Jun 2018 12:41:49 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w5SBfnm3008961; Thu, 28 Jun 2018 12:41:49 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w5SBfnbO008957; Thu, 28 Jun 2018 12:41:49 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: Bruce Richardson Date: Thu, 28 Jun 2018 12:41:48 +0100 Message-Id: <385f43246053aaf19d2377dbb9f91dbf8c314e35.1530186042.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 2/3] eal/bsdapp: concatenate adjacent segments X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2018 11:41:52 -0000 Previously, memory allocator always left holes between mapped contigmem segments, even if they were IOVA-contiguous. Fix this by remembering last IOVA address and memseg index, and checking against those when mapping new contigmem segments. Signed-off-by: Anatoly Burakov --- Notes: v2: - Fix comparison when deciding if hole is needed lib/librte_eal/bsdapp/eal/eal_memory.c | 48 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c index ca06de2f8..7bf05c760 100644 --- a/lib/librte_eal/bsdapp/eal/eal_memory.c +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c @@ -104,6 +104,8 @@ rte_eal_hugepage_init(void) /* map all hugepages and sort them */ for (i = 0; i < internal_config.num_hugepage_sizes; i ++){ struct hugepage_info *hpi; + rte_iova_t prev_end = 0; + int prev_ms_idx = -1; uint64_t page_sz, mem_needed; unsigned int n_pages, max_pages; @@ -124,10 +126,27 @@ rte_eal_hugepage_init(void) int error; size_t sysctl_size = sizeof(physaddr); char physaddr_str[64]; + bool is_adjacent; + + /* first, check if this segment is IOVA-adjacent to + * the previous one. + */ + snprintf(physaddr_str, sizeof(physaddr_str), + "hw.contigmem.physaddr.%d", j); + error = sysctlbyname(physaddr_str, &physaddr, + &sysctl_size, NULL, 0); + if (error < 0) { + RTE_LOG(ERR, EAL, "Failed to get physical addr for buffer %u " + "from %s\n", j, hpi->hugedir); + return -1; + } + + is_adjacent = prev_end != 0 && physaddr == prev_end; + prev_end = physaddr + hpi->hugepage_sz; for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) { - bool empty; + bool empty, need_hole; msl = &mcfg->memsegs[msl_idx]; arr = &msl->memseg_arr; @@ -136,20 +155,23 @@ rte_eal_hugepage_init(void) empty = arr->count == 0; - /* we need 1, plus hole if not empty */ + /* we need a hole if this isn't an empty memseg + * list, and if previous segment was not + * adjacent to current one. + */ + need_hole = !empty && !is_adjacent; + + /* we need 1, plus hole if not adjacent */ ms_idx = rte_fbarray_find_next_n_free(arr, - 0, 1 + (empty ? 1 : 0)); + 0, 1 + (need_hole ? 1 : 0)); /* memseg list is full? */ if (ms_idx < 0) continue; - /* leave some space between memsegs, they are - * not IOVA contiguous, so they shouldn't be VA - * contiguous either. - */ - if (!empty) + if (need_hole && prev_ms_idx == ms_idx - 1) ms_idx++; + prev_ms_idx = ms_idx; break; } @@ -178,16 +200,6 @@ rte_eal_hugepage_init(void) return -1; } - snprintf(physaddr_str, sizeof(physaddr_str), "hw.contigmem" - ".physaddr.%d", j); - error = sysctlbyname(physaddr_str, &physaddr, &sysctl_size, - NULL, 0); - if (error < 0) { - RTE_LOG(ERR, EAL, "Failed to get physical addr for buffer %u " - "from %s\n", j, hpi->hugedir); - return -1; - } - seg->addr = addr; seg->iova = physaddr; seg->hugepage_sz = page_sz; -- 2.17.1