From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752597AbbC3Bfm (ORCPT ); Sun, 29 Mar 2015 21:35:42 -0400 Received: from mail-pd0-f178.google.com ([209.85.192.178]:33497 "EHLO mail-pd0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbbC3Bfi (ORCPT ); Sun, 29 Mar 2015 21:35:38 -0400 Date: Sun, 29 Mar 2015 18:35:34 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: David Rientjes cc: Andrew Morton , Jonathan Corbet , Davide Libenzi , Luiz Capitulino , Shuah Khan , Hugh Dickins , Andrea Arcangeli , Joern Engel , Jianguo Wu , Eric B Munson , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [patch 1/2] mm, doc: cleanup and clarify munmap behavior for hugetlb memory In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Mar 2015, David Rientjes wrote: > munmap(2) of hugetlb memory requires a length that is hugepage aligned, > otherwise it may fail. Add this to the documentation. Thanks for taking this on, David. But although munmap(2) is the one Davide called out, it goes beyond that, doesn't it? To mprotect and madvise and ... I don't want to work out the list myself: is_vm_hugetlb_page() is special-cased all over, and different syscalls react differently. Which is another reason why, like you, I much prefer not to interfere with the long established behavior: it would be very easy to introduce bugs and worse inconsistencies. And mprotect(2) is a good example of why we should not mess around with the long established API here: changing an mprotect from failing on a particular size to acting on a larger size is not a safe change. Eric, I apologize for bringing you in to the discussion, and then ignoring your input. I understand that you would like MAP_HUGETLB to behave more understandably. We can all agree that the existing behavior is unsatisfying. But it's many years too late now to change it around - and I suspect that a full exercise to do so would actually discover some good reasons why the original choices were made. > > This also cleans up the documentation and separates it into logical > units: one part refers to MAP_HUGETLB and another part refers to > requirements for shared memory segments. > > Signed-off-by: David Rientjes > --- > Documentation/vm/hugetlbpage.txt | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/Documentation/vm/hugetlbpage.txt b/Documentation/vm/hugetlbpage.txt > --- a/Documentation/vm/hugetlbpage.txt > +++ b/Documentation/vm/hugetlbpage.txt > @@ -289,15 +289,20 @@ file systems, write system calls are not. > Regular chown, chgrp, and chmod commands (with right permissions) could be > used to change the file attributes on hugetlbfs. > > -Also, it is important to note that no such mount command is required if the > +Also, it is important to note that no such mount command is required if > applications are going to use only shmat/shmget system calls or mmap with > -MAP_HUGETLB. Users who wish to use hugetlb page via shared memory segment > -should be a member of a supplementary group and system admin needs to > -configure that gid into /proc/sys/vm/hugetlb_shm_group. It is possible for > -same or different applications to use any combination of mmaps and shm* > -calls, though the mount of filesystem will be required for using mmap calls > -without MAP_HUGETLB. For an example of how to use mmap with MAP_HUGETLB see > -map_hugetlb.c. > +MAP_HUGETLB. For an example of how to use mmap with MAP_HUGETLB see map_hugetlb > +below. > + > +Users who wish to use hugetlb memory via shared memory segment should be a > +member of a supplementary group and system admin needs to configure that gid > +into /proc/sys/vm/hugetlb_shm_group. It is possible for same or different > +applications to use any combination of mmaps and shm* calls, though the mount of > +filesystem will be required for using mmap calls without MAP_HUGETLB. > + > +When using munmap(2) to unmap hugetlb memory, the length specified must be > +hugepage aligned, otherwise it will fail with errno set to EINVAL. Perhaps just adding something like "The same is true for mprotect(2) and other such memory system calls." is good enough for here. > + > > Examples > ========