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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 D2B03C433E0 for ; Wed, 13 Jan 2021 09:33:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 472F42339F for ; Wed, 13 Jan 2021 09:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 472F42339F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 478D86B0133; Wed, 13 Jan 2021 04:33:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42B5E6B0135; Wed, 13 Jan 2021 04:33:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F1C18D0019; Wed, 13 Jan 2021 04:33:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 172756B0133 for ; Wed, 13 Jan 2021 04:33:34 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CAE6C10F15 for ; Wed, 13 Jan 2021 09:33:33 +0000 (UTC) X-FDA: 77700239106.22.straw09_490188d2751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id A76C91803AA9B for ; Wed, 13 Jan 2021 09:33:33 +0000 (UTC) X-HE-Tag: straw09_490188d2751d X-Filterd-Recvd-Size: 3619 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 09:33:33 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610530412; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=voqVdGYzYdHfnFqrEWaLDjLhPhxcuxwsSJVMqjuuK2s=; b=q2JTLMTVtUUEiE86kntcI1HHn5aDwM3ujMCEnSylIRxFVQDvDCK3odhZBxTONNXUX4sxRL IVOrxA2De1a/KIcO0dzRElYU4hTb5brVzgT8oSTQrC0pmO0kzww1ySIFtUpMlMSqOeXJ03 QbiG7Monfh90YrRckli55/YSxGxHse8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 397C8AA6F; Wed, 13 Jan 2021 09:33:32 +0000 (UTC) Date: Wed, 13 Jan 2021 10:33:31 +0100 From: Michal Hocko To: Muchun Song Cc: mike.kravetz@oracle.com, akpm@linux-foundation.org, n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 4/6] mm: hugetlb: retry dissolve page when hitting race Message-ID: <20210113093331.GV22493@dhcp22.suse.cz> References: <20210113052209.75531-1-songmuchun@bytedance.com> <20210113052209.75531-5-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210113052209.75531-5-songmuchun@bytedance.com> 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 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? > + } > > /* > * Move PageHWPoison flag from head page to the raw error page, > -- > 2.11.0 -- Michal Hocko SUSE Labs