DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com,
	keith.wiles@intel.com, benjamin.walker@intel.com,
	bruce.richardson@intel.com, thomas@monjalon.net
Subject: [dpdk-dev] [PATCH 15/23] eal: add API to check if memory is physically contiguous
Date: Tue, 19 Dec 2017 11:04:41 +0000	[thread overview]
Message-ID: <23b3239ed0ad52d78d2c3a1fdb8dd19be69ecd51.1513680516.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1513680516.git.anatoly.burakov@intel.com>
In-Reply-To: <cover.1513680516.git.anatoly.burakov@intel.com>

This will be helpful down the line when we implement support for
allocating physically contiguous memory. We can no longer guarantee
physically contiguous memory unless we're in IOVA_AS_VA mode, but
we can certainly try and see if we succeed. In addition, this would
be useful for e.g. PMD's who may allocate chunks that are smaller
than the pagesize, but they must not cross the page boundary, in
which case we will be able to accommodate that request.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/eal_common_memalloc.c | 79 +++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_memalloc.h        |  5 ++
 lib/librte_eal/linuxapp/eal/Makefile        |  1 +
 3 files changed, 85 insertions(+)
 create mode 100755 lib/librte_eal/common/eal_common_memalloc.c

diff --git a/lib/librte_eal/common/eal_common_memalloc.c b/lib/librte_eal/common/eal_common_memalloc.c
new file mode 100755
index 0000000..395753a
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_memalloc.c
@@ -0,0 +1,79 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_lcore.h>
+#include <rte_fbarray.h>
+#include <rte_memzone.h>
+#include <rte_memory.h>
+#include <rte_eal_memconfig.h>
+
+#include "eal_private.h"
+#include "eal_internal_cfg.h"
+#include "eal_memalloc.h"
+
+// TODO: secondary
+// TODO: 32-bit
+
+bool
+eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
+		size_t len) {
+	const struct rte_memseg *ms;
+	uint64_t page_sz;
+	void *end;
+	int start_page, end_page, cur_page;
+	rte_iova_t expected;
+
+	/* for legacy memory, it's always contiguous */
+	if (internal_config.legacy_mem)
+		return true;
+
+	/* figure out how many pages we need to fit in current data */
+	page_sz = msl->hugepage_sz;
+	end = RTE_PTR_ADD(start, len);
+
+	start_page = RTE_PTR_DIFF(start, msl->base_va) / page_sz;
+	end_page = RTE_PTR_DIFF(end, msl->base_va) / page_sz;
+
+	/* now, look for contiguous memory */
+	ms = rte_fbarray_get(&msl->memseg_arr, start_page);
+	expected = ms->iova + page_sz;
+
+	for (cur_page = start_page + 1; cur_page < end_page;
+			cur_page++, expected += page_sz) {
+		ms = rte_fbarray_get(&msl->memseg_arr, cur_page);
+
+		if (ms->iova != expected)
+			return false;
+	}
+
+	return true;
+}
diff --git a/lib/librte_eal/common/eal_memalloc.h b/lib/librte_eal/common/eal_memalloc.h
index 47e4367..04f9b72 100755
--- a/lib/librte_eal/common/eal_memalloc.h
+++ b/lib/librte_eal/common/eal_memalloc.h
@@ -36,6 +36,7 @@
 #include <stdbool.h>
 
 #include <rte_memory.h>
+#include <rte_eal_memconfig.h>
 
 struct rte_memseg *
 eal_memalloc_alloc_page(uint64_t size, int socket);
