On (22/07/08 09:06), Adam Litke didst pronounce: > On Tue, 2008-07-22 at 13:18 +0100, Mel Gorman wrote: > > During preparation, a hugetlbfs file is mapped MAP_SHARED and the data > > copied. At this point, the hugepages have been allocated and exist in the > > page cache. The file later mapped MAP_PRIVATE which kernels after 2.6.26 > > will reserve hugepages in case mprotect() is called and a COW is required. > > > > In hugetlbfs we know it is very highly unlikely that read-only segments > > will be marked read-write. The impact is that the pages exist in page cache > > but additional pages are reserved which will never be used. This patch uses > > MAP_NORESERVE for all read-only mappings on the assumption mprotect() and > > writes never occur for these segments. > > > > Signed-off-by: Mel Gorman <[EMAIL PROTECTED]> > > --- > > elflink.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/elflink.c b/elflink.c > > index ce1cf02..ec1efb3 100644 > > --- a/elflink.c > > +++ b/elflink.c > > @@ -1068,12 +1068,12 @@ static void remap_segments(struct seg_info *seg, > > int num) > > 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 this is a read-only mapping, then use MAP_NORESERVE. > > + * The assumption is that the pages already exist in the > > + * hugetlbfs file and that mprotect() will not be called > > + * which would require a COW > > */ > > - if (sharing && !(seg[i].prot & PROT_WRITE)) > > + if (!(seg[i].prot & PROT_WRITE)) > > mmap_flags |= MAP_NORESERVE; > > > > p = mmap((void *) start, mapsize, seg[i].prot, > > Just to be on the safe side, I would recommend one more requirement for > the MAP_NORESERVE flag. Not only should the segment be writable, but
I don't quite get this. The segment should be read-only, not writable. > its seg[n].filesz should be equal to its seg[n].memsz. This makes sure > there cannot be uninitialized data in the mapping that hasn't been > copied yet. Note that text segments tend to meet this criteria (I have > never seen one that doesn't) so this is just playing it safe. > Assuming you meant read-only, I can post test and post a version that includes the additional test. -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab ------------------------------------------------------------------------- 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
