On Fri, Nov 19, 2010 at 04:33:55PM -0700, Eric B Munson wrote: > When MAP_HUGETLB is used, the standard test for a maaping being backed by huge
s/maaping/mapping/ > pages fails because the mapping will not be on hugetlbfs. Instead of testing > the filesystem backing the mapping, this patch adds a check of reported MMU > page size from /proc/self/smaps. get_mapping_page_size returns the page > size that is being used for the specified mapping in bytes. > > Signed-off-by: Eric B Munson <emun...@mgebm.net> > --- > tests/hugetests.h | 1 + > tests/testutils.c | 53 > +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+), 0 deletions(-) > > diff --git a/tests/hugetests.h b/tests/hugetests.h > index 85f5b4f..a5a54d6 100644 > --- a/tests/hugetests.h > +++ b/tests/hugetests.h > @@ -45,6 +45,7 @@ void check_must_be_root(void); > void check_hugetlb_shm_group(void); > void test_init(int argc, char *argv[]); > int test_addr_huge(void *p); > +unsigned long long get_mapping_page_size(void *p); > long read_meminfo(const char *tag); > ino_t get_addr_inode(void *p); > > diff --git a/tests/testutils.c b/tests/testutils.c > index b8a1bf2..bc8c585 100644 > --- a/tests/testutils.c > +++ b/tests/testutils.c > @@ -162,6 +162,59 @@ static int read_maps(unsigned long addr, char *buf) > return 0; > } > > +/* > + * With the inclusion of MAP_HUGETLB it is now possible to have huge pages > + * without using hugetlbfs, so not all huge page regions will show with the > + * test that reads /proc/self/maps. Instead we ask /proc/self/smaps for > + * the MMUPageSize. On success we return the page size (in bytes) for the > + * mapping that contains addr, on failure we return 0 > + */ > +unsigned long long get_mapping_page_size(void *p) > +{ > + FILE *f; > + char line[MAPS_BUF_SZ]; > + char *tmp; > + unsigned long addr = (unsigned long)p; > + > + f = fopen("/proc/self/smaps", "r"); > + if (!f) { > + ERROR("Unable to open /proc/self/smaps\n"); > + return 0; > + } > + > + while ((tmp = fgets(line, MAPS_BUF_SZ, f))) { > + unsigned long start, end, dummy; > + char map_name[256]; > + char buf[64]; > + int ret; > + > + ret = sscanf(line, "%lx-%lx %s %lx %s %ld %s", &start, &end, > + buf, &dummy, buf, &dummy, map_name); > + if (ret < 7 || start > addr || end <= addr) > + continue; > + > + while ((tmp = fgets(line, MAPS_BUF_SZ, f))) { > + unsigned long long page_size; > + > + ret = sscanf(line, "MMUPageSize: %lld kB", &page_size); > + if (ret == 0 ) You want the KernelPageSize here, not the MMUPageSize. Most of the time, they are the same. The only time there is a difference is on ppc64 with 64K base page size on older processors that do not support 64K pages. In this case, the kernel page size is 64K as expected by the MMU page size is 4K. I can't think of a case where you hit an error here as such because you'll always be dealing with a huge page size but it's vaguely possible we'll hit a snag in the future. > + continue; > + if (ret < 1 || page_size <= 0) { > + ERROR("Cannot parse /proc/self/smaps\n"); > + page_size = 0; > + } > + > + fclose(f); > + /* page_size is reported in kB, we return B */ > + return page_size * 1024; > + } > + } > + > + /* We couldn't find an entry for this addr in smaps */ > + fclose(f); > + return 0; > +} > + > /* We define this function standalone, rather than in terms of > * hugetlbfs_test_path() so that we can use it without -lhugetlbfs for > * testing PRELOAD */ -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel