[dpdk-dev] app/testpmd: adds mlockall() to fix pages

Message ID 22990026376b08418cb0eb6f028840c03e89f47f.1505221429.git.echaudro@redhat.com (mailing list archive)
State Superseded, archived
Headers

Checks

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

Commit Message

Eelco Chaudron Sept. 12, 2017, 1:08 p.m. UTC
  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 | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Aaron Conole Sept. 12, 2017, 2:50 p.m. UTC | #1
Eelco Chaudron <echaudro@redhat.com> writes:

> 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>
  
Thomas Monjalon Sept. 12, 2017, 8:14 p.m. UTC | #2
12/09/2017 16:50, Aaron Conole:
> Eelco Chaudron <echaudro@redhat.com> writes:
> 
> > 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>

It is interesting, but why make it in testpmd?

Maybe it should be documented in this guide:
	http://dpdk.org/doc/guides/linux_gsg/nic_perf_intel_platform.html
  
Aaron Conole Sept. 12, 2017, 8:29 p.m. UTC | #3
Thomas Monjalon <thomas@monjalon.net> writes:

> 12/09/2017 16:50, Aaron Conole:
>> Eelco Chaudron <echaudro@redhat.com> writes:
>> 
>> > 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>
>
> It is interesting, but why make it in testpmd?
>
> Maybe it should be documented in this guide:
> 	http://dpdk.org/doc/guides/linux_gsg/nic_perf_intel_platform.html

Well, I'm not sure what the user would be able to do to get the
prefaulting performance without having a library they use with
LD_PRELOAD and a function with the constructor attribute which does the
same thing, AND export LD_BIND_NOW before linking starts.

The LD_BIND_NOW simply does the symbol resolution, but there's no
guarantee that it will fault all the code pages in to process space, and
without an mlockall(), I'm not sure that there's any kind of guarantee
that they don't get swapped out of resident memory (which also leads to
later page faults).

Maybe I misunderstood the question?
  
Thomas Monjalon Sept. 12, 2017, 10:13 p.m. UTC | #4
12/09/2017 22:29, Aaron Conole:
> Thomas Monjalon <thomas@monjalon.net> writes:
> 
> > 12/09/2017 16:50, Aaron Conole:
> >> Eelco Chaudron <echaudro@redhat.com> writes:
> >> 
> >> > 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>
> >
> > It is interesting, but why make it in testpmd?
> >
> > Maybe it should be documented in this guide:
> > 	http://dpdk.org/doc/guides/linux_gsg/nic_perf_intel_platform.html
> 
> Well, I'm not sure what the user would be able to do to get the
> prefaulting performance without having a library they use with
> LD_PRELOAD and a function with the constructor attribute which does the
> same thing, AND export LD_BIND_NOW before linking starts.
> 
> The LD_BIND_NOW simply does the symbol resolution, but there's no
> guarantee that it will fault all the code pages in to process space, and
> without an mlockall(), I'm not sure that there's any kind of guarantee
> that they don't get swapped out of resident memory (which also leads to
> later page faults).
> 
> Maybe I misunderstood the question?

Maybe you misunderstood :)

I was saying that if this improvement applies to applications,
it should be documented in the tuning guide.
  
Eelco Chaudron Sept. 13, 2017, 8:55 a.m. UTC | #5
On 13/09/17 00:13, Thomas Monjalon wrote:
> 12/09/2017 22:29, Aaron Conole:
>> Thomas Monjalon <thomas@monjalon.net> writes:
>>
>>> 12/09/2017 16:50, Aaron Conole:
>>>> Eelco Chaudron <echaudro@redhat.com> writes:
>>>>
>>>>> 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>
>>> It is interesting, but why make it in testpmd?
>>>
>>> Maybe it should be documented in this guide:
>>> 	http://dpdk.org/doc/guides/linux_gsg/nic_perf_intel_platform.html
>> Well, I'm not sure what the user would be able to do to get the
>> prefaulting performance without having a library they use with
>> LD_PRELOAD and a function with the constructor attribute which does the
>> same thing, AND export LD_BIND_NOW before linking starts.
>>
>> The LD_BIND_NOW simply does the symbol resolution, but there's no
>> guarantee that it will fault all the code pages in to process space, and
>> without an mlockall(), I'm not sure that there's any kind of guarantee
>> that they don't get swapped out of resident memory (which also leads to
>> later page faults).
>>
>> Maybe I misunderstood the question?
> Maybe you misunderstood :)
>
> I was saying that if this improvement applies to applications,
> it should be documented in the tuning guide.
>
I'll try to find a good place in the documentation for adding a 
reference to mlockall(), but will send it as a separate documentation patch.

