Re: [PATCH v5] hugetlbfs: Get unmapped area below TASK_UNMAPPED_BASE for hugetlbfs

From: Mike Kravetz
Date: Mon May 18 2020 - 00:16:42 EST


On 5/16/20 12:47 AM, Hushijie wrote:
>> On 5/14/20 7:31 AM, Shijie Hu wrote:
>>> + if (mm->get_unmapped_area == arch_get_unmapped_area)
>>> + return hugetlb_get_unmapped_area_bottomup(file, addr, len,
>>> + pgoff, flags);
>>> + return hugetlb_get_unmapped_area_topdown(file, addr, len,
>>> + pgoff, flags);
>>
>> I like this code using the value of mm->get_unmapped_area to determine
>> which routine to call. It is used by a few architectures. However, I
>> noticed that on at least one architecture (powerpc) mm->get_unmapped_area
>> may be assigned to routines other than arch_get_unmapped_area or
>> arch_get_unmapped_area_topdown. In such a case, we would call the 'new'
>> topdown routine. I would prefer that we call the bottomup routine in this
>> default case.
>>
>> In reality, this does not impact powerpc as that architecture has it's
>> own hugetlb_get_unmapped_area routine.
>>
>
> Yes, I also noticed this before, powerpc uses radix__arch_get_unmapped_area*()
> when CONFIG_PPC_RADIX_MMU opened as 'y' and radix_enabled() returns
> true. However, powerpc implemented its own hugetlb_get_unmapped_area(). This
> patch actually has no effect on powerpc.
>
>> Because of this, I suggest we add a comment above this code and switch
>> the if/else order. For example,
>>
>> + /*
>> + * Use mm->get_unmapped_area value as a hint to use topdown routine.
>> + * If architectures have special needs, they should define their own
>> + * version of hugetlb_get_unmapped_area.
>> + */
>> + if (mm->get_unmapped_area == arch_get_unmapped_area_topdown)
>> + return hugetlb_get_unmapped_area_topdown(file, addr, len,
>> + pgoff, flags);
>> + return hugetlb_get_unmapped_area_bottomup(file, addr, len,
>> + pgoff, flags);
>>
>> Thoughts?
>> --
>> Mike Kravetz
>>
> I agree with you. It's clever to switch the if/else order. If there is such
> a case, mm->get_unmapped_area() is neihter arch_get_unmapped_area() nor
> arch_get_unmapped_area_topdown(), it is indeed more appropriate to make the
> bottomup routine as the default behavior.
>
> May I put this code and comment you show above into patch v6 and add
> "Signed-off-by: Mike Kravetz <mike.kravetz@xxxxxxxxxx>" to it?

Feel free to add this code and my Signed-off-by.

I assume this still works for your use case. Correct?
--
Mike Kravetz