[dpdk-dev,v2] app/testpmd: adds mlockall() to avoid pages being swapped out

Message ID 5482c65ba817cd8543fd9634943a1c3b34fd1081.1506672633.git.echaudro@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Eelco Chaudron Sept. 29, 2017, 8:11 a.m. UTC
  v2:
* Moved mlockall() after rte_eal_init() to allow rte_log() to be used
* Check for mlockall() return value, and add an rte_log()

Call the mlockall() function, to attempt to lock all of its process
memory into physical RAM, and preventing the kernel from paging any
of its memory to disk.

When using testpmd for performance testing, depending on the code path
taken, we see a couple of page faults in a row. These faults effect
the overall drop-rate of testpmd. On Linux the mlockall() call will
prefault all the pages of testpmd (and the DPDK libraries if linked
dynamically), even without LD_BIND_NOW.

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
 app/test-pmd/testpmd.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Ferruh Yigit Oct. 9, 2017, 11:40 p.m. UTC | #1
On 9/29/2017 9:11 AM, Eelco Chaudron wrote:
> v2:
> * Moved mlockall() after rte_eal_init() to allow rte_log() to be used
> * Check for mlockall() return value, and add an rte_log()
> 
> Call the mlockall() function, to attempt to lock all of its process
> memory into physical RAM, and preventing the kernel from paging any
> of its memory to disk.
> 
> When using testpmd for performance testing, depending on the code path
> taken, we see a couple of page faults in a row. These faults effect
> the overall drop-rate of testpmd. On Linux the mlockall() call will
> prefault all the pages of testpmd (and the DPDK libraries if linked
> dynamically), even without LD_BIND_NOW.
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>

Acked-by: Aaron Conole <aconole@redhat.com>
Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Applied to dpdk/master, thanks.

(Kept ACKs from previous version of the patch)
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e097ee04e..f741fcd0a 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -38,6 +38,7 @@ 
 #include <string.h>
 #include <time.h>
 #include <fcntl.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <errno.h>
 
@@ -2337,6 +2338,11 @@  main(int argc, char** argv)
 	if (diag < 0)
 		rte_panic("Cannot init EAL\n");
 
+	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
+		RTE_LOG(NOTICE, USER1, "mlockall() failed with error \"%s\"\n",
+			strerror(errno));
+	}
+
 #ifdef RTE_LIBRTE_PDUMP
 	/* initialize packet capture framework */
 	rte_pdump_init(NULL);