Re: [PATCH] mm: hugetlb: fix non-atomic enqueue of huge page

From: Andrew Morton
Date: Tue Dec 27 2011 - 18:44:03 EST


On Fri, 23 Dec 2011 21:35:25 +0800
Hillf Danton <dhillf@xxxxxxxxx> wrote:

> From: Hillf Danton <dhillf@xxxxxxxxx>
> Subject: [PATCH] mm: hugetlb: fix non-atomic enqueue of huge page
>
> If huge page is enqueued under the protection of hugetlb_lock, then
> the operation is atomic and safe.
>
> Cc: Michal Hocko <mhocko@xxxxxxx>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
> ---
>
> --- a/mm/hugetlb.c Tue Dec 20 21:26:30 2011
> +++ b/mm/hugetlb.c Fri Dec 23 21:16:28 2011
> @@ -901,7 +901,6 @@ retry:
> h->resv_huge_pages += delta;
> ret = 0;
>
> - spin_unlock(&hugetlb_lock);
> /* Free the needed pages to the hugetlb pool */
> list_for_each_entry_safe(page, tmp, &surplus_list, lru) {
> if ((--needed) < 0)
> @@ -915,6 +914,7 @@ retry:
> VM_BUG_ON(page_count(page));
> enqueue_huge_page(h, page);
> }
> + spin_unlock(&hugetlb_lock);
>
> /* Free unnecessary surplus pages to the buddy allocator */

btw,

/* Free the needed pages to the hugetlb pool */
list_for_each_entry_safe(page, tmp, &surplus_list, lru) {
if ((--needed) < 0)
break;
list_del(&page->lru);
/*
* This page is now managed by the hugetlb allocator and has
* no users -- drop the buddy allocator's reference.
*/
put_page_testzero(page);
VM_BUG_ON(page_count(page));
enqueue_huge_page(h, page);
}
spin_unlock(&hugetlb_lock);


That VM_BUG_ON() largely duplicates the one in put_page_testzero().

(Putting a VM_BUG_ON() in put_page_testzero() was pretty expensive,
too. I wonder how many people are enabling VM_BUG_ON()? We should be
sparing in using these things)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/