//Eelco
  
Maxime Coquelin Sept. 13, 2017, 9:15 a.m. UTC | #6
On 09/12/2017 03:08 PM, Eelco Chaudron wrote:
> 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 | 3 +++
>   1 file changed, 3 insertions(+)
> 

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

Thanks,
Maxime
  
Thomas Monjalon Sept. 13, 2017, 9:39 a.m. UTC | #7
12/09/2017 15:08, Eelco Chaudron:
> 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.

Does it work on FreeBSD?
Is there any drawback?
Do we need to add an option for it?
  
Aaron Conole Sept. 13, 2017, 12:28 p.m. UTC | #8
Thomas Monjalon <thomas@monjalon.net> writes:

> 12/09/2017 22:29, Aaron Conole:
>> Thomas Monjalon <thomas@monjalon.net> writes:
>> 
>> > 12/09/2017 16:50, Aaron Conole:
>> >> Eelco Chaudron <echaudro@redhat.com> writes:
>> >> 
>> >> > 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>
>> >
>> > It is interesting, but why make it in testpmd?
>> >
>> > Maybe it should be documented in this guide:
>> > 	http://dpdk.org/doc/guides/linux_gsg/nic_perf_intel_platform.html
>> 
>> Well, I'm not sure what the user would be able to do to get the
>> prefaulting performance without having a library they use with
>> LD_PRELOAD and a function with the constructor attribute which does the
>> same thing, AND export LD_BIND_NOW before linking starts.
>> 
>> The LD_BIND_NOW simply does the symbol resolution, but there's no
>> guarantee that it will fault all the code pages in to process space, and
>> without an mlockall(), I'm not sure that there's any kind of guarantee
>> that they don't get swapped out of resident memory (which also leads to
>> later page faults).
>> 
>> Maybe I misunderstood the question?
>
> Maybe you misunderstood :)
>
> I was saying that if this improvement applies to applications,
> it should be documented in the tuning guide.

Ahh, okay.  Yep, I agree with all you've written above.
  
Eelco Chaudron Sept. 14, 2017, 7:22 a.m. UTC | #9
On 13/09/17 11:39, Thomas Monjalon wrote:
> 12/09/2017 15:08, Eelco Chaudron:
>> 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.
> Does it work on FreeBSD?
I do not have a FreeBSD setup, but from the documentation I've read the 
call is supported by FreeBSD.
If some one has a working setup, please give this patch a quick try.
> Is there any drawback?
> Do we need to add an option for it?
The only drawback I can think of is that with this change memory 
phyiscal memory is consumed as pages are pre-loaded.
For testpmd (just loaded not doing anything) this is 2MB vs 35MB of 
memory used. I do not think this yields an extra option.
  
Olivier Matz Sept. 19, 2017, 7:28 a.m. UTC | #10
Hi,

On Thu, Sep 14, 2017 at 09:22:38AM +0200, Eelco Chaudron wrote:
> On 13/09/17 11:39, Thomas Monjalon wrote:
> > 12/09/2017 15:08, Eelco Chaudron:
> > > 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.
> > Does it work on FreeBSD?
> I do not have a FreeBSD setup, but from the documentation I've read the call
> is supported by FreeBSD.
> If some one has a working setup, please give this patch a quick try.
> > Is there any drawback?
> > Do we need to add an option for it?
> The only drawback I can think of is that with this change memory phyiscal
> memory is consumed as pages are pre-loaded.
> For testpmd (just loaded not doing anything) this is 2MB vs 35MB of memory
> used. I do not think this yields an extra option.

One small comment: the call to mlockall() will fail if we don't have
the permissions. I guess it's not an issue, but I wonder if we should
log it?

Olivier
  
Eelco Chaudron Sept. 21, 2017, 12:24 p.m. UTC | #11
On 19/09/17 09:28, Olivier MATZ wrote:
> Hi,
>
> On Thu, Sep 14, 2017 at 09:22:38AM +0200, Eelco Chaudron wrote:
>> On 13/09/17 11:39, Thomas Monjalon wrote:
>>> 12/09/2017 15:08, Eelco Chaudron:
>>>> 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.
>>> Does it work on FreeBSD?
>> I do not have a FreeBSD setup, but from the documentation I've read the call
>> is supported by FreeBSD.
>> If some one has a working setup, please give this patch a quick try.
>>> Is there any drawback?
>>> Do we need to add an option for it?
>> The only drawback I can think of is that with this change memory phyiscal
>> memory is consumed as pages are pre-loaded.
>> For testpmd (just loaded not doing anything) this is 2MB vs 35MB of memory
>> used. I do not think this yields an extra option.
> One small comment: the call to mlockall() will fail if we don't have
> the permissions. I guess it's not an issue, but I wonder if we should
> log it?
I did not at add a log, as the rte log subsystem is not yet initialized.
However we could add a printf("WARNING: mlockall() failed with error %s")
like message. What do you think?

> Olivier
  
Olivier Matz Sept. 25, 2017, 7:53 a.m. UTC | #12
On Thu, Sep 21, 2017 at 02:24:28PM +0200, Eelco Chaudron wrote:
> On 19/09/17 09:28, Olivier MATZ wrote:
> > Hi,
> > 
> > On Thu, Sep 14, 2017 at 09:22:38AM +0200, Eelco Chaudron wrote:
> > > On 13/09/17 11:39, Thomas Monjalon wrote:
> > > > 12/09/2017 15:08, Eelco Chaudron:
> > > > > 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.
> > > > Does it work on FreeBSD?
> > > I do not have a FreeBSD setup, but from the documentation I've read the call
> > > is supported by FreeBSD.
> > > If some one has a working setup, please give this patch a quick try.
> > > > Is there any drawback?
> > > > Do we need to add an option for it?
> > > The only drawback I can think of is that with this change memory phyiscal
> > > memory is consumed as pages are pre-loaded.
> > > For testpmd (just loaded not doing anything) this is 2MB vs 35MB of memory
> > > used. I do not think this yields an extra option.
> > One small comment: the call to mlockall() will fail if we don't have
> > the permissions. I guess it's not an issue, but I wonder if we should
> > log it?
> I did not at add a log, as the rte log subsystem is not yet initialized.
> However we could add a printf("WARNING: mlockall() failed with error %s")
> like message. What do you think?

Since it's not critical, maybe NOTICE is better than WARNING.

One more question: what would be the drawback of calling
mlockall() after eal_init()? (rte_log would be initialized)


Thanks,
Olivier
  
Eelco Chaudron Sept. 29, 2017, 7:59 a.m. UTC | #13
On 25/09/17 09:53, Olivier MATZ wrote:
>> [SNIP]
>> I did not at add a log, as the rte log subsystem is not yet initialized.
>> However we could add a printf("WARNING: mlockall() failed with error %s")
>> like message. What do you think?
> Since it's not critical, maybe NOTICE is better than WARNING.
>
> One more question: what would be the drawback of calling
> mlockall() after eal_init()? (rte_log would be initialized)
>
Calling mlockall() after eal_init() does seem to have the same effect.
I'll send out a v2 patch later today with a rte_log(NOTICE).
  
Sergio Gonzalez Monroy Sept. 29, 2017, 8:07 a.m. UTC | #14
On 12/09/2017 14:08, Eelco Chaudron wrote:
> 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>
> ---

When used for performance testing using hugepages or --no-huge option?

Thanks,
Sergio
  
Eelco Chaudron Sept. 29, 2017, 8:15 a.m. UTC | #15
On 29/09/17 10:07, Sergio Gonzalez Monroy wrote:
> On 12/09/2017 14:08, Eelco Chaudron wrote:
>> 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>
>> ---
>
> When used for performance testing using hugepages or --no-huge option?
This is independent of huge pages, its for the text (code) sections.
  
Sergio Gonzalez Monroy Sept. 29, 2017, 9:27 a.m. UTC | #16
On 29/09/2017 09:15, Eelco Chaudron wrote:
> On 29/09/17 10:07, Sergio Gonzalez Monroy wrote:
>> On 12/09/2017 14:08, Eelco Chaudron wrote:
>>> 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>
>>> ---
>>
>> When used for performance testing using hugepages or --no-huge option?
> This is independent of huge pages, its for the text (code) sections.

Understood.

Just for curiosity, how much drop-rate was observed?

Thanks,
Sergio
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 7d4013941..80f3c3e8e 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>
 
@@ -2292,6 +2293,8 @@  main(int argc, char** argv)
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
 
+	mlockall(MCL_CURRENT | MCL_FUTURE);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_panic("Cannot init EAL\n");