From patchwork Wed Jan 6 08:47:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12001137 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,URIBL_BLOCKED,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 BF59CC433E0 for ; Wed, 6 Jan 2021 08:49:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 46DEC23107 for ; Wed, 6 Jan 2021 08:49:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46DEC23107 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 C5E618D00F8; Wed, 6 Jan 2021 03:49:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F4B8D0090; Wed, 6 Jan 2021 03:49:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99ACE8D00F8; Wed, 6 Jan 2021 03:49:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 759608D0090 for ; Wed, 6 Jan 2021 03:49:56 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3C172181AEF15 for ; Wed, 6 Jan 2021 08:49:56 +0000 (UTC) X-FDA: 77674727592.22.sea82_0801f9f274e0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 0E35F18038E67 for ; Wed, 6 Jan 2021 08:49:56 +0000 (UTC) X-HE-Tag: sea82_0801f9f274e0 X-Filterd-Recvd-Size: 5374 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 08:49:55 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id w1so2274626pjc.0 for ; Wed, 06 Jan 2021 00:49:55 -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=90s6LK3gLF/6oFq+lOVMbrh8BJ60hxrqeIvsRF2lESM=; b=x3RU16oGuaT9sj2vIkIgRGzTxCPsAJdSnMd8sWAyflNmD0NnMx1rKjuocHYi397T9D RF+7WdL0V2t096pAAfJkwWwOl36sla9UeFGrx5nfzIaIPZV/J9pnj0/4icH7FiUKBqgN ldv+68PZgSRVHgvJ+pxM9ZgSUVLak8lEKUfZ0bIHj9lQH0McLpydQItaiBCUb2fo6lWE owYdYy9m0KdlGsCroggp8cUG7c6GIkamaMe/S80o2Jn/D4raYVvsEqvHxHBEJzHfR6rh nBuZhve0ItidW5g8AruxveGDuIczgSLUQzP5qi9doNPuQ51oNJ1+hp8/rLUA6Ce0QIar 5u7Q== 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=90s6LK3gLF/6oFq+lOVMbrh8BJ60hxrqeIvsRF2lESM=; b=MFrRVJquQG0yW02HqyLmNIuikfwrZUTUJIMpd8+EiRHx/ZEJleU6PF7m3JegM5frC7 nxdyi/SdetXEQqR5gZWvUHDSUHN91/cfADRxGV0imLb9NY930vW9AD1ED1wjg5GHdf4K vHpI/0i5IIKiSFBjdYRuw9Y6GZXnIcoWM8IPdSnJduzLUDFLp/pDJpr2mjtVgraVi0+n N2KUuTs6FMmDBEujBAAmkv3u87zyVdpPsFHFTguqOBGvRgyGZvTZMjWcYu6l9PtcE9j7 YbeadMoJjYa86NSRsFsssASWP/Pm/VWlHGd7LSc39807MRx7mwo3v+KvBfby8UO0yn9m 8Ukw== X-Gm-Message-State: AOAM532iizU4INXsFEcpm+rrOiCCNzEjtvvzsadIw4V7xi2KZgX4FcdB pmZSZIBMo6Q7OCJK1AVl5TO2IA== X-Google-Smtp-Source: ABdhPJwzdYvHQSuz/lHuo7gp/98j1oFQJ+7wjSIWQAntgC/87EdZgm6Fv43aPtl5McyEwfidSM/5KQ== X-Received: by 2002:a17:90b:4a03:: with SMTP id kk3mr3237244pjb.97.1609922994744; Wed, 06 Jan 2021 00:49:54 -0800 (PST) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id h8sm1851806pjc.2.2021.01.06.00.49.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2021 00:49:54 -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 v2 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page Date: Wed, 6 Jan 2021 16:47:37 +0800 Message-Id: <20210106084739.63318-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210106084739.63318-1-songmuchun@bytedance.com> References: <20210106084739.63318-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: When dissolve_free_huge_page() races with __free_huge_page(), we can do a retry. Because the race window is small. 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 8ff138c17129..bf02e81e3953 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1775,10 +1775,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-use + * (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) { @@ -1805,8 +1806,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 = -EAGAIN; goto out; + } /* * Move PageHWPoison flag from head page to the raw error page, @@ -1825,6 +1828,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 == -EAGAIN)) + flush_work(&free_hpage_work); + return rc; } @@ -1847,7 +1858,12 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { page = pfn_to_page(pfn); +retry: rc = dissolve_free_huge_page(page); + if (rc == -EAGAIN) { + cpu_relax(); + goto retry; + } if (rc) break; }