Skip to contentSkip to conversation

app/testpmd: only lock text pages

RFC PATCH In review David Marchand 2 participants 5 messages Mar 6, 2020 – Mar 10, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 app/testpmd: only lock text pages

Since 18.05 and the memory subsystem rework, EAL reserves some big (unused) mappings.

In testpmd, we have been locking all pages to avoid page faults during benchmark/performance regression tests [1].
However, asking for locking all the pages triggers issues on FreeBSD [2] and becomes really heavy in some Linux configurations (see [3], [4]).

This patch changes the behavior so that testpmd only lock pages containing .text by default.

1: https://git.dpdk.org/dpdk/commit/?id=1c036b16c284
2: https://git.dpdk.org/dpdk/commit/?id=fb7b8b32cd95
3: https://bugzilla.redhat.com/show_bug.cgi?id=1786923
4: http://mails.dpdk.org/archives/dev/2020-February/158477.html

---
 app/test-pmd/parameters.c |  4 +--
 app/test-pmd/testpmd.c    | 53 +++++++++++++++++++++++++++++++--------
 app/test-pmd/testpmd.h    |  5 +++-
 3 files changed, 49 insertions(+), 13 deletions(-)
app/test-pmd/parameters.c +2 -2
index 404dba2b2..952371e6c 100644
@@ -1304,9 +1304,9 @@ launch_args_parse(int argc, char** argv)
 			if (!strcmp(lgopts[opt_idx].name, "hot-plug"))
 				hot_plug = 1;
 			if (!strcmp(lgopts[opt_idx].name, "mlockall"))
-				do_mlockall = 1;
+				do_mlock = TESTPMD_MLOCK_ALL;
 			if (!strcmp(lgopts[opt_idx].name, "no-mlockall"))
-				do_mlockall = 0;
+				do_mlock = TESTPMD_MLOCK_NONE;
 			if (!strcmp(lgopts[opt_idx].name,
 				    "noisy-tx-sw-buffer-size")) {
 				n = atoi(optarg);
app/test-pmd/testpmd.c +43 -10

83 lines not on this page · raw message

app/test-pmd/testpmd.h +4 -1
index 7a7c73f79..a38e5a1f5 100644
@@ -343,7 +343,10 @@ extern uint32_t event_print_mask;
 /**< set by "--print-event xxxx" and "--mask-event xxxx parameters */
 extern bool setup_on_probe_event; /**< disabled by port setup-on iterator */
 extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */
-extern int do_mlockall; /**< set by "--mlockall" or "--no-mlockall" parameter */
+#define TESTPMD_MLOCK_NONE 0
+#define TESTPMD_MLOCK_TEXT 1
+#define TESTPMD_MLOCK_ALL  2
+extern int do_mlock; /**< set by "--mlockall" or "--no-mlockall" parameter */
 extern uint8_t clear_ptypes; /**< disabled by set ptype cmd */
 
 #ifdef RTE_LIBRTE_IXGBE_BYPASS
Signature · 1 line
2.23.0
#1 lore raw
Quoted 17 lines · David Marchand

Since 18.05 and the memory subsystem rework, EAL reserves some big (unused) mappings.

In testpmd, we have been locking all pages to avoid page faults during benchmark/performance regression tests [1].
However, asking for locking all the pages triggers issues on FreeBSD [2] and becomes really heavy in some Linux configurations (see [3], [4]).

This patch changes the behavior so that testpmd only lock pages containing .text by default.

1: https://git.dpdk.org/dpdk/commit/?id=1c036b16c284
2: https://git.dpdk.org/dpdk/commit/?id=fb7b8b32cd95
3: https://bugzilla.redhat.com/show_bug.cgi?id=1786923
4: http://mails.dpdk.org/archives/dev/2020-February/158477.html

<...>

Quoted 29 lines
app/test-pmd/testpmd.c +25 -0
@@ -3455,6 +3456,42 @@ signal_handler(int signum)
 	}
 }
 
