Re: [PATCH v3 1/5] hugetlb: add demote hugetlb page sysfs interfaces

From: Mike Kravetz
Date: Mon Oct 04 2021 - 14:28:14 EST


On 10/4/21 6:00 AM, Oscar Salvador wrote:
> On Fri, Oct 01, 2021 at 10:52:06AM -0700, Mike Kravetz wrote:
>> -which function as described above for the default huge page-sized case.
>> +The demote interfaces provide the ability to split a huge page into
>> +smaller huge pages. For example, the x86 architecture supports both
>> +1GB and 2MB huge pages sizes. A 1GB huge page can be split into 512
>> +2MB huge pages. Demote interfaces are not available for the smallest
>> +huge page size. The demote interfaces are:
>> +
>> +demote_size
>> + is the size of demoted pages. When a page is demoted a corresponding
>> + number of huge pages of demote_size will be created. By default,
>> + demote_size is set to the next smaller huge page size. If there are
>> + multiple smaller huge page sizes, demote_size can be set to any of
>> + these smaller sizes. Only huge page sizes less then the current huge
>
> s/then/than ?
>

Thanks

>> static void __init hugetlb_init_hstates(void)
>> {
>> - struct hstate *h;
>> + struct hstate *h, *h2;
>>
>> for_each_hstate(h) {
>> if (minimum_order > huge_page_order(h))
>> @@ -2995,6 +2995,23 @@ static void __init hugetlb_init_hstates(void)
>> /* oversize hugepages were init'ed in early boot */
>> if (!hstate_is_gigantic(h))
>> hugetlb_hstate_alloc_pages(h);
>> +
>> + /*
>> + * Set demote order for each hstate. Note that
>> + * h->demote_order is initially 0.
>> + * - We can not demote gigantic pages if runtime freeing
>> + * is not supported.
>> + */
>> + if (!hstate_is_gigantic(h) ||
>> + gigantic_page_runtime_supported()) {
>
> Based on the comment, I think that making the condition explicit looks
> better from my point of view.
>
> if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported())
> continue;
>

Agreed. In addition, this code will look better when more conditions
are added in subsequent patches.

--
Mike Kravetz

>> + for_each_hstate(h2) {
>> + if (h2 == h)
>> + continue;
>> + if (h2->order < h->order &&
>> + h2->order > h->demote_order)
>> + h->demote_order = h2->order;
>> + }
>> + }
>> }
>> VM_BUG_ON(minimum_order == UINT_MAX);
>> }
>> @@ -3235,9 +3252,29 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
>> return 0;
>> }
>>