On Mon, 2008-07-14 at 22:17 +0100, Mel Gorman wrote:
> When HUGETLB_SHARE=1, read-only text segments are copied to a file on
> a hugetlbfs mount and shared between multiple processes. However with
> kernel 2.6.27 and later, the expectation is that pages will be reserved for
> MAP_PRIVATE mappings as well as MAP_SHARED. This will render HUGETLB_SHARE
> ineffective as huge pages will be reserved that already exist in the page
> cache. This patch disables reservations for read-only mappings when sharing
> is enabled on the assumption mprotect() will never be called for remapped
> read-only segments.
Hmm. Is it possible to safely do this for read-only segments even when
HUGETLB_SHARE is not set? I think the same assumption (that we won't
cow the readonly mapping) applies and MAP_NORESERVE will reduce actual
hugepage footprint (including consumed huge pages and unused reserved
pages) in the linkhuge_rw testcase from 4 pages to 3 when using
HUGETLB_ELFMAP=RW and from 2 to 1 when HUGETLB_ELFMAP=R.
>
> Signed-off-by: Mel Gorman <[EMAIL PROTECTED]>
> ---
> diff --git a/elflink.c b/elflink.c
> index 2816f8f..fdb5698 100644
> --- a/elflink.c
> +++ b/elflink.c
> @@ -1035,6 +1035,7 @@ static void remap_segments(struct seg_info *seg, int
> num)
> unsigned long start, offset, mapsize;
> long page_size = getpagesize();
> long hpage_size = gethugepagesize();
> + int mmap_flags;
>
> /*
> * XXX: The bogus call to mmap below forces ld.so to resolve the
> @@ -1064,9 +1065,19 @@ static void remap_segments(struct seg_info *seg, int
> num)
> start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size);
> offset = (unsigned long)(seg[i].vaddr - start);
> mapsize = ALIGN(offset + seg[i].memsz, hpage_size);
> + mmap_flags = MAP_PRIVATE|MAP_FIXED;
> +
> + /*
> + * If HUGETLB_SHARE is enabled and this is a read-only
> + * segment, then use MAP_NORESERVE. The assumption is that
> + * the pages already exist in the hugetlbfs file and that
> + * mprotect() will not be called requiring a COW
> + */
> + if (sharing && !(seg[i].prot & PROT_WRITE))
> + mmap_flags |= MAP_NORESERVE;
>
> p = mmap((void *) start, mapsize, seg[i].prot,
> - MAP_PRIVATE|MAP_FIXED, seg[i].fd, 0);
> + mmap_flags, seg[i].fd, 0);
> if (p == MAP_FAILED)
> unmapped_abort("Failed to map hugepage segment %u: "
> "%p-%p (errno=%u)\n", i, start,
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> Libhugetlbfs-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
>
--
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel