Eric, 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 <[email protected]> > --- > hugeutils.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++----------- snip.. > + /* > + * Because the region was mmap'd with MAP_HUGETLB instead of > + * using hugetlbfs_unlinked_fd we cannot use the readv trick > + * to prefault each page. So instead we protect ourselves > + * from SIGSEGV and try to read from and write to the first > + * byte of each huge page to fault it. If we receive a > + * SIGSEGV then we return -ENOMEM > + */ > + sighandler_t orig = signal(SIGSEGV, handle_segv); > + if (orig == SIG_ERR) { > + ret = errno; > + WARNING("Unable to reserve %ld huge pages " > + "for new region\n", > + length / gethugepagesize()); > + return ret; > + } > + > + for (offset = 0; offset < length && !has_segv; > + offset += gethugepagesize()) { > + char *page_start = (char *)(addr + offset); > + *page_start = *page_start; > + } > + > + signal(SIGSEGV, orig); > + > + if (has_segv) { > + has_segv = 0; > + WARNING("Unable to reserve %ld huge pages " > + "for new region\n", > + length / gethugepagesize()); > + return -ENOMEM; > + } > } > > return 0;
I have a couple of concerns about this code: 1. Is it threadsafe? What if a separate thread in user code registers a SIGSEGV handler shortly after the libhugetlbfs handler is registered? 2. Is it guaranteed that the process will receive SIGSEGV when insufficient memory is available? I'd thought that the OOM killer sent SIGKILL. Perhaps it might be better to _not_ use MAP_HUGETLB if any type of prefaulting is required? -Andrew Hastings Cray Inc. ------------------------------------------------------------------------------ Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev _______________________________________________ Libhugetlbfs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
