From: Eric B Munson <emunson@akamai.com>
To: David Rientjes <rientjes@google.com>
Cc: Davide Libenzi <davidel@xmailserver.org>,
Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Joern Engel <joern@logfs.org>, Jianguo Wu <wujianguo@huawei.com>,
linux-mm@kvack.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [patch][resend] MAP_HUGETLB munmap fails with size not 2MB aligned
Date: Fri, 27 Mar 2015 09:51:39 -0400 [thread overview]
Message-ID: <20150327135139.GA10747@akamai.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1503261250430.9410@chino.kir.corp.google.com>
[-- Attachment #1: Type: text/plain, Size: 3658 bytes --]
On Thu, 26 Mar 2015, David Rientjes wrote:
> On Thu, 26 Mar 2015, Davide Libenzi wrote:
>
> > > Yes, this munmap() behavior of lengths <= hugepage_size - PAGE_SIZE for a
> > > hugetlb vma is long standing and there may be applications that break as a
> > > result of changing the behavior: a database that reserves all allocated
> > > hugetlb memory with mmap() so that it always has exclusive access to those
> > > hugepages, whether they are faulted or not, and maintains its own hugepage
> > > pool (which is common), may test the return value of munmap() and depend
> > > on it returning -EINVAL to determine if it is freeing memory that was
> > > either dynamically allocated or mapped from the hugetlb reserved pool.
> >
> > You went a long way to create such a case.
> > But, in your case, that application will erroneously considering hugepage
> > mmaped memory, as dynamically allocated, since it will always get EINVAL,
> > unless it passes an aligned size. Aligned size, which a fix like the one
> > posted in the patch will still leave as success.
>
> There was a patch proposed last week to add reserved pools to the
> hugetlbfs mount option specifically for the case where a large database
> wants sole reserved access to the hugepage pool. This is why hugetlbfs
> pages become reserved on mmap(). In that case, the database never wants
> to do munmap() and instead maintains its own hugepage pool.
>
> That makes the usual database case, mmap() all necessary hugetlb pages to
> reserve them, even easier since they have historically had to maintain
> this pool amongst various processes.
>
> Is there a process out there that tests for munmap(ptr) == EINVAL and, if
> true, returns ptr to its hugepage pool? I can't say for certain that none
> exist, that's why the potential for breakage exists.
Such an application can use /proc/pid/smaps to determine the page size
of a mapping. IMO, this is relying on broken behavior but I see where
you are coming from that this behavior has been present for a long time.
As I stated before, I think we should fix this bug and make munmap()
behavior match what is described in the man page.
>
> > OTOH, an application, which might be more common than the one you posted,
> > which calls munmap() to release a pointer which it validly got from a
> > previous mmap(), will leak huge pages as all the issued munmaps will fail.
> >
>
> That application would have to be ignoring an EINVAL return value.
>
> > > If we were to go back in time and decide this when the munmap() behavior
> > > for hugetlb vmas was originally introduced, that would be valid. The
> > > problem is that it could lead to userspace breakage and that's a
> > > non-starter.
> > >
> > > What we can do is improve the documentation and man-page to clearly
> > > specify the long-standing behavior so that nobody encounters unexpected
> > > results in the future.
> >
> > This way you will leave the mmap API with broken semantics.
> > In any case, I am done arguing.
> > I will leave to Andrew to sort it out, and to Michael Kerrisk to update
> > the mmap man pages with the new funny behaviour.
> >
>
> The behavior is certainly not new, it has always been the case for
> munmap() on hugetlb vmas.
>
> In a strict POSIX interpretation, it refers only to pages in the sense of
> what is returned by sysconf(_SC_PAGESIZE). Such vmas are not backed by
> any pages of size sysconf(_SC_PAGESIZE), so this behavior is undefined.
> It would be best to modify the man page to explicitly state this for
> MAP_HUGETLB.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-03-27 13:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-23 2:26 Davide Libenzi
2015-03-26 0:47 ` Hugh Dickins
2015-03-26 1:06 ` Davide Libenzi
2015-03-26 3:17 ` David Rientjes
2015-03-26 11:56 ` Davide Libenzi
2015-03-26 14:08 ` Eric B Munson
2015-03-30 16:03 ` KOSAKI Motohiro
2015-03-30 20:32 ` Hugh Dickins
2015-03-26 19:15 ` David Rientjes
2015-03-26 19:39 ` Davide Libenzi
2015-03-26 20:03 ` David Rientjes
2015-03-27 9:47 ` Vlastimil Babka
2015-03-27 13:51 ` Eric B Munson [this message]
2015-03-27 9:45 ` Vlastimil Babka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150327135139.GA10747@akamai.com \
--to=emunson@akamai.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=davidel@xmailserver.org \
--cc=hughd@google.com \
--cc=joern@logfs.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=wujianguo@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox