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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 F25B0C433E0 for ; Sun, 10 Jan 2021 12:41:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F6E022ADF for ; Sun, 10 Jan 2021 12:41:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F6E022ADF 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 378AA8D001D; Sun, 10 Jan 2021 07:41:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34E1E8D0019; Sun, 10 Jan 2021 07:41:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23DA08D001D; Sun, 10 Jan 2021 07:41:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 0E28B8D0019 for ; Sun, 10 Jan 2021 07:41:41 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C8BD7180AD806 for ; Sun, 10 Jan 2021 12:41:40 +0000 (UTC) X-FDA: 77689826760.23.legs54_430ccd327504 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id AD3FB37606 for ; Sun, 10 Jan 2021 12:41:40 +0000 (UTC) X-HE-Tag: legs54_430ccd327504 X-Filterd-Recvd-Size: 6031 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Sun, 10 Jan 2021 12:41:40 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id w2so1424079pfc.13 for ; Sun, 10 Jan 2021 04:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HhlvFEw8jdfKSbqCegVc8DBdoL7Xly+0YXsiaFK68GM=; b=nKa0zwCZ2svXtZUVz4u93tOukfQ1rtXnodZzLZhzNw1D0tYe9JtTZFDbpoY1bK9Ae4 p0r4U3LV61u3OUIaXpKBU6s8bKiOAbz3MGr/sYXcISksN4RvmQJYhO96VW2igbvtWCZO tuweADoElAyPvb5rZaYt+9AC0vLhUxyFP3/0SPCeUHpsigUZLZO6gDn0Tczo8q3OUNax JACLi7hxFufRkJs4tq2LpErAFIoyJuRMX4fhVybpmp1T5siBX/mHgdkb87tEpWSyPtFV 1HFdOc6YrluZJzk2TcViU0uhqtJOv1KOVP4gFNFblSzqJoyQua1kNOFf+reaUu8xZLwS DUsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HhlvFEw8jdfKSbqCegVc8DBdoL7Xly+0YXsiaFK68GM=; b=qlO6QsMx4GBw1E1dYzEjEfCyV4sKn0V7w5u9+HxRDqbdHokwYemVQt0+IfNlk9Pce5 YUTE0xm+vNOCcZypfJzgxajuHWlYDZZUeXBeUxNiJWgZE0MfCkvTdR4yeD9LbuSp8aeY asfcJGa89rO9JBxeiLITGAE6cZsX+uESeHK0DsaiclEpSVPzr3shlUSHRKLGh+G0TvqX L/trT7DpP8DiPOe391d/I5ep3/H28PtVy4r2wbb7nvEZUsl3YPx+UmiZHE0GIGZsb5D6 +61G1POSAJkWKaXUD6L6pTrzEsF6rO+6BaoH3Egh2GUPUtUgm8iLNFDAKzPuNRlZpu+3 pbmw== X-Gm-Message-State: AOAM530VQGJvW+iEsdc5UDh79fzh+voE0xJRdg0giFUbsdtVsX0zTl00 G6/rY56iSmoRACRpruiD1Oax/Q== X-Google-Smtp-Source: ABdhPJz16FQS6hGSFtI9gh/TUdc46pPEDeMctnvCGgRCVHKmu4bKwdmuvDxjYQLBqeHMn1ZWiX3K6Q== X-Received: by 2002:aa7:8ad0:0:b029:1a9:3a46:78d1 with SMTP id b16-20020aa78ad00000b02901a93a4678d1mr12335934pfd.77.1610282499413; Sun, 10 Jan 2021 04:41:39 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id p9sm16176960pfq.136.2021.01.10.04.41.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jan 2021 04:41:38 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v3 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page Date: Sun, 10 Jan 2021 20:40:15 +0800 Message-Id: <20210110124017.86750-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210110124017.86750-1-songmuchun@bytedance.com> References: <20210110124017.86750-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: There is a race between dissolve_free_huge_page() and put_page(), and the race window is quite small. Theoretically, we should return -EBUSY when we encounter this race. In fact, we have a chance to successfully dissolve the page if we do a retry. Because the race window is quite small. If we seize this opportunity, it is an optimization for increasing the success rate of dissolving page. If we free a HugeTLB page from a non-task context, it is deferred through a workqueue. In this case, we need to flush the work. The dissolve_free_huge_page() can be called from memory hotplug, the caller aims to free the HugeTLB page to the buddy allocator so that the caller can unplug the page successfully. Signed-off-by: Muchun Song --- mm/hugetlb.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4a9011e12175..a176ceed55f1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1763,10 +1763,11 @@ static int free_pool_huge_page(struct hstate *h, = nodemask_t *nodes_allowed, * nothing for in-use hugepages and non-hugepages. * This function returns values like below: * - * -EBUSY: failed to dissolved free hugepages or the hugepage is in-use - * (allocated or reserved.) - * 0: successfully dissolved free hugepages or the page is not a - * hugepage (considered as already dissolved) + * -EAGAIN: race with __free_huge_page() and can do a retry + * -EBUSY: failed to dissolved free hugepages or the hugepage is in-us= e + * (allocated or reserved.) + * 0: successfully dissolved free hugepages or the page is not a + * hugepage (considered as already dissolved) */ int dissolve_free_huge_page(struct page *page) { @@ -1793,8 +1794,10 @@ int dissolve_free_huge_page(struct page *page) * We should make sure that the page is already on the free list * when it is dissolved. */ - if (unlikely(!PageHugeFreed(head))) + if (unlikely(!PageHugeFreed(head))) { + rc =3D -EAGAIN; goto out; + } =20 /* * Move PageHWPoison flag from head page to the raw error page, @@ -1813,6 +1816,14 @@ int dissolve_free_huge_page(struct page *page) } out: spin_unlock(&hugetlb_lock); + + /* + * If the freeing of the HugeTLB page is put on a work queue, we should + * flush the work before retrying. + */ + if (unlikely(rc =3D=3D -EAGAIN)) + flush_work(&free_hpage_work); + return rc; } =20 @@ -1835,7 +1846,12 @@ int dissolve_free_huge_pages(unsigned long start_p= fn, unsigned long end_pfn) =20 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D 1 << minimum_order) { page =3D pfn_to_page(pfn); +retry: rc =3D dissolve_free_huge_page(page); + if (rc =3D=3D -EAGAIN) { + cpu_relax(); + goto retry; + } if (rc) break; } --=20 2.11.0