From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEA25C433DB for ; Sat, 27 Mar 2021 06:54:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 375C9619F8 for ; Sat, 27 Mar 2021 06:54:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 375C9619F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BB2B26B006C; Sat, 27 Mar 2021 02:54:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B61AE6B006E; Sat, 27 Mar 2021 02:54:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B40B6B0070; Sat, 27 Mar 2021 02:54:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 835386B006C for ; Sat, 27 Mar 2021 02:54:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 34F60B7BA for ; Sat, 27 Mar 2021 06:54:52 +0000 (UTC) X-FDA: 77964741624.08.F753757 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf06.hostedemail.com (Postfix) with ESMTP id 5E2D5C0001F7 for ; Sat, 27 Mar 2021 06:54:50 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id ha17so3606519pjb.2 for ; Fri, 26 Mar 2021 23:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iHhxYzKxSZK7e1pTvFSaSY+himIOm/SDf+mnW3D31k8=; b=YRNmiHIA6YRSp9KCax5lTcZH1dWYiQMLqlJyd+TIWrNH8b4w8IONyj7C+k2WvL7pX2 l5+D6T52yMOW3fSSmfw/nXiNhluCxgNvma9KTvvTDIvBQ0X+iLwVhhqgi0a3rJziHjr6 00PlZbv4u6nUh0LZiGALlT2pzrXwsdmc6ciE/bRHsNpPaFRx80FXjAQQY4OZHvSJdp5P uR5Lha6yRNskjfv1sS4c5dAAYYVgC7zo3yK5+m5yiR9UiEQAwnuPtofdSHxNpnhggbv5 U7XrY9EcCkQ+GTldIOksYHqctaDAAiGf7mfsph/tWay9r6g1WmM6ZJBwKU3Z8ZZKyXw2 0ElA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iHhxYzKxSZK7e1pTvFSaSY+himIOm/SDf+mnW3D31k8=; b=Clc3u6RM3ZVpHzQ51ptn5IPK+woJyN5qJvLC6VyrOpoQDRPp9a01Jth0l4hGKEGyBV EwJYQ2+f1aKNVGx9SjT3Zi+wVUW41C9W6KOivlYj13bHhJWUnWanzRmUvdxhJSlJSTkb JQ5pKIQcqAR6ZxZe/dA36pTdfa4fibhvGP/+DPhVuuAMtC9Va4hv3f4L+YWzM71gLkLa epMzP1ToH+/dYp4PIJzaXmNxID83dYrwDOjPZa4DR9yPNLqnV5Y+/HuZN5VTH+zWC8ei 4BBjV3MYjJ98KVruR3t+184iAgkR/9rMfNZwKJW/kQjurbxc7wJM+x2+OMDyALIt9cRw iAIg== X-Gm-Message-State: AOAM533UM6w9u6uHIkJJIaO3FDCGo3LcGPSpjz1IfzDuBMyvAt0whslI dZSpvN01E7TqiYfgYPO3FKTVbkeAgJR3H4JgRSDD3Q== X-Google-Smtp-Source: ABdhPJxRD75z5ix5RMtTYqxS/AMhK2yQpgljLHut/GHQ6lyB7w5a0hQeKSj0687N2pji1r4DdfX+XbNVJI3vvwHCp6E= X-Received: by 2002:a17:902:d4cb:b029:e5:f608:6d5e with SMTP id o11-20020a170902d4cbb02900e5f6086d5emr18827042plg.20.1616828089060; Fri, 26 Mar 2021 23:54:49 -0700 (PDT) MIME-Version: 1.0 References: <20210325002835.216118-1-mike.kravetz@oracle.com> <20210325002835.216118-6-mike.kravetz@oracle.com> In-Reply-To: <20210325002835.216118-6-mike.kravetz@oracle.com> From: Muchun Song Date: Sat, 27 Mar 2021 14:54:12 +0800 Message-ID: Subject: Re: [External] [PATCH 5/8] hugetlb: call update_and_free_page without hugetlb_lock To: Mike Kravetz Cc: Linux Memory Management List , LKML , Roman Gushchin , Michal Hocko , Shakeel Butt , Oscar Salvador , David Hildenbrand , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: nhuzxncsqbs6owqkrpwqsuazjez7d8t8 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5E2D5C0001F7 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=mail-pj1-f45.google.com; client-ip=209.85.216.45 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616828090-758927 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Mar 25, 2021 at 8:29 AM Mike Kravetz wrote: > > With the introduction of remove_hugetlb_page(), there is no need for > update_and_free_page to hold the hugetlb lock. Change all callers to > drop the lock before calling. > > With additional code modifications, this will allow loops which decrease > the huge page pool to drop the hugetlb_lock with each page to reduce > long hold times. > > The ugly unlock/lock cycle in free_pool_huge_page will be removed in > a subsequent patch which restructures free_pool_huge_page. > > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Some nits below. > --- > mm/hugetlb.c | 34 +++++++++++++++++++++++++++++----- > 1 file changed, 29 insertions(+), 5 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 3938ec086b5c..fae7f034d1eb 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1450,16 +1450,18 @@ static void __free_huge_page(struct page *page) > > if (HPageTemporary(page)) { > remove_hugetlb_page(h, page, false); > + spin_unlock(&hugetlb_lock); > update_and_free_page(h, page); > } else if (h->surplus_huge_pages_node[nid]) { > /* remove the page from active list */ > remove_hugetlb_page(h, page, true); > + spin_unlock(&hugetlb_lock); > update_and_free_page(h, page); > } else { > arch_clear_hugepage_flags(page); > enqueue_huge_page(h, page); > + spin_unlock(&hugetlb_lock); > } > - spin_unlock(&hugetlb_lock); > } > > /* > @@ -1740,7 +1742,13 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, > list_entry(h->hugepage_freelists[node].next, > struct page, lru); > remove_hugetlb_page(h, page, acct_surplus); > + /* > + * unlock/lock around update_and_free_page is temporary > + * and will be removed with subsequent patch. > + */ > + spin_unlock(&hugetlb_lock); > update_and_free_page(h, page); > + spin_lock(&hugetlb_lock); > ret = 1; > break; > } > @@ -1809,8 +1817,9 @@ int dissolve_free_huge_page(struct page *page) > } > remove_hugetlb_page(h, page, false); > h->max_huge_pages--; > + spin_unlock(&hugetlb_lock); > update_and_free_page(h, head); > - rc = 0; > + return 0; > } > out: > spin_unlock(&hugetlb_lock); > @@ -2563,22 +2572,37 @@ static void try_to_free_low(struct hstate *h, unsigned long count, > nodemask_t *nodes_allowed) > { > int i; > + struct list_head page_list; I prefer to use LIST_HEAD(page_list) directly. > + struct page *page, *next; > > if (hstate_is_gigantic(h)) > return; > > + /* > + * Collect pages to be freed on a list, and free after dropping lock > + */ > + INIT_LIST_HEAD(&page_list); > for_each_node_mask(i, *nodes_allowed) { > - struct page *page, *next; > struct list_head *freel = &h->hugepage_freelists[i]; > list_for_each_entry_safe(page, next, freel, lru) { > if (count >= h->nr_huge_pages) > - return; > + goto out; > if (PageHighMem(page)) > continue; > remove_hugetlb_page(h, page, false); > - update_and_free_page(h, page); > + INIT_LIST_HEAD(&page->lru); As Michal pointed out that this is superfluous. > + list_add(&page->lru, &page_list); > } > } > + > +out: > + spin_unlock(&hugetlb_lock); > + list_for_each_entry_safe(page, next, &page_list, lru) { > + list_del(&page->lru); It looks like list_del() is also superfluous. Should we remove it? Thanks. > + update_and_free_page(h, page); > + cond_resched(); > + } > + spin_lock(&hugetlb_lock); > } > #else > static inline void try_to_free_low(struct hstate *h, unsigned long count, > -- > 2.30.2 >