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 7EA9BC433E0 for ; Wed, 13 Jan 2021 10:15:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D12FF206EC for ; Wed, 13 Jan 2021 10:15:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D12FF206EC 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 F1DFF8D0019; Wed, 13 Jan 2021 05:15:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECDEB6B016E; Wed, 13 Jan 2021 05:15:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE2C48D0019; Wed, 13 Jan 2021 05:15:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id C7F276B016D for ; Wed, 13 Jan 2021 05:15:36 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7F6F8181AEF30 for ; Wed, 13 Jan 2021 10:15:36 +0000 (UTC) X-FDA: 77700345072.25.cave31_54066892751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 4CB2B1804E3A1 for ; Wed, 13 Jan 2021 10:15:36 +0000 (UTC) X-HE-Tag: cave31_54066892751d X-Filterd-Recvd-Size: 5901 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 10:15:35 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id h10so929133pfo.9 for ; Wed, 13 Jan 2021 02:15:35 -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=rcaLsuqlhl7AUPdK1MZqrBVd9AgtDva3ByblrNRXVVQ=; b=QBthpibIbhXcNn0sING9h1ZwCyVuLKDCxT12fHrKn8pifxGsxaFYAvbHyPvl6qEdfz pFQzsPSd4EDq33qYmPxHQwnR4VMI6dzQQ62FjSmJpPogUXABQQN8Bjm4JtF534gmDh7k 7RpU4Ln6XAiRj12yBYmtxTXmBIHCGu8yzsMkRx7HKIpq29DQjB+E0Ez7fJnMjqvB6N7v QWRVmwjr+ueQbdvJtoFqlgFN1c57T6roP8LRbc1RURwe48P4JrsYJWAauB+fBtfs4CL2 boOFGKsbU2WT1a0q8+sWr1UH72TLZNF4wk1V7Jcp4x1CBYMTHpSleNUPqDlQiaYLZkhH fuwg== 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=rcaLsuqlhl7AUPdK1MZqrBVd9AgtDva3ByblrNRXVVQ=; b=Cw42Tv/xszGPYmcfn/0CkL9uynlehWf+NVrKvobeRQmiaua2dQp5AYbZl+aK1AM9nW Srvh+6TQ44EG8q2PbHs2M3xqi+kHCwCyMHvOs0MX9gvmoPlKnqAhRSZ19e+5kvL7Cy7c xIvGd6zKBRQXl0g+jsQREPxviXxKa+gms8fauyGoU8jUZKHS/Gpb0kCdstsQ9qR3NWLu Oeko6sGQYitbIIGLHFD4jT5ajlCbDEuLGDEeMQ5DeGToVyNnBPQkrWdbOiQm6HfZb5xn B8rV/KSub/fzHD8m29kIehGNk+tuSGhbEGBU1ME+Z9KNhBXw3rPfg6a3/Ii44MfY/EMR DWDA== X-Gm-Message-State: AOAM532n1f6SgsxG1qFhESRddkQoFNIcD8e0jDODiaLfs9rEYiEVB/sy vS6elonn9Dey1GVqDVisCrkZar6nk+o0U9HnaTLyoQ== X-Google-Smtp-Source: ABdhPJyiYaQx1lHd114SOzLARU4DDZgoo6iWc/G7lrJC+z7xCIHbNZzFRzLYmo/YYcyr5zLYNJ83/U9UJIdsG47fBSI= X-Received: by 2002:a63:50a:: with SMTP id 10mr1416399pgf.273.1610532934323; Wed, 13 Jan 2021 02:15:34 -0800 (PST) MIME-Version: 1.0 References: <20210113052209.75531-1-songmuchun@bytedance.com> <20210113052209.75531-5-songmuchun@bytedance.com> <20210113093331.GV22493@dhcp22.suse.cz> In-Reply-To: <20210113093331.GV22493@dhcp22.suse.cz> From: Muchun Song Date: Wed, 13 Jan 2021 18:14:55 +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 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? 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(); If yes, IMHO, I don't think it is necessary. > > > + } > > > > /* > > * Move PageHWPoison flag from head page to the raw error page, > > -- > > 2.11.0 > > -- > Michal Hocko > SUSE Labs