Re: PROBLEM: Remapping hugepages mappings causes kernel to return EINVAL

From: Mike Kravetz
Date: Fri Oct 27 2017 - 13:06:21 EST


On 10/27/2017 07:29 AM, Vlastimil Babka wrote:
> On 10/24/2017 09:41 AM, C.Wehrmeyer wrote:
>> On 2017-10-23 20:02, Michal Hocko wrote:
>>> On Mon 23-10-17 19:52:27, C.Wehrmeyer wrote:
>>> [...]
>>
>> 1. Provide a flag to mmap, which might be something different from
>> MAP_HUGETLB. After all your question revolved merely around properly
>> aligned pages - we don't want to *force* the kernel to reserve
>> hugepages, we just want it to provide the proper alignment in this case.
>> That wouldn't be very transparent, but it would be the easiest route to
>> go (and mmap already kind-of supports such a thing).
>
> Maybe just have mmap() detect that the requested size is a multiple of
> huge page size, and then align it automatically? I.e. a heuristic that
> should work in 99% of the cases?

We already do this for DAX (see thp_get_unmapped_area). So, not much
code to write. But could potentially fragment address spaces more.
We could also check to determine if the system/process/mapping is even
THP enabled before doing the alignment.

I like the idea, but still am concerned about fragmentation. In addition,
even though applications shouldn't care where new mappings are placed it
would not surprise me that such a change will be noticeable to some.

--
Mike Kravetz