[PATCH] D71975: [Support] Support MF_HUGE_HINT on Linux and FreeBSD

Bruno Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 06:34:57 PST 2020


riccibruno added a comment.

In D71975#1809205 <https://reviews.llvm.org/D71975#1809205>, @bsdjhb wrote:

> For FreeBSD, `MAP_ALIGNED_SUPER` probably isn't what you want.  The default mmap() for MAP_ANON on FreeBSD tries to do what `MAP_ALIGNED_SUPER` does if the request is at least one large page in size first, and if that fails to find available address space, falls back to finding any possible virtual addresses (it does the two steps you are doing inside of mmap() itself).  Specifying `MAP_ALIGNED_SUPER` tells mmap() to only try the first pass and fail without trying the second pass, but then the second call to mmap() that you would make as a result would just do both passes anyway.


Ah, I did not know that. Thanks for your comment. The reason I used `MAP_ALIGNED_SUPER` is the note in the man page for mmap(2):

>   The MAP_ALIGNED_SUPER flag is an optimization that will align the mapping request to the size of a large page similar to MAP_ALIGNED [...]

but what you are saying is that for large enough requests with `MAP_ANON` the default is already `MAP_ALIGNED_SUPER` with a fallback. The only difference with using `MAP_ALIGNED_SUPER` is that we can detect if the first `mmap` fails and clear the `MF_HUGE_HINT` flag. However this is not actually useful since the `MF_HUGE_HINT` flag in the returned block of memory has no reliable meaning (on some systems the block of memory may use large pages even if `MF_HUGE_HINT` is cleared, and on some other systems the block of memory may use small pages even if `MF_HUGE_HINT` is set).

> FreeBSD doesn't currently have a "must-only-use-large-pages-and-never-demote-to-small-pages" flag which is probably what you would want to use here instead.  (We've talked about adding one, but no one has done it to date.)

Not really, `MF_HUGE_HINT` is only a hint and a fallback to small pages is entirely acceptable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71975/new/

https://reviews.llvm.org/D71975





More information about the llvm-commits mailing list