From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by dpdk.org (Postfix) with ESMTP id 6BB8F2BE5 for ; Tue, 10 Jul 2018 13:18:31 +0200 (CEST) Received: by mail-ed1-f51.google.com with SMTP id d3-v6so16306681edi.1 for ; Tue, 10 Jul 2018 04:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=IQ9dSxftFbNb0A4FW9meEjy5zeuZBrzmUrnvW7a/ku8=; b=xNEt8LyrVP461DtkjRj0CCmItPcIsqQas0K/pW1+uXftFXMsYdnQoNP962iB53VBmF tXx0G2pib3673L4wVkNX1xYRFFBAqqfAsdF+W65BuGvbOdVnpqZByjxJ1p1gDmAUUfO/ +aCE7ZwXr5p3b4RUluvs8pmtZ6WKj9IWA2cbGeGwaeZYYQf2w7OWa6xrAHpckblnU1CS P7GfeH5C8PG7FtvRT7sLXyDIZsxIJ1/KQzRD1heedlVYIpDT/yn6/lfz31cF3K95m+iQ LbJVg7oLdlh1WvjpUT1HXlDiqer425vQhZZ6BKNZOWC1rTTLnQvJU2BS/qYiYo9Flslb J2rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=IQ9dSxftFbNb0A4FW9meEjy5zeuZBrzmUrnvW7a/ku8=; b=i6YvZwdE6m0vNmG0uZf0sZmlRL42M39gkw1X9ENTUzjN5J8Pz9Nu8GGk3wv5wAx5yB c1nXPlNAhLMzztAaxBLAGLHv94eaqzVWI2wB/ChKs0Uolm0f0XBPFCOm1c5fiN56Z9BK Y4fqmoJBPw8SfWaJedicYLIFMekXTu/aaXKrUPB3LxtfWDqd8w+m+ujTEAxdTil3V1ei Q1nwPxhyIOYAdLqkk+yUjxonUOsE8YsppQhWs/5010WSeXf3agYKRDbTWzAmLP5DncNO v6BcoQzy9VqVhwTZQuxF7NSQlBllAlmC2Fw+t92VM/Xu+ILjZ6f/EZH2sI0z65JB6waM VJwA== X-Gm-Message-State: APt69E3FfL4DN8g+qf5M3vcvbAWsoOvK77NLplbRhSpOo6HmhkUAbena 4wg8dwj8N9YDp/utfKEfS356zmKJp9Nt8j+lTKhD+w== X-Google-Smtp-Source: AAOMgpfMr3zWhcFbez3ap/rSBUIWC5RBh214rw7Q8Gnzuf/W7hPLjrNdL/CX9D+g7FgxK6+svCUjl4Izz7GSO9QNaRk= X-Received: by 2002:a50:8e09:: with SMTP id 9-v6mr4811567edw.101.1531221511229; Tue, 10 Jul 2018 04:18:31 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:b194:0:0:0:0:0 with HTTP; Tue, 10 Jul 2018 04:18:30 -0700 (PDT) In-Reply-To: References: From: Alejandro Lucero Date: Tue, 10 Jul 2018 12:18:30 +0100 Message-ID: To: Anatoly Burakov Cc: dev , srinath.mannam@broadcom.com, scott.branden@broadcom.com, Ajit Khaparde Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [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: , X-List-Received-Date: Tue, 10 Jul 2018 11:18:31 -0000 On Fri, Jul 6, 2018 at 2:17 PM, Anatoly Burakov wrote: > 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. > + */ > I do not clear understand when external segments can be used along with hugepages segments, but if this is a possibility, should not we support memseg walk for just external segments and also to allow any walk type as an API? If I'm right, it seems just memseg walk skipping external memsegs can be invoked from other files. > +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 */ > -- > 2.17.1 >