Re: [PATCH v7 6/7] mm: Make alloc_contig_range handle in-use hugetlb pages
From: Mike Kravetz
Date: Tue Apr 13 2021 - 18:49:08 EST
On 4/13/21 3:47 AM, Oscar Salvador wrote:
> alloc_contig_range() will fail if it finds a HugeTLB page within the range,
> without a chance to handle them. Since HugeTLB pages can be migrated as any
> LRU or Movable page, it does not make sense to bail out without trying.
> Enable the interface to recognize in-use HugeTLB pages so we can migrate
> them, and have much better chances to succeed the call.
>
> Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
> Reviewed-by: Mike Kravetz <mike.kravetz@xxxxxxxxxx>
> Acked-by: Michal Hocko <mhocko@xxxxxxxx>
One small issue/question/request below.
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 4a664d6e82c1..24a453ff47f2 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2270,10 +2270,12 @@ static void restore_reserve_on_error(struct hstate *h,
> * alloc_and_dissolve_huge_page - Allocate a new page and dissolve the old one
> * @h: struct hstate old page belongs to
> * @old_page: Old page to dissolve
> + * @list: List to isolate the page in case we need to
> * Returns 0 on success, otherwise negated error.
> */
>
> -static int alloc_and_dissolve_huge_page(struct hstate *h, struct page *old_page)
> +static int alloc_and_dissolve_huge_page(struct hstate *h, struct page *old_page,
> + struct list_head *list)
> {
> gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE;
> int nid = page_to_nid(old_page);
> @@ -2300,9 +2302,13 @@ static int alloc_and_dissolve_huge_page(struct hstate *h, struct page *old_page)
> goto free_new;
> } else if (page_count(old_page)) {
> /*
> - * Someone has grabbed the page, fail for now.
> + * Someone has grabbed the page, try to isolate it here.
> + * Fail with -EBUSY if not possible.
> */
> - ret = -EBUSY;
> + spin_unlock_irq(&hugetlb_lock);
> + if (!isolate_huge_page(old_page, list))
> + ret = -EBUSY;
> + spin_lock_irq(&hugetlb_lock);
> goto free_new;
The label free_new is:
free_new:
spin_unlock_irq(&hugetlb_lock);
__free_pages(new_page, huge_page_order(h));
return ret;
So, we are locking and immediately unlocking without any code in
between. Usually, I don't like like multiple labels before return.
However, perhaps we should add another to avoid this unnecessary
cycle. On the other hand, this is an uncommon race condition so the
simple code may be acceptable.
--
Mike Kravetz