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

From: Oscar Salvador
Date: Mon Oct 04 2021 - 09:02:46 EST


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 ?

> 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;

> + 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;
> }
>

--
Oscar Salvador
SUSE L3