From patchwork Wed Jan 13 05:22:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12015801 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 ABA5AC433E6 for ; Wed, 13 Jan 2021 05:25:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0D96523120 for ; Wed, 13 Jan 2021 05:25:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D96523120 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 8C0C78D0011; Wed, 13 Jan 2021 00:25:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8988E8D0007; Wed, 13 Jan 2021 00:25:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 786208D0011; Wed, 13 Jan 2021 00:25:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 63D028D0007 for ; Wed, 13 Jan 2021 00:25:51 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2F169181AEF30 for ; Wed, 13 Jan 2021 05:25:51 +0000 (UTC) X-FDA: 77699614902.21.bears36_0b021792751b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 0FAF3180442C7 for ; Wed, 13 Jan 2021 05:25:51 +0000 (UTC) X-HE-Tag: bears36_0b021792751b X-Filterd-Recvd-Size: 4813 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 05:25:50 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id md11so419281pjb.0 for ; Tue, 12 Jan 2021 21:25:48 -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=df+OSfZ6Luc35Oz4+SS0Ts5oHiC9zu8mWZ+1lvg6xFY=; b=wBRMJy+2MZVtfgvXnwW63ZbQjCCWkgb2dOMUynxH9HAzryqJzMWO8hX3hUebpvrjPo 46M+sxORf5F6Z9VDNvKGgxBsXVzdJCpJYijbRpEPg9GwZjjo0hbNKzIqT10ABwAcz9jr ybrk4dJHUZr8fk+ZzwAbiMXkwOB97p4K4FIgDk6YJCnScgJMrRMl53HLrCUM2wIIiq88 YsEMOjimlLmRxhj+6UTzRrq8sdEbJThESelLVqg+a3pAp+1TB3PLfvuBP7Kyu2UsJcOv d5b8KYUgqK6GJgTBDmXCHG1edYjugzk/IP061E9C2RfgM/4GpT2x9V83wtXV20FY39QG uvSw== 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=df+OSfZ6Luc35Oz4+SS0Ts5oHiC9zu8mWZ+1lvg6xFY=; b=BsJ1Ouf8+xerw8vz+++LKPbgQ3YNb+Yqr9Q2SAjlookgT89Hvb8g+QmkpA+bSrVtHW 1WMu47BoNuv9U3g4huFoJ+VAC/Mdw2umVwzqUj5mjyAeR2MpgE50gdlzOmazCsZE7beO 2i6nHFsZSakwG2N1AHpovC+yevM+pCKjZpF/mCY7b+NrmlpEvsFoUcksR/cZVqorgg9B PMTl0GfImLcditX1h5RvxAMBs6hSA+UF04n1WIU/bvkdUm5SjppFBJ3wU6QVPEE5ZSuA 8ynUM3ySJrCYZDSYtMy3dk60w/hV8GFi3CQOkgKFdqRtFx2wHJZbI6RiApiNQAH0i+HM 5KuQ== X-Gm-Message-State: AOAM530vk1gcaAt79v5kYTOwp2ZprCg/7lpxsti/OOXapQmU915fL8rD 5Puw4ra/sVjftS6djA8e4yUABA== X-Google-Smtp-Source: ABdhPJyKl1cvK6NkpSmYZQknrW7MZ4B+txOHVft4CSpdorPAXL1OO4sVsWZKeOvhYqOuCHE1W/qd3g== X-Received: by 2002:a17:90a:4208:: with SMTP id o8mr386094pjg.224.1610515548247; Tue, 12 Jan 2021 21:25:48 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id x15sm893081pfa.80.2021.01.12.21.25.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 21:25:47 -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 v4 4/6] mm: hugetlb: retry dissolve page when hitting race Date: Wed, 13 Jan 2021 13:22:07 +0800 Message-Id: <20210113052209.75531-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210113052209.75531-1-songmuchun@bytedance.com> References: <20210113052209.75531-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: There is a race between dissolve_free_huge_page() and put_page(). 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. Signed-off-by: Muchun Song --- mm/hugetlb.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4a9011e12175..898e4ea43e13 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1772,6 +1772,7 @@ int dissolve_free_huge_page(struct page *page) { int rc = -EBUSY; +retry: /* Not to disrupt normal path by vainly holding hugetlb_lock */ if (!PageHuge(page)) return 0; @@ -1793,8 +1794,23 @@ 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))) - goto out; + if (unlikely(!PageHugeFreed(head))) { + spin_unlock(&hugetlb_lock); + + /* + * 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. + */ + while (PageHeadHuge(head) && !PageHugeFreed(head)) { + cond_resched(); + cpu_relax(); + } + goto retry; + } /* * Move PageHWPoison flag from head page to the raw error page,