Re: [patch] hugetlb: add hugepage reservation upon mremap expansion.

From: Ken Chen
Date: Wed Nov 09 2011 - 15:47:57 EST


On Fri, Nov 4, 2011 at 3:13 PM, Hugh Dickins <hughd@xxxxxxxxxx> wrote:
> But changing i_size in mmap and mremap is unusual, if not simply wrong.
> The size of mmap or mremap is the size of a userspace mapping, which
> is modified by mmap, mremap, munmap.  The size of the underlying object
> is usually independent of that, and modified by ftruncate or write.
>
> It was suggested a few years ago that it would be helpful if mremap of
> a shared anonymous shmem object would change the size of the underlying
> object, instead of just giving SIGBUS on the enlargement; but in the
> end I played cautious, and made no change there.

Indeed, that would be undesirable to modify i_size in mremap(). For small
page, the only mapping one can truly expand beyond file size via mremap()
is private anon. All other cases it will SIGBUS at the time of fault. In
that respect, I think hugetlb should match the behavior of small page as
well. I will add a size check for hugetlb mapping and disallow new size
to pass beyond i_size.

Then there are cases of taking partial region and perform an mremap
expansion: e.g.
addr = mmap(.., SIZE, ..)
mremap(addr, SIZE / 2, SIZE, ...);

Which for shared mapping, it is fine because everything is already
reserved. For private mapping, a new set of expansion would be needed.
I will re-post with updated changes on this.

- Ken
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/