Re: [PATCH v4 4/4] hugetlb: allow to free gigantic pages regardless of the configuration

From: Mike Kravetz
Date: Fri Mar 01 2019 - 12:53:25 EST


On 3/1/19 5:21 AM, Alexandre Ghiti wrote:
> On 03/01/2019 07:25 AM, Alex Ghiti wrote:
>> On 2/28/19 5:26 PM, Mike Kravetz wrote:
>>> On 2/28/19 12:23 PM, Dave Hansen wrote:
>>>> On 2/28/19 11:50 AM, Mike Kravetz wrote:
>>>>> On 2/28/19 11:13 AM, Dave Hansen wrote:
>>>>>>> + if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
>>>>>>> + spin_lock(&hugetlb_lock);
>>>>>>> + if (count > persistent_huge_pages(h)) {
>>>>>>> + spin_unlock(&hugetlb_lock);
>>>>>>> + return -EINVAL;
>>>>>>> + }
>>>>>>> + goto decrease_pool;
>>>>>>> + }
>>>>>> This choice confuses me. The "Decrease the pool size" code already
>>>>>> works and the code just falls through to it after skipping all the
>>>>>> "Increase the pool size" code.
>>>>>>
>>>>>> Why did did you need to add this case so early? Why not just let it
>>>>>> fall through like before?
>>>>> I assume you are questioning the goto, right? You are correct in that
>>>>> it is unnecessary and we could just fall through.
>>>> Yeah, it just looked odd to me.
>
>> I'd rather avoid useless checks when we already know they won't
>> be met and I think that makes the code more understandable.
>>
>> But that's up to you for the next version.

I too find some value in the goto. It tells me this !CONFIG_CONTIG_ALLOC
case is special and we are skipping the normal checks. But, removing the
goto is not a requirement for me.

>>>>> However, I wonder if we might want to consider a wacky condition that the
>>>>> above check would prevent. Consider a system/configuration with 5 gigantic
...
>>
>> If I may, I think that this is the kind of info the user wants to have and we should
>> return an error when it is not possible to allocate runtime huge pages.
>> I already noticed that if someone asks for 10 huge pages, and only 5 are allocated,
>> no error is returned to the user and I found that surprising.

Upon further thought, let's not consider this wacky permanent -> surplus ->
permanent case. I just can't see it being an actual use case.

IIUC, that 'no error' behavior is somewhat expected. I seem to recall previous
discussions about changing with the end result to leave as is.

>>>> @@ -2428,7 +2442,9 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
>>>> } else
>>>> nodes_allowed = &node_states[N_MEMORY];
>>>> - h->max_huge_pages = set_max_huge_pages(h, count, nodes_allowed);
>>>> + err = set_max_huge_pages(h, count, nodes_allowed);
>>>> + if (err)
>>>> + goto out;
>>>> if (nodes_allowed != &node_states[N_MEMORY])
>>>> NODEMASK_FREE(nodes_allowed);
>>> Do note that I beleive there is a bug the above change. The code after
>>> the out label is:
>>>
>>> out:
>>> NODEMASK_FREE(nodes_allowed);
>>> return err;
>>> }
>>>
>>> With the new goto, we need the same
>>> if (nodes_allowed != &node_states[N_MEMORY]) before NODEMASK_FREE().
>>>
>>> Sorry, I missed this in previous versions.
>>
>> Oh right, I'm really sorry I missed that, thank you for noticing.

This is the only issue I have with the code in hugetlb.c. For me, the
goto can stay or go. End result is the same.
--
Mike Kravetz