From patchwork Fri Jul 6 13:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatoly Burakov X-Patchwork-Id: 42502 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 03BCD1BEFF; Fri, 6 Jul 2018 15:17:47 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id BD8D71BE41 for ; Fri, 6 Jul 2018 15:17:36 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 06:17:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,316,1526367600"; d="scan'208";a="70160976" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 06 Jul 2018 06:17:33 -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 w66DHX3a027469; Fri, 6 Jul 2018 14:17:33 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w66DHXn0003746; Fri, 6 Jul 2018 14:17:33 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w66DHXNN003742; Fri, 6 Jul 2018 14:17:33 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: srinath.mannam@broadcom.com, scott.branden@broadcom.com, ajit.khaparde@broadcom.com Date: Fri, 6 Jul 2018 14:17:22 +0100 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [RFC 01/11] mem: allow memseg lists to be marked as external 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When we allocate and use DPDK memory, we need to be able to differentiate between DPDK hugepage segments and segments that were made part of DPDK but are externally allocated. Add such a property to memseg lists. Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/eal_common_memory.c | 51 ++++++++++++++++--- .../common/include/rte_eal_memconfig.h | 1 + lib/librte_eal/common/malloc_heap.c | 2 +- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 4f0688f9d..835bbffb6 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -24,6 +24,21 @@ #include "eal_private.h" #include "eal_internal_cfg.h" +/* forward declarations for memseg walk functions. we support external segments, + * but for some functionality to work, we need to either skip or not skip + * external segments. for example, while we expect for virt2memseg to return a + * valid memseg even though it's an external memseg, for regular memseg walk we + * want to skip those because the expectation is that we will only walk the + * DPDK allocated memory. + */ +static int +memseg_list_walk(rte_memseg_list_walk_t func, void *arg, bool skip_external); +static int +memseg_walk(rte_memseg_walk_t func, void *arg, bool skip_external); +static int +memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg, + bool skip_external); + /* * Try to mmap *size bytes in /dev/zero. If it is successful, return the * pointer to the mmap'd area and keep *size unmodified. Else, retry @@ -621,9 +636,9 @@ rte_mem_iova2virt(rte_iova_t iova) * as we know they are PA-contiguous as well */ if (internal_config.legacy_mem) - rte_memseg_contig_walk(find_virt_legacy, &vi); + memseg_contig_walk(find_virt_legacy, &vi, false); else - rte_memseg_walk(find_virt, &vi); + memseg_walk(find_virt, &vi, false); return vi.virt; } @@ -787,8 +802,8 @@ rte_mem_lock_page(const void *virt) return mlock((void *)aligned, page_size); } -int __rte_experimental -rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg) +static int +memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg, bool skip_external) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; int i, ms_idx, ret = 0; @@ -803,6 +818,8 @@ rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg) if (msl->memseg_arr.count == 0) continue; + if (skip_external && msl->external) + continue; arr = &msl->memseg_arr; @@ -837,7 +854,13 @@ rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg) } int __rte_experimental -rte_memseg_walk(rte_memseg_walk_t func, void *arg) +rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg) +{ + return memseg_contig_walk(func, arg, true); +} + +static int +memseg_walk(rte_memseg_walk_t func, void *arg, bool skip_external) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; int i, ms_idx, ret = 0; @@ -852,6 +875,8 @@ rte_memseg_walk(rte_memseg_walk_t func, void *arg) if (msl->memseg_arr.count == 0) continue; + if (skip_external && msl->external) + continue; arr = &msl->memseg_arr; @@ -875,7 +900,13 @@ rte_memseg_walk(rte_memseg_walk_t func, void *arg) } int __rte_experimental -rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg) +rte_memseg_walk(rte_memseg_walk_t func, void *arg) +{ + return memseg_walk(func, arg, true); +} + +static int +memseg_list_walk(rte_memseg_list_walk_t func, void *arg, bool skip_external) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; int i, ret = 0; @@ -888,6 +919,8 @@ rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg) if (msl->base_va == NULL) continue; + if (skip_external && msl->external) + continue; ret = func(msl, arg); if (ret < 0) { @@ -904,6 +937,12 @@ rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg) return ret; } +int __rte_experimental +rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg) +{ + return memseg_list_walk(func, arg, true); +} + /* init memory subsystem */ int rte_eal_memory_init(void) diff --git a/lib/librte_eal/common/include/rte_eal_memconfig.h b/lib/librte_eal/common/include/rte_eal_memconfig.h index aff0688dd..4e8720ba6 100644 --- a/lib/librte_eal/common/include/rte_eal_memconfig.h +++ b/lib/librte_eal/common/include/rte_eal_memconfig.h @@ -30,6 +30,7 @@ struct rte_memseg_list { uint64_t addr_64; /**< Makes sure addr is always 64-bits */ }; + bool external; /**< true if this list points to external memory */ int socket_id; /**< Socket ID for all memsegs in this list. */ uint64_t page_sz; /**< Page size for all memsegs in this list. */ volatile uint32_t version; /**< version number for multiprocess sync. */ diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index d6cf3af81..8a1f54905 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -631,7 +631,7 @@ malloc_heap_free(struct malloc_elem *elem) ret = 0; /* ...of which we can't avail if we are in legacy mode */ - if (internal_config.legacy_mem) + if (internal_config.legacy_mem || msl->external) goto free_unlock; /* check if we can free any memory back to the system */