From: Mike Kravetz <mike.kravetz@oracle.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
Davidlohr Bueso <dave@stgolabs.net>,
David Rientjes <rientjes@google.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Kravetz <mike.kravetz@oracle.com>
Subject: [PATCH v4 0/3] alloc_huge_page/hugetlb_reserve_pages race
Date: Tue, 2 Jun 2015 09:59:10 -0700 [thread overview]
Message-ID: <1433264353-4050-1-git-send-email-mike.kravetz@oracle.com> (raw)
v3 of patch did not take hugetlbfs min_size into account as noted
in change log.
While working on hugetlbfs fallocate support, I noticed the following
race in the existing code. It is unlikely that this race is hit very
often in the current code. However, if more functionality to add and
remove pages to hugetlbfs mappings (such as fallocate) is added the
likelihood of hitting this race will increase.
alloc_huge_page and hugetlb_reserve_pages use information from the
reserve map to determine if there are enough available huge pages to
complete the operation, as well as adjust global reserve and subpool
usage counts. The order of operations is as follows:
- call region_chg() to determine the expected change based on reserve map
- determine if enough resources are available for this operation
- adjust global counts based on the expected change
- call region_add() to update the reserve map
The issue is that reserve map could change between the call to region_chg
and region_add. In this case, the counters which were adjusted based on
the output of region_chg will not be correct.
In order to hit this race today, there must be an existing shared hugetlb
mmap created with the MAP_NORESERVE flag. A page fault to allocate a huge
page via this mapping must occur at the same another task is mapping the
same region without the MAP_NORESERVE flag.
The patch set does not prevent the race from happening. Rather, it adds
simple functionality to detect when the race has occurred. If a race is
detected, then the incorrect counts are adjusted.
Review comments pointed out the need for documentation of the existing
region/reserve map routines. This patch set also adds documentation
in this area.
v4:
Reserve count adjustments need to take into account hugetlbfs min_size
reservation pools
v3:
Created separate patch for new documentation created in v2
Added VM_BUG_ON() to region add at suggestion of Naoya Horiguchi
__vma_reservation_common keys off parameter commit for easier reading
v2:
Added documentation for the region/reserve map routines
Created common routine for vma_commit_reservation and
vma_commit_reservation to help prevent them from drifting
apart in the future.
Mike Kravetz (3):
mm/hugetlb: document the reserve map/region tracking routines
mm/hugetlb: compute/return the number of regions added by region_add()
mm/hugetlb: handle races in alloc_huge_page and hugetlb_reserve_pages
mm/hugetlb.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 133 insertions(+), 30 deletions(-)
--
2.1.0
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2015-06-02 17:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 16:59 Mike Kravetz [this message]
2015-06-02 16:59 ` [PATCH v4 1/3] mm/hugetlb: document the reserve map/region tracking routines Mike Kravetz
2015-06-02 16:59 ` [PATCH v4 2/3] mm/hugetlb: compute/return the number of regions added by region_add() Mike Kravetz
2015-06-02 16:59 ` [PATCH v4 3/3] mm/hugetlb: handle races in alloc_huge_page and hugetlb_reserve_pages Mike Kravetz
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=1433264353-4050-1-git-send-email-mike.kravetz@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=lcapitulino@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=rientjes@google.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;
as well as URLs for NNTP newsgroup(s).