linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Bruce Merry <bmerry@ska.ac.za>, Linux MM <linux-mm@kvack.org>,
	Mike Kravetz <mike.kravetz@oracle.com>
Subject: Re: Is MAP_POPULATE supposed to fail silently?
Date: Tue, 9 Mar 2021 11:32:25 +0100	[thread overview]
Message-ID: <a1c18758-d587-12cc-04a6-fe026cf9d682@redhat.com> (raw)
In-Reply-To: <CAOm-9aquXZUmt9kHeYCWUqgvgyphP7cf=z1DVX90PK=xqduoiQ@mail.gmail.com>

On 09.03.21 10:33, Bruce Merry wrote:
> Hi
> 
> I've run into a problem with using mmap(..., MAP_ANONYMOUS | 
> MAP_POPULATE | MAP_HUGETLB). If there are no huge pages available due to 
> vm.nr_hugepages (or hugetlb.2MB.rsvd.limit_in_bytes cgroup setting) then 
> the mmap call fails and I can gracefully fall back to 4KB pages. 
> However, if neither of the above apply but hugetlb.2MB.limit_in_bytes 
> prevents pages being mapped, then it appears that MAP_POPULATE is 
> silently ignored (according to mincore), and rather than being able to 
> gracefully fall back, attempting to use the memory results in SIGBUS.

I would have imagined that the hugepage reservation would fail. But 
looks like they might get reserved, however, actual population is 
restricted using cgroups later.

Huge page reservation is actually pretty weird in some special cases 
(including NUMA bindings).

> 
> Is that expected behaviour? I don't see anything in the mmap(2) man page 
> about it being best-effort (in contrast to MAP_LOCKED, which explicitly 
> says the call won't fail if it can't lock the memory).

I think it has been best-effort forever, just like MAP_LOCKED.

You could use memfd_create() to create an anonymous file backed by huge 
pages, then try allocating backend storage using fallocate() - which 
fails in a safe way. You just have to make sure to map it MAP_SHARED 
later to avoid nasty side effects with private mappings + fallocate().

> 
> This is on Linux 5.8 on Ubuntu 20.04. I can provide sample code if it's 
> of interest, or test on a newer kernel if it'll help.
> 

Note that I'm working on a reliable populate mechanism that can also 
work on parts of a mapping only, especially relevant in combination with 
MAP_NORESERVE. Not sure if that applies to your use case, sounds like 
memfd_create() +fallocate() could be good enough - unless you also 
really want to have all page tables properly populated already or really 
need MAP_PRIVATE.

https://lkml.kernel.org/r/20210308164520.18323-1-david@redhat.com

-- 
Thanks,

David / dhildenb



  reply	other threads:[~2021-03-09 10:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09  9:33 Bruce Merry
2021-03-09 10:32 ` David Hildenbrand [this message]
2021-03-09 11:10   ` Bruce Merry
2021-03-09 18:54     ` 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=a1c18758-d587-12cc-04a6-fe026cf9d682@redhat.com \
    --to=david@redhat.com \
    --cc=bmerry@ska.ac.za \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.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