+static void
+lock_pages(const void *_addr, size_t _len, const char *prefix)
+{
+	const void *addr;
+	size_t pagesize;
+	size_t len;
+
+	/* While Linux does not care, FreeBSD mlock expects page aligned
+	 * address (according to the man).
+	 */
+	pagesize = sysconf(_SC_PAGESIZE);
+	addr = RTE_PTR_ALIGN_FLOOR(_addr, pagesize);
+	len = _len + ((uintptr_t)_addr & (pagesize - 1));
+	if (mlock(addr, len)) {
+		TESTPMD_LOG(NOTICE, "%s: mlock %p (0x%zx) aligned to %p (0x%zx) failed with error \"%s\"\n",
+			prefix, _addr, _len, addr, len, strerror(errno));
+	}
+}
+
+static int
+lock_text_cb(struct dl_phdr_info *info, __rte_unused size_t size,
+		__rte_unused void *data)
+{
+	int i;
+

app/test-pmd/testpmd.c signal_handler(int signum) · line 3493

Quoted 10 lines
app/test-pmd/testpmd.c +10 -0
+	for (i = 0; i < info->dlpi_phnum; i++) {
+		void *addr;
+
+		if (info->dlpi_phdr[i].p_memsz == 0)
+			continue;
+		addr = (void *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+		lock_pages(addr, info->dlpi_phdr[i].p_memsz, info->dlpi_name);
+	}
+	return 0;
+}

+1 to the idea, testpmd initialization was taking too lock without '--no-mlockall', but this code looks complex for the application level.

We can do this for testpmd but does all applications need to do something similar? If so can we have a solution on eal level instead?

#2 lore raw
Quoted 65 lines · Ferruh Yigit
Quoted 17 lines · David Marchand

Since 18.05 and the memory subsystem rework, EAL reserves some big (unused) mappings.

In testpmd, we have been locking all pages to avoid page faults during benchmark/performance regression tests [1].
However, asking for locking all the pages triggers issues on FreeBSD [2] and becomes really heavy in some Linux configurations (see [3], [4]).

This patch changes the behavior so that testpmd only lock pages containing .text by default.

1: https://git.dpdk.org/dpdk/commit/?id=1c036b16c284
2: https://git.dpdk.org/dpdk/commit/?id=fb7b8b32cd95
3: https://bugzilla.redhat.com/show_bug.cgi?id=1786923
4: http://mails.dpdk.org/archives/dev/2020-February/158477.html

<...>

Quoted 29 lines
app/test-pmd/testpmd.c +25 -0
@@ -3455,6 +3456,42 @@ signal_handler(int signum)
      }
 }
 
+static void
+lock_pages(const void *_addr, size_t _len, const char *prefix)
+{
+     const void *addr;
+     size_t pagesize;
+     size_t len;
+
+     /* While Linux does not care, FreeBSD mlock expects page aligned
+      * address (according to the man).
+      */
+     pagesize = sysconf(_SC_PAGESIZE);
+     addr = RTE_PTR_ALIGN_FLOOR(_addr, pagesize);
+     len = _len + ((uintptr_t)_addr & (pagesize - 1));
+     if (mlock(addr, len)) {
+             TESTPMD_LOG(NOTICE, "%s: mlock %p (0x%zx) aligned to %p (0x%zx) failed with error \"%s\"\n",
+                     prefix, _addr, _len, addr, len, strerror(errno));
+     }
+}
+
+static int
+lock_text_cb(struct dl_phdr_info *info, __rte_unused size_t size,
+             __rte_unused void *data)
+{
+     int i;
+

app/test-pmd/testpmd.c signal_handler(int signum) · line 3493

Quoted 10 lines
app/test-pmd/testpmd.c +10 -0
+     for (i = 0; i < info->dlpi_phnum; i++) {
+             void *addr;
+
+             if (info->dlpi_phdr[i].p_memsz == 0)
+                     continue;
+             addr = (void *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+             lock_pages(addr, info->dlpi_phdr[i].p_memsz, info->dlpi_name);
+     }
+     return 0;
+}

+1 to the idea, testpmd initialization was taking too lock without '--no-mlockall', but this code looks complex for the application level.

Quoted 2 lines

We can do this for testpmd but does all applications need to do something similar? If so can we have a solution on eal level instead?

I submitted a patch on the EAL side.
This makes mlockall way lighter, since it skips pages marked with PROT_NONE.
http://patchwork.dpdk.org/patch/66469/

Signature · 1 line
David Marchand
#3 lore raw
Quoted 66 lines · David Marchand
Quoted 65 lines · Ferruh Yigit
Quoted 17 lines · David Marchand

Since 18.05 and the memory subsystem rework, EAL reserves some big (unused) mappings.

In testpmd, we have been locking all pages to avoid page faults during benchmark/performance regression tests [1].
However, asking for locking all the pages triggers issues on FreeBSD [2] and becomes really heavy in some Linux configurations (see [3], [4]).

This patch changes the behavior so that testpmd only lock pages containing .text by default.

1: https://git.dpdk.org/dpdk/commit/?id=1c036b16c284
2: https://git.dpdk.org/dpdk/commit/?id=fb7b8b32cd95
3: https://bugzilla.redhat.com/show_bug.cgi?id=1786923
4: http://mails.dpdk.org/archives/dev/2020-February/158477.html

<...>

Quoted 29 lines
app/test-pmd/testpmd.c +25 -0
@@ -3455,6 +3456,42 @@ signal_handler(int signum)
      }
 }
 
