On Wed, Apr 24, 2013 at 04:20:50PM +0800, Jianguo Wu wrote: ... > Hi Naoya, > > I think the -EINVAL is returned from hugetlb_get_unmapped_area(), > for the two testcases: > 1) $ ./mmappu $((5 * 2 * 1024 * 1024 - 4096)) //len1 = 0x9ff000 > 2) $ ./mmappu $((5 * 2 * 1024 * 1024 - 4095)) //len2 = 0x9ff001 > > In do_mmap_pgoff(), after "len = PAGE_ALIGN(len);", len1 = 0x9ff000, > len2 = 0xa00000, so len2 will pass "if (len & ~huge_page_mask(h))" check in > hugetlb_get_unmapped_area(), and len1 will return -EINVAL. As follow: > > do_mmap_pgoff() > { > ... > /* Careful about overflows.. */ > len = PAGE_ALIGN(len); > ... > get_unmapped_area() > -->hugetlb_get_unmapped_area() > { > ... > if (len & ~huge_page_mask(h)) > return -EINVAL; > ... > } > } You are right, Jianguo. Thanks you. I totally missed the point. > > do we need to align len to hugepage size if it's hugetlbfs mmap? something like below: > > --- > mm/mmap.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index 0db0de1..bd42be24 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1188,7 +1188,10 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, > addr = round_hint_to_min(addr); > > /* Careful about overflows.. */ > - len = PAGE_ALIGN(len); > + if (file && is_file_hugepages(file)) > + len = ALIGN(len, huge_page_size(hstate_file(file))); > + else > + len = PAGE_ALIGN(len); > if (!len) > return -ENOMEM; > > -- I like putting this alignment code in if (flags & MAP_HUGETLB) branch in SYSCALL_DEFINE6(mmap_pgoff) as Johannes pointed out in another subthread, because it adds no impact on mmap calls with !MAP_HUGETLB. Thanks, Naoya Horiguchi -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>