On Fri, Nov 19, 2010 at 04:33:54PM -0700, Eric B Munson wrote: > hugetlbfs_prefault relies on having a file descriptor associated with > the huge page backed region to prefault the huge pages. This patch > gives an alternative for prefaulting which will be used when the > kernel supports MAP_HUGETLB. > > Signed-off-by: Eric B Munson <emun...@mgebm.net> > --- > hugeutils.c | 59 > ++++++++++++++++++++++++++++++++++++++--------------------- > 1 files changed, 38 insertions(+), 21 deletions(-) > > diff --git a/hugeutils.c b/hugeutils.c > index bf9fb85..ecbfc29 100644 > --- a/hugeutils.c > +++ b/hugeutils.c > @@ -956,6 +956,15 @@ int hugetlbfs_unlinked_fd(void) > #define IOV_LEN 64 > int hugetlbfs_prefault(int fd, void *addr, size_t length) > { > + size_t offset; > + struct iovec iov[IOV_LEN]; > + int ret; > + int i; > + int close_fd = -1; > + > + if (!__hugetlbfs_prefault) > + return 0; > + > /* > * The NUMA users of libhugetlbfs' malloc feature are > * expected to use the numactl program to specify an > @@ -972,30 +981,38 @@ int hugetlbfs_prefault(int fd, void *addr, size_t > length) > * -ENOMEM is returned. The caller is expected to release the entire > * mapping and optionally it may recover by mapping base pages instead. > */ > - if (__hugetlbfs_prefault) { > - int i; > - size_t offset; > - struct iovec iov[IOV_LEN]; > - int ret; > - > - for (offset = 0; offset < length; ) { > - for (i = 0; i < IOV_LEN && offset < length; i++) { > - iov[i].iov_base = addr + offset; > - iov[i].iov_len = 1; > - offset += gethugepagesize(); > - } > - ret = readv(fd, iov, i); > - if (ret != i) { > - DEBUG("Got %d of %d requested; err=%d\n", ret, > - i, ret < 0 ? errno : 0); > - WARNING("Failed to reserve %ld huge pages " > - "for new region\n", > - length / gethugepagesize()); > - return -ENOMEM; > - } > + > + if (fd < 0 && __hugetlb_opts.map_hugetlb) { > + fd = open("/dev/zero", O_RDONLY); > + if (fd < 0) { > + ERROR("Failed to open /dev/zero for reading\n"); > + return -ENOMEM; > + } > + close_fd = fd; > + } > + > + for (offset = 0; offset < length; ) { > + for (i = 0; i < IOV_LEN && offset < length; i++) { > + iov[i].iov_base = addr + offset; > + iov[i].iov_len = 1; > + offset += gethugepagesize(); > + } > + ret = readv(fd, iov, i); > + if (ret != i) { > + DEBUG("Got %d of %d requested; err=%d\n", ret, > + i, ret < 0 ? errno : 0); > + WARNING("Failed to reserve %ld huge pages " > + "for new region\n", > + length / gethugepagesize()); > + if (close_fd >= 0) > + close(close_fd); > + return -ENOMEM; > }
I'm missing something. How does opening /dev/zero guarantee that we are checking for huge page availability? This looks like we are just prefaulting some base pages. Should we consider MAP_HUGETLB and prefaulting incompatible? That said, the availability of MAP_HUGETLB in the kernel guarantees that proper reservations are also available due to the timing the features were introduced. > } > > + if (close_fd >= 0) > + close(close_fd); > + > return 0; > } > > -- > 1.7.1 > > > ------------------------------------------------------------------------------ > 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/msIE9-sfdev2dev > _______________________________________________ > Libhugetlbfs-devel mailing list > Libhugetlbfs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel > -- 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