mmap/munmap /dev/zero
PATCH v2 1/1 mmap/munmap /dev/zero
In reply to a message not in the archivev2: incorporate comments from Mike and Garrett.
Add a new test to mmap/munmap /dev/zero. A common way of malloc()/free() anonymous memory on Solaris. Anyway, mmap() of /dev/zero results in calling map_zero() which on RHEL5 maps the ZERO_PAGE in every pte within that virtual address range. Since a application is also multi-threaded the subsequent munmap() of /dev/zero results is TLB shootdowns to all other CPUs. When this happens thousands or millions of times the application performance is terrible. The mapping ZERO_PAGE in every pte within that virtual address range was an optimization to make the subsequent pagefault times faster on RHEL5 that has been removed/changed upstream.
testcases/kernel/syscalls/mmap/mmap10.c | 153 +++++++++++++++++++++++++++++++ 1 files changed, 153 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/mmap/mmap10.c new file +153 -0
@@ -0,0 +1,153 @@ +/* +* mmap/munmap /dev/zero: a common way of malloc()/free() anonymous +* memory on Solaris. Anyway, mmap() of /dev/zero results in calling +* map_zero() which on RHEL5 maps the ZERO_PAGE in every pte within +* that virtual address range. Since a application is also +* multi-threaded the subsequent munmap() of /dev/zero results is TLB +* shootdowns to all other CPUs. When this happens thousands or +* millions of times the application performance is terrible. The +* mapping ZERO_PAGE in every pte within that virtual address range +* was an optimization to make the subsequent pagefault times faster +* on RHEL5 that has been removed/changed upstream. +* +* Copyright (C) 2010 Red Hat, Inc. +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it +* is free of the rightful claim of any third person regarding +* infringement or the like. Any license provided herein, whether +* implied or otherwise, applies only to this software file. Patent +* licenses, if any, provided herein do not apply to combinations of +* this program with other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA. +*/ + +#include "test.h" +#include "usctest.h" +#include <errno.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <stdio.h> + +#define SIZE (5*1024*1024) + +char *TCID ="mmap10" ; +int TST_TOTAL =1 ; +extern int Tst_count; + +/* main setup function of test */ +void setup (void ); +/* cleanup function for the test */ +void cleanup (void ); +int mmapzero (void ); + +int main (int argc,char *argv[]) +{ +/* loop counter */ +int lc; +/* message returned from parse_opts */ +char *msg; + + msg =parse_opts (argc, argv, (option_t *)NULL ,NULL ); +if (msg !=NULL ) { +tst_brkm (TBROK ,NULL ,"OPTION PARSING ERROR - %s" , msg); +tst_exit (); + } + +/* Perform global setup for test */ +setup (); + +/* Check looping state if -i option given */ +for (lc =0 ;TEST_LOOPING (lc); lc++) { +/* Reset Tst_count in case we are looping. */ + Tst_count =0 ; + +TEST (mmapzero ()); + +if (TEST_RETURN !=0 ) +tst_resm (TFAIL ,"mmapzero() failed with %ld." , +TEST_RETURN ); +else +tst_resm (TPASS ,"mmapzero() completed successfully." ); + } + +cleanup (); +return 0 ; +} + +int mmapzero (void ) +{ +char *x; +int n; + + x =mmap ("/dev/zero" ,SIZE +SIZE -4096 ,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); +if (x ==MAP_FAILED ) { +tst_resm (TFAIL ,"mmap: %s" ,strerror (errno)); +return 1 ; + } + x[SIZE ] =0 ; + n =fork (); +if (n ==-1 ) +tst_brkm (TBROK , cleanup,"fork: %s" ,strerror (errno)); +else if (n ==0 ) { +if (munmap (x +SIZE +4096 ,SIZE -4096 *2 ) ==-1 ) +tst_resm (TFAIL ,"munmap: %s" ,strerror (errno)); +_exit (0 ); + } + n =fork (); +if (n ==-1 ) +tst_brkm (TBROK , cleanup,"fork: %s" ,strerror (errno)); +else if (n ==0 ) { +if (munmap (x +SIZE +4096 ,SIZE -4096 *2 ) ==-1 ) +tst_resm (TFAIL ,"munmap: %s" ,strerror (errno)); +_exit (0 ); + }else { + n =fork (); +if (n ==-1 ) +tst_brkm (TBROK , cleanup,"fork: %s" ,strerror (errno)); +else if (n ==0 ) { +if (munmap (x +SIZE +4096 ,SIZE -4096 *2 ) ==-1 ) +tst_resm (TFAIL ,"munmap: %s" ,strerror (errno)); +_exit (0 ); + } + } +if (munmap (x,SIZE +SIZE -4096 ) ==-1 ) +tst_resm (TFAIL ,"munmap: %s" ,strerror (errno)); +while (waitpid (-1 ,NULL ,WNOHANG ) >0 ); +return 0 ; +} + +void cleanup (void ) +{ +/* +* remove the tmp directory and exit +*/ +TEST_CLEANUP ; +tst_rmdir (); +tst_exit (); +} + + +void setup (void ) +{ +/* +* setup a default signal hander and a +* temporary working directory. +*/ +tst_sig (FORK ,DEF_HANDLER , cleanup); +TEST_PAUSE ; +tst_tmpdir (); +}
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 9 lines · On Tuesday, October 12, 2010 22:02:28 [email protected] wrote:
Add a new test to mmap/munmap
/dev/zero. A common way of malloc()/free() anonymous memory on Solaris. Anyway,mmap()of/dev/zeroresults in callingmap_zero()which on RHEL5 maps theZERO_PAGEin every pte within that virtual address range. Since a application is also multi-threaded the subsequentmunmap()of/dev/zeroresults is TLB shootdowns to all other CPUs. When this happens thousands or millions of times the application performance is terrible. The mappingZERO_PAGEin every pte within that virtual address range was an optimization to make the subsequent pagefault times faster on RHEL5 that has been removed/changed upstream.
you need to fix your mailer and/or use git send-email. changelogs must be line wrapped to the standard e-mail length (or even a few chars shorter).
further, your e-mail lacks the marker "---" which tells git where the changelog ends. git send-email takes care of this for you too.
patch changelogs (i.e. what changed in v2, v3, ....) should be below the "---" marker or at the end of the changelog (not the start). personally, i prefer the "---" system.
-mike
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
You've filled in some of the blanks, but there are some that are still missing...
Quoted 3 lines · On Tue, Oct 12, 2010 at 7:02 PM, <[email protected]> wrote:
v2: incorporate comments from Mike and Garrett.
Add a new test to mmap/munmap
/dev/zero. A common way of malloc()/free() anonymous memory on Solaris.
The first sentence should standalone as the summary, like:
Add a new test to mmap/munmap /dev/zero [fill in reason why it's being tested -- try to summarize in less than 80 columns].
Right now it's a dangling modifier.
The second sentence is a fragment; you are describing the process, but not describing the important actors or involved parties in the process (in particular on the Linux side).
There's also little context between the two sentences, so it's confusing to the end reader.
Quoted 1 line
Anyway,
You can remove Anyway,
Quoted 1 line
mmap()
memory mapping
Quoted 1 line
of
unnecessary particle.
Quoted 1 line
/dev/zeroresults in callingmap_zero()which on RHEL5 maps theZERO_PAGEin every pte within that virtual address range.
PTE is an acronym (please capitalize).
Quoted 1 line
Since a application is also multi-threaded the subsequent
munmap()of/dev/zeroresults is TLB shootdowns to all other CPUs.
Why isn't the test multithreaded then? How do you measure the poor performance resulting from all of the anonymous page TLB shootdowns?
Quoted 1 line
When this happens thousands or millions of times the application performance is terrible.
Well, TLB shootdown hurts no matter how many times it occurs, so I wouldn't doubt that thousands or millions or times would hurt more.
Quoted 1 line
The mapping
ZERO_PAGEin every pte within that virtual address range was an optimization to make the subsequent pagefault
Ok. I think I have an idea of what you're trying to achieve based on this statement, but I'm not quite sure. Are you saying that anonymous mapped pages without data should have an equivalent address to a shared zeroed out page? If so how do you know what the master zeroed out page is? Why aren't any memory address comparisons being performed below? Where's the performance trend data to prove that the feature delivers as per its claimed performance benefits?
Quoted 1 line
times faster on RHEL5 that.
How much faster?
Quoted 1 line
has been removed/changed upstream.
Reference?
Quoted 1 line
Signed-off-by CAI Qian <[email protected]>
...
testcases/kernel/syscalls/mmap/mmap10.c line 42
Quoted 8 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +8
-0+#include "test.h" +#include "usctest.h" +#include <errno.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <stdio.h>
It's not linux style (BSD style(9) to be exact), but could you at least sort the headers by:
sys/ system headers -> non-sys/ system headers -> `user defined' headers
in alphabetical order...? it's much easier to read.
Quoted 1 line
+#define SIZE (5*1024*1024)
Why 5MB?
Quoted 26 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +26
-0+char *TCID ="mmap10" ; +int TST_TOTAL =1 ; +extern int Tst_count; + +/* main setup function of test */ +void setup (void ); +/* cleanup function for the test */ +void cleanup (void ); +int mmapzero (void ); + +int main (int argc,char *argv[]) +{ + /* loop counter */ + int lc; + /* message returned from parse_opts */ + char *msg; + + msg = parse_opts(argc, argv, (option_t *) NULL, NULL); + if (msg != NULL) { + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + tst_exit(); + } + + /* Perform global setup for test */ + setup(); +
testcases/kernel/syscalls/mmap/mmap10.c line 81
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ /* Check looping state if -i option given */ + for (lc = 0; TEST_LOOPING(lc); lc++) { + /* Reset Tst_count in case we are looping. */ + Tst_count = 0; + + TEST(mmapzero()); + + if (TEST_RETURN != 0) + tst_resm(TFAIL, "mmapzero() failed with %ld.", + TEST_RETURN);
TEST_RETURN is an integer, not a long integer, correct (hence the %ld could be a %d)?
Quoted 13 lines
+ else
+tst_resm(TPASS, "mmapzero() completed successfully.");
+ }testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ + cleanup(); + return 0; +} + +int mmapzero (void ) +{ + char *x; + int n; +
testcases/kernel/syscalls/mmap/mmap10.c line 104
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ x = mmap("/dev/zero", SIZE+SIZE-4096, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (x == MAP_FAILED) { + tst_resm(TFAIL, "mmap: %s", strerror(errno)); + return 1; + } + x[SIZE] = 0; + n = fork(); + if (n == -1) + tst_brkm(TBROK, cleanup, "fork: %s", strerror(errno));
tst_brkm(TBROK|TERRNO, cleanup, "fork failed");
etc, would be better than using tst_brkm with strerror.
Quoted 4 lines
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)== -1)
+tst_resm(TFAIL, "munmap: %s", strerror(errno));
+_exit(0);
Quoted 8 lines
+ }
+ n =fork();
+ if (n == -1)
+tst_brkm(TBROK, cleanup, "fork: %s", strerror(errno));
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)== -1)
+tst_resm(TFAIL, "munmap: %s", strerror(errno));
+_exit(0);
What are you trying to achieve by munmap'ing the same section of
memory in a forked process [twice] and the parent process in the end? They're 3 anonymous COW backed pages because you specified MAP_PRIVATE | MAP_ANONYMOUS ...
Quoted 6 lines
+ } else {
+ n =fork();
+ if (n == -1)
+tst_brkm(TBROK, cleanup, "fork: %s", strerror(errno));
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)== -1)
Quoted 8 lines
+
tst_resm(TFAIL, "munmap: %s", strerror(errno));
+_exit(0);
+ }
+ }
+ if (munmap(x, SIZE+SIZE-4096)== -1)
+tst_resm(TFAIL, "munmap: %s", strerror(errno));
+ while (waitpid(-1, NULL, WNOHANG)> 0);
+ return 0;
This test isn't written according to the description. Please
better address what you're trying to achieve so that we might be able to help you reach a conclusion.
Thanks,
-Garrett
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 10 lines · ----- "Garrett Cooper
You've filled in some of the blanks, but there are some that are still
missing...Quoted 3 lines · On Tue, Oct 12, 2010 at 7:02 PM, <[email protected]> wrote:
v2: incorporate comments from Mike and Garrett.
Add a new test to mmap/munmap
/dev/zero. A common way ofmalloc()/free() anonymous memory on Solaris.
Quoted 7 lines
The first sentence should standalone as the summary, like:
Add a new test to mmap/munmap
/dev/zero[fill in reason why it's being
tested -- try to summarize in less than 80 columns].Right now it's a dangling modifier
It is important to test this scenarios because it is a common way of malloc()/free() anonymous memory on Solaris.
Quoted 121 lines
The second sentence is a fragment; you are describing the process, but
not describing the important actors or involved parties in the process
(in particular on the Linux side).There's also little context between the two sentences, so it's confusing to the end reader.
Quoted 1 line
Anyway,
You can remove Anyway,
Quoted 1 line
mmap()memory mapping
Quoted 1 line
of
unnecessary particle.
Quoted 1 line
/dev/zeroresults in callingmap_zero()which on RHEL5 maps the
ZERO_PAGEin every pte within that virtual address range.PTE is an acronym (please capitalize).
Quoted 1 line
Since a application is also multi-threaded the subsequent
munmap()of
/dev/zeroresults is TLB shootdowns to all other CPUs.Why isn't the test multithreaded then? How do you measure the poor performance resulting from all of the anonymous page TLB shootdowns?
Quoted 1 line
When this happens thousands or millions of times the application
performance is terrible.
Well, TLB shootdown hurts no matter how many times it occurs, so I wouldn't doubt that thousands or millions or times would hurt more.
Quoted 1 line
The mapping
ZERO_PAGEin every pte within that virtual address rangewas an optimization to make the subsequent pagefault
Ok. I think I have an idea of what you're trying to achieve based on this statement, but I'm not quite sure. Are you saying that anonymous mapped pages without data should have an equivalent address to a shared zeroed out page? If so how do you know what the master zeroed out page is? Why aren't any memory address comparisons being performed
below? Where's the performance trend data to prove that the feature delivers as per its claimed performance benefits?Quoted 1 line
times faster on RHEL5 that.
How much faster?
Quoted 1 line
has been removed/changed upstream.
Reference?
Quoted 1 line
Signed-off-by CAI Qian <[email protected]>...
testcases/kernel/syscalls/mmap/mmap10.c line 42
Quoted 8 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +8
-0+#include "test.h" +#include "usctest.h" +#include <errno.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <stdio.h> It's not linux style (BSD style(9) to be exact), but could you at least sort the headers by:
sys/ system headers -> non-sys/ system headers -> `user defined' headers
in alphabetical order...? it's much easier to read.
Quoted 1 line
+#define SIZE (5*1024*1024)
Why 5MB?
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+char *TCID ="mmap10" ; +int TST_TOTAL =1 ; +extern int Tst_count; + +/* main setup function of test */ +void setup (void ); +/* cleanup function for the test */ +void cleanup (void ); +int mmapzero (void ); +testcases/kernel/syscalls/mmap/mmap10.c
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+int main (int argc,char *argv[]) +{ + /* loop counter */ + int lc; + /* message returned from parse_opts */ + char *msg; + + msg = parse_opts(argc, argv, (option_t *) NULL, NULL); + if (msg != NULL) { + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s",msg);
Quoted 5 lines
+
tst_exit();
+ }testcases/kernel/syscalls/mmap/mmap10.c new file +3
-0+ + /* Perform global setup for test */ + setup();testcases/kernel/syscalls/mmap/mmap10.c
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ + /* Check looping state if -i option given */ + for (lc = 0; TEST_LOOPING(lc); lc++) { + /* Reset Tst_count in case we are looping. */ + Tst_count = 0; + + TEST(mmapzero()); + + if (TEST_RETURN != 0) + tst_resm(TFAIL, "mmapzero() failed with%ld.",
Quoted 4 lines
Quoted 1 line
+
TEST_RETURN);
TEST_RETURNis an integer, not a long integer, correct (hence the %ld could be a %d)?
OK, I am not familiar with this internal variable.
Quoted 27 lines
Quoted 3 lines
+ else
+ tst_resm(TPASS, "mmapzero()completedsuccessfully.");
Quoted 11 lines
+ }
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ + cleanup(); + return 0; +} + +int mmapzero (void ) +{ + char *x; + int n; +testcases/kernel/syscalls/mmap/mmap10.c
Quoted 10 lines
testcases/kernel/syscalls/mmap/mmap10.c new file +10
-0+ x = mmap("/dev/zero", SIZE+SIZE-4096, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (x == MAP_FAILED) { + tst_resm(TFAIL, "mmap: %s", strerror(errno)); + return 1; + } + x[SIZE] = 0; + n = fork(); + if (n == -1) + tst_brkm(TBROK, cleanup, "fork: %s",strerror(errno));
Quoted 3 lines
tst_brkm(TBROK|TERRNO, cleanup, "fork failed");etc, would be better than using
tst_brkmwith strerror.
OK.
Quoted 14 lines
Quoted 4 lines
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)== -1)
+ tst_resm(TFAIL, "munmap: %s",strerror(errno));
Quoted 5 lines
+
_exit(0);
+ }
+ n =fork();
+ if (n == -1)
+ tst_brkm(TBROK, cleanup, "fork: %s",strerror(errno));
Quoted 3 lines
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)== -1)
+ tst_resm(TFAIL, "munmap: %s",
Quoted 8 lines
strerror(errno));
Quoted 1 line
+
_exit(0);What are you trying to achieve by munmap'ing the same section of
memory in a forked process [twice] and the parent process in the end? They're 3 anonymous COW backed pages because you specifiedMAP_PRIVATE
|MAP_ANONYMOUS...
I'll explain in v4.
Quoted 19 lines
Quoted 5 lines
+ } else {
+ n =fork();
+ if (n == -1)
+ tst_brkm(TBROK, cleanup, "fork: %s",strerror(errno));
Quoted 2 lines
+ else if (n == 0) {
+ if (munmap(x + SIZE+4096, SIZE-4096*2)==-1)
Quoted 1 line
+ tst_resm(TFAIL, "munmap: %s",
strerror(errno));
Quoted 7 lines
+
_exit(0);
+ }
+ }
+ if (munmap(x, SIZE+SIZE-4096)== -1)
+tst_resm(TFAIL, "munmap: %s", strerror(errno));
+ while (waitpid(-1, NULL, WNOHANG)> 0);
+ return 0;
Quoted 3 lines
This test isn't written according to the description. Please
better address what you're trying to achieve so that we might be able to help you reach a conclusion.
v4 followed.
Quoted 2 lines
Thanks,
-Garrett
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list