@@ -47,4 +48,8 @@ eal_memalloc_alloc_page_bulk(struct rte_memseg **ms, int n, uint64_t size,
 int
 eal_memalloc_free_page(struct rte_memseg *ms);
 
+bool
+eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
+		size_t len);
+
 #endif // EAL_MEMALLOC_H
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 88f10e9..c1fc557 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -75,6 +75,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memalloc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_errno.c
-- 
2.7.4

  parent reply	other threads:[~2017-12-19 11:05 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-19 11:04 [dpdk-dev] [PATCH 00/23] Dynamic memory allocation for DPDK Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 01/23] eal: move get_virtual_area out of linuxapp eal_memory.c Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 02/23] eal: add function to report number of detected sockets Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 03/23] eal: add rte_fbarray Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 04/23] eal: move all locking to heap Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 05/23] eal: protect malloc heap stats with a lock Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 06/23] eal: make malloc a doubly-linked list Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 07/23] eal: make malloc_elem_join_adjacent_free public Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 08/23] eal: add "single file segments" command-line option Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 09/23] eal: add "legacy memory" option Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 10/23] eal: read hugepage counts from node-specific sysfs path Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 11/23] eal: replace memseg with memseg lists Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 12/23] eal: add support for dynamic memory allocation Anatoly Burakov
     [not found] ` <cover.1513594170.git.anatoly.burakov@intel.com>
2017-12-19 11:04   ` [dpdk-dev] [RFC 01/23] eal/memory: move get_virtual_area out of linuxapp eal_memory.c Anatoly Burakov
2017-12-19 11:15     ` Burakov, Anatoly
2017-12-19 11:04   ` [dpdk-dev] [RFC 02/23] eal/lcore: add function to report number of detected sockets Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 04/23] eal/malloc: move all locking to heap Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 05/23] eal/malloc: protect malloc heap stats with a lock Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 06/23] eal/malloc: make malloc a doubly-linked list Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 07/23] eal/malloc: make malloc_elem_join_adjacent_free public Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 10/23] eal: populate hugepage counts from socket-specific sysfs path Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 12/23] eal/memalloc: add support for dynamic memory allocation Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 13/23] eal/memory: make use of dynamic memory allocation for init Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 14/23] eal/memory: add support for dynamic unmapping of pages Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 15/23] eal/memalloc: add function to check if memory is physically contiguous Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 16/23] eal/malloc: enable dynamic memory allocation/free on malloc/free Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 17/23] eal/malloc: add backend support for contiguous memory allocation Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 18/23] eal/malloc: add rte_malloc support for allocating contiguous memory Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 19/23] eal/memzone: add support for reserving physically contiguous memzones Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 20/23] eal/memzone: make memzones use rte_fbarray Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 21/23] lib/mempool: add support for the new memory allocation methods Anatoly Burakov
2017-12-19 11:04   ` [dpdk-dev] [RFC 23/23] eal/memalloc: register/unregister memory with VFIO when alloc/free pages Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 13/23] eal: make use of dynamic memory allocation for init Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 14/23] eal: add support for dynamic unmapping of pages Anatoly Burakov
2017-12-19 11:04 ` Anatoly Burakov [this message]
2017-12-19 11:04 ` [dpdk-dev] [PATCH 16/23] eal: enable dynamic memory allocation/free on malloc/free Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 17/23] eal: add backend support for contiguous memory allocation Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 18/23] eal: add rte_malloc support for allocating contiguous memory Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 19/23] eal: enable reserving physically contiguous memzones Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 20/23] eal: make memzones use rte_fbarray Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 21/23] mempool: add support for the new memory allocation methods Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 22/23] vfio: allow to map other memory regions Anatoly Burakov
2017-12-19 11:04 ` [dpdk-dev] [PATCH 23/23] eal: map/unmap memory with VFIO when alloc/free pages Anatoly Burakov
2017-12-19 11:15 ` [dpdk-dev] [PATCH 00/23] Dynamic memory allocation for DPDK Burakov, Anatoly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23b3239ed0ad52d78d2c3a1fdb8dd19be69ecd51.1513680516.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=andras.kovacs@ericsson.com \
    --cc=benjamin.walker@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=keith.wiles@intel.com \
    --cc=laszlo.vadkeri@ericsson.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).