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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 C2FBBC433E6 for ; Thu, 14 Jan 2021 15:38:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F83123B40 for ; Thu, 14 Jan 2021 15:38:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F83123B40 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 D88D38D00EC; Thu, 14 Jan 2021 10:38:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D12088D008E; Thu, 14 Jan 2021 10:38:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9F88D00EC; Thu, 14 Jan 2021 10:38:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id A3E018D008E for ; Thu, 14 Jan 2021 10:38:25 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5A307181AEF1E for ; Thu, 14 Jan 2021 15:38:25 +0000 (UTC) X-FDA: 77704787370.27.judge85_551314127527 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 37DBB3D668 for ; Thu, 14 Jan 2021 15:38:25 +0000 (UTC) X-HE-Tag: judge85_551314127527 X-Filterd-Recvd-Size: 4095 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 14 Jan 2021 15:38:24 +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=1610638703; 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=QeRFjkYJBJIGL2sjsf3y8jXeoXRfYr95O8LxnCXhhDM=; b=oca6QqkWqnSPyzG5NiYYq7/pyff0Ez5l9E2Xzwpbg1mCuf05mT+VEGqYq1KPlmo7lUqXus rFEJGEZRfZOBZ22V1aAotvb6OjYH0CiAjNv7PzmTooUIYz76tEK33RDkx5OOvCcxKQhmSQ PVg35zjcbUUEb6AN4QKpwr/gjvkre3c= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A01EFB94C; Thu, 14 Jan 2021 15:38:22 +0000 (UTC) Date: Thu, 14 Jan 2021 16:38:14 +0100 From: Michal Hocko To: Muchun Song Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , Linux Memory Management List , LKML , linux- stable Subject: Re: [External] Re: [PATCH v5 3/5] mm: hugetlb: fix a race between freeing and dissolving the page Message-ID: <20210114153814.GB27777@dhcp22.suse.cz> References: <20210114103515.12955-1-songmuchun@bytedance.com> <20210114103515.12955-4-songmuchun@bytedance.com> <20210114132036.GA27777@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu 14-01-21 21:47:36, Muchun Song wrote: > On Thu, Jan 14, 2021 at 9:20 PM Michal Hocko wrote: [...] > > > @@ -1770,6 +1789,28 @@ int dissolve_free_huge_page(struct page *page) > > > int nid = page_to_nid(head); > > > if (h->free_huge_pages - h->resv_huge_pages == 0) > > > goto out; > > > + > > > + /* > > > + * We should make sure that the page is already on the free list > > > + * when it is dissolved. > > > + */ > > > + 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(); > > > > Sorry, I should have raised that when replying to the previous version > > already but we have focused more on other things. Is there any special > > reason that you didn't simply > > if (!PageHugeFreed(head)) { > > spin_unlock(&hugetlb_lock); > > cond_resched(); > > goto retry; > > } > > > > This would be less code and a very slight advantage would be that the > > waiter might get blocked on the spin lock while the concurrent freeing > > is happening. But maybe you wanted to avoid exactly this contention? > > Please put your thinking into the changelog. > > I want to avoid the lock contention. I will add this reason > to the changelog. Thanks. Please also explain why it matters and whether an unintended contention is a real problem. -- Michal Hocko SUSE Labs