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,URIBL_BLOCKED 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 52230C433DB for ; Wed, 13 Jan 2021 11:11:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8CE222310F for ; Wed, 13 Jan 2021 11:11:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CE222310F 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 DDD0F8D0038; Wed, 13 Jan 2021 06:11:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8AE68D002E; Wed, 13 Jan 2021 06:11:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C78C58D0038; Wed, 13 Jan 2021 06:11:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id B2A678D002E for ; Wed, 13 Jan 2021 06:11:47 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8468A3631 for ; Wed, 13 Jan 2021 11:11:47 +0000 (UTC) X-FDA: 77700486654.27.wool25_3c0a0372751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 68CAC3D663 for ; Wed, 13 Jan 2021 11:11:47 +0000 (UTC) X-HE-Tag: wool25_3c0a0372751d X-Filterd-Recvd-Size: 6585 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 11:11:46 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id p12so920277pju.5 for ; Wed, 13 Jan 2021 03:11:46 -0800 (PST) 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=2SLKDdrQFM+WKaMV48OG/N2sM0JT//xOlqtXb3zZwTM=; b=tTu7f6bnfxotrdB4JETUlesNGyB16DkTfyA/8UvHNfMq0QW9me+kof54gMELVaGeVI EbesI5FCIwQO1vCJUNw3KR2kGj6QALlS44wK/zibHCvF6+ELlBrZMe+1f0QB1W0fk1Ku BRD+3fMPFvd7jsFp7vwWvXQPlX1CUpXyWE10es/mBOC3pevgA54Nn0NpitnpxbnsE2cC OzWcCP+5qwwnBRnKGlmgTOkN6o2joxynqk1LfK0tBvFoN4fNTvhmKv+v++k68EkM+Gta CPkzEEPjRWJBlPGAt3rFnrROxpF/j8hzZqb0tO12mibE+HnDvBThhkXWS4AMaK+h5wGB qcdg== 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=2SLKDdrQFM+WKaMV48OG/N2sM0JT//xOlqtXb3zZwTM=; b=Gao+kZq7k7JXBZaQaU1cTPpOBzlEt6fFPiSSozxYkxSsoDu28I6zTDQ+So5oc7iCSI 7sq69h+97eyT4NG8E16IW66oQ5142Rsufpp12vuMii7OZZQpkTxiFHWRn0Dbn6wtYUK3 EVd1jamwQvA+fMAB+5Tgxec+EhD0eukv0r2g/pIAehUFl6SiCPEj2CIFy+w6rMYynwxo v9uifWVa6IkdkWJ8dv34qo0Zqe75w/63xqN0Z7GPOZ+dLhIKEmy6kAQknaDG2HJ6ffeC XjvkJohXKTUUQalFlt2CS3iLqrAHr/IDaaSYmTG5hO8gUyo/4q+gQWMEWELWzs5U4DN9 2MyQ== X-Gm-Message-State: AOAM532QsdHjhbTVS3GdRS/clyDYUIauja+G5Pzje+EEWatG61zghr39 oPC1Oojf/li6us/Atmvhmmwv8n5i2EERFZfKWWNc7w== X-Google-Smtp-Source: ABdhPJxEclREtaF8KMJhPc6n8HXvQMOJj+quJHpcDJGFXs+/Ww1SZjKGKbAzR42YPHfJhPnnuVgxOHBZgTZPbAO2bBk= X-Received: by 2002:a17:90a:ba88:: with SMTP id t8mr1792739pjr.229.1610536305779; Wed, 13 Jan 2021 03:11:45 -0800 (PST) MIME-Version: 1.0 References: <20210113052209.75531-1-songmuchun@bytedance.com> <20210113052209.75531-5-songmuchun@bytedance.com> <20210113093331.GV22493@dhcp22.suse.cz> <20210113103836.GW22493@dhcp22.suse.cz> In-Reply-To: <20210113103836.GW22493@dhcp22.suse.cz> From: Muchun Song Date: Wed, 13 Jan 2021 19:11:06 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v4 4/6] mm: hugetlb: retry dissolve page when hitting race To: Michal Hocko Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" 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 Wed, Jan 13, 2021 at 6:38 PM Michal Hocko wrote: > > On Wed 13-01-21 18:14:55, Muchun Song wrote: > > On Wed, Jan 13, 2021 at 5:33 PM Michal Hocko wrote: > > > > > > On Wed 13-01-21 13:22:07, Muchun Song wrote: > > > > 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; > > > > > > OK, so you have done the retry here. Please fold it into the previous > > > patch. Also do we need cpu_relax on top of cond_resched as well? > > > > Because the previous patch is a bugfix and should be backprt to the other > > stable tree, right? > > Yes, it is a bugfix but it arguably opens another issue so the follow up > patch should better be applied along with it. OK. I will fold this one into the previous one. Thanks. > > > I just want the fix patch to be small enough. > > So I do the retry in this patch. If you do not agree with this. I > > will fold this into the previous patch. > > > > Do you mean this? > > > > cpu_relax(); > > cond_resched(); > > cpu_relax(); > > No, I am questiong the use of cpu_relax. What is the point? If there is no task to be scheduled. Here is just a while loop. The cpu_relax is a good thing to insert into busy-wait loops, right? > > -- > Michal Hocko > SUSE Labs