+static void
+lock_pages(const void *_addr, size_t _len, const char *prefix)
+{
+     const void *addr;
+     size_t pagesize;
+     size_t len;
+
+     /* While Linux does not care, FreeBSD mlock expects page aligned
+      * address (according to the man).
+      */
+     pagesize = sysconf(_SC_PAGESIZE);
+     addr = RTE_PTR_ALIGN_FLOOR(_addr, pagesize);
+     len = _len + ((uintptr_t)_addr & (pagesize - 1));
+     if (mlock(addr, len)) {
+             TESTPMD_LOG(NOTICE, "%s: mlock %p (0x%zx) aligned to %p (0x%zx) failed with error \"%s\"\n",
+                     prefix, _addr, _len, addr, len, strerror(errno));
+     }
+}
+
+static int
+lock_text_cb(struct dl_phdr_info *info, __rte_unused size_t size,
+             __rte_unused void *data)
+{
+     int i;
+

app/test-pmd/testpmd.c signal_handler(int signum) · line 3493

Quoted 10 lines
app/test-pmd/testpmd.c +10 -0
+     for (i = 0; i < info->dlpi_phnum; i++) {
+             void *addr;
+
+             if (info->dlpi_phdr[i].p_memsz == 0)
+                     continue;
+             addr = (void *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+             lock_pages(addr, info->dlpi_phdr[i].p_memsz, info->dlpi_name);
+     }
+     return 0;
+}

+1 to the idea, testpmd initialization was taking too lock without '--no-mlockall', but this code looks complex for the application level.

Quoted 7 lines
Quoted 2 lines

We can do this for testpmd but does all applications need to do something similar? If so can we have a solution on eal level instead?

I submitted a patch on the EAL side.
This makes mlockall way lighter, since it skips pages marked with PROT_NONE.
http://patchwork.dpdk.org/patch/66469/

Cool,

With that patch timing improves a lot, in my system testpmd initialization reduced from 38s to 9s. (it was 6s with --no-mlockall).

Do we still need this testpmd patch?

#4 lore raw
Quoted 11 lines · Ferruh Yigit
Quoted 10 lines
Quoted 5 lines

+1 to the idea, testpmd initialization was taking too lock without '--no-mlockall', but this code looks complex for the application level.

We can do this for testpmd but does all applications need to do something similar? If so can we have a solution on eal level instead?

I submitted a patch on the EAL side.
This makes mlockall way lighter, since it skips pages marked with PROT_NONE.
http://patchwork.dpdk.org/patch/66469/

Quoted 6 lines

Cool,

With that patch timing improves a lot, in my system testpmd initialization reduced from 38s to 9s. (it was 6s with --no-mlockall).

Do we still need this testpmd patch?

My intention is to drop this RFC once Anatoly gives a ACK on the EAL side.

Signature · 1 line
David Marchand