On Fri, Oct 13, 2006 at 12:45:44PM -0700, Nishanth Aravamudan wrote: > On 11.10.2006 [13:53:18 +1000], David Gibson wrote: > > A couple of questions about the mlock testcase added in commit > > ff2f5343e4a4e2d2e62173d557a7e5952cfa7733. > > > > First, is there a rationale for mlock()ing all the available hugepages > > (as passed in on the command line). I don't see an obvious reason > > that that's a useful thing to test (as opposed to just mlock()ing a > > sample page), and it makes the testcase run quite slowly. I'd like to > > keep the "functional" (rather than "stress") portion of the testsuite > > nice and fast, making for quicker cycle time when tracking down > > regressions. > > > > Second, the testcase maps the file both normally and with MAP_LOCKED, > > which ought to lock the file as with mlock() at mmap() time. It also > > explicitly mlock()s the file, but only when mapped with MAP_LOCKED > > which seems backwards. Surely we should be checking mlock() when the > > file was not originally locked. Is this really the intended > > behaviour. > > Your concerns seem pretty valid, David. > > Patches are welcome :)
Here you go, then: Simplify and speed up the mlock testcase. At present the mlock test case attempts to mlock() all available hugepages (as passed in on the command line). This isn't particularly more useful than just testing locking a single page. This patch reduces it to testing just a single page (with each set of mapping options). In addition, we were only testing actual mlock() calls on files opened with MAP_LOCKED, which are supposed to be mlock()ed anyway, rather an oversight. This patch corrects this also. What would be another useful test is to verify that mlock()ing really does reserve the page in question, i.e. that a page mlock()ed but not touched will always instantiate without fault later, even if all other hugepages on the system have been consumed. That's another patch for another day. Signed-off-by: David Gibson <[EMAIL PROTECTED]> Index: libhugetlbfs/tests/mlock.c =================================================================== --- libhugetlbfs.orig/tests/mlock.c 2006-09-04 17:08:33.000000000 +1000 +++ libhugetlbfs/tests/mlock.c 2006-10-16 11:41:22.000000000 +1000 @@ -29,46 +29,36 @@ #include <hugetlbfs.h> #include "hugetests.h" -static void test_simple_mlock(unsigned long size, unsigned long map_flags) +static void test_simple_mlock(int flags) { - char *a; - int ret; int fd = hugetlbfs_unlinked_fd(); + void *p; + int ret; - a = mmap(0, size, PROT_READ|PROT_WRITE, map_flags, fd, 0); - if (a == MAP_FAILED) - FAIL("mmap() failed: %s", strerror(errno)); - - if (map_flags & MAP_LOCKED) { - ret = mlock(a, size); - if (ret) - FAIL("mlock() failed: %s", strerror(errno)); - - ret = munlock(a, size); - if (ret) - FAIL("munlock() failed: %s", strerror(errno)); - } + p = mmap(0, gethugepagesize(), PROT_READ|PROT_WRITE, flags, fd, 0); + if (p == MAP_FAILED) + FAIL("mmap() failed (flags=%x): %s", flags, strerror(errno)); - ret = munmap(a, size); + ret = mlock(p, gethugepagesize()); if (ret) - FAIL("munmap() failed: %s", strerror(errno)); + FAIL("mlock() failed (flags=%x): %s", flags, strerror(errno)); + + ret = munlock(p, gethugepagesize()); + if (ret) + FAIL("munlock() failed (flags=%x): %s", flags, strerror(errno)); + + ret = munmap(p, gethugepagesize()); + if (ret) + FAIL("munmap() failed (flags=%x): %s", flags, strerror(errno)); close(fd); } int main(int argc, char *argv[]) { - unsigned long tot_pages, size; - - if (argc != 2) - CONFIG("Usage: mlock <# total available hugepages>"); - - tot_pages = atoi(argv[1]); - size = tot_pages * gethugepagesize(); - - test_simple_mlock(size, MAP_PRIVATE); - test_simple_mlock(size, MAP_SHARED); - test_simple_mlock(size, MAP_PRIVATE|MAP_LOCKED); - test_simple_mlock(size, MAP_SHARED|MAP_LOCKED); + test_simple_mlock(MAP_PRIVATE); + test_simple_mlock(MAP_SHARED); + test_simple_mlock(MAP_PRIVATE|MAP_LOCKED); + test_simple_mlock(MAP_SHARED|MAP_LOCKED); PASS(); } Index: libhugetlbfs/tests/run_tests.sh =================================================================== --- libhugetlbfs.orig/tests/run_tests.sh 2006-10-16 11:17:10.000000000 +1000 +++ libhugetlbfs/tests/run_tests.sh 2006-10-16 11:25:06.000000000 +1000 @@ -109,7 +109,7 @@ functional_tests () { run_test truncate run_test shared run_test mprotect - run_test mlock `free_hpages` + run_test mlock # Specific kernel bug tests run_test ptrace-write-hugepage -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel