Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3520192rdg; Tue, 17 Oct 2023 18:58:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEB/1kKD/67fTTMdsnQlNhrEIGLKQAaR6zFfQQI0NH8Fatxtsh3E+eOj+hpU0T/U25PW3T1 X-Received: by 2002:a05:6358:a1e:b0:135:46d9:12f7 with SMTP id 30-20020a0563580a1e00b0013546d912f7mr3977641rwa.26.1697594337668; Tue, 17 Oct 2023 18:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697594337; cv=none; d=google.com; s=arc-20160816; b=yo0+f9UYvXEcaaEQx+/QHCYj0R8NcYyr0438K43hqQpIdwuNhdrvvuiQ8MdI4yMhQY Lu8cVofbfRrjSUeqD9DYw11qNXv6Vb6nFCwkfGU286WZbP5mB6RLHFcaSruoF4hIMKOp s0n3DayZHqiYRLzd3X/wf0l6PYYlodmkVlors9GOpF8ukG+YhgFVpys4jGK8KkJLTD10 pV8l7s1OBmAU4fQUQj+0zlaTXwPXoBK+Wpk2u+iBTGOSawF5FxMkT9r2yFH7rRezvxXY 47ZiYXCcRdo3CYBol9RPRUy6Il567rO+qG1IRaGYQBdPs4E3d4OwkdZLU9Tm+kpV7PMe eOLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=TtNdG5qwi8W/bQEJ73s/sZz1y//7quk4778GSvCx/FQ=; fh=oRrhLpM463tnW/p2FMup105MxIDWIx/UaM2p0pKS4q4=; b=ALQp7Tgc5O2/gcbKaYdqoRXxKZIAMVucu04PSz6nkV7Nies86OuVSouTDeG9IsYcIO 7g3SgHvAM+Mgo6UrM9mEOvDuAoxXlg+oV1YvM6WNaDgo+iHqRfYZNZmitDGIvhPojPq7 /0/N0c987DhTsPWo1AdK9+jdHYPitBNzTqg24hOw5ZGECOQNrD7fswGanZWMbmv0lDNZ 54/W+3XD0WI1KpmfH9tQ/9+cpvk97chcW+9P4kzLa2cjC6s1CqhWqJGMn/Pd5mnDTjYB LZv7gno7gb9hC7wt9eo8MGZ8KgZhR2flmY1BSiCSFXnu3cFN6HSvnkK80P38oWSF4Sit C8+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=G45y4SRi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g70-20020a636b49000000b005acffc12ae4si1021491pgc.409.2023.10.17.18.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 18:58:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=G45y4SRi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B251C8026F03; Tue, 17 Oct 2023 18:58:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229475AbjJRB6o (ORCPT + 99 others); Tue, 17 Oct 2023 21:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjJRB6n (ORCPT ); Tue, 17 Oct 2023 21:58:43 -0400 Received: from out-190.mta1.migadu.com (out-190.mta1.migadu.com [IPv6:2001:41d0:203:375::be]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22649C6 for ; Tue, 17 Oct 2023 18:58:41 -0700 (PDT) Date: Wed, 18 Oct 2023 10:58:24 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1697594317; h=from:from:reply-to:subject:subject: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=TtNdG5qwi8W/bQEJ73s/sZz1y//7quk4778GSvCx/FQ=; b=G45y4SRiY5MglF+fHzpy9Hizc1US199bCJce5SoSOLMcJZqTHrxY7fpp2dw5nv2ANBjyTy zaqbam+GWAiolwdvwntcuiLbFqDeosMefjbwE68fZ3pjKb/XNoRzshj2PlosslQMwgwS1f fjUk3KwU1B2GUy/czphYufIuiplUqxc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Naoya Horiguchi To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Joao Martins , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Barry Song , Michal Hocko , Matthew Wilcox , Xiongchun Duan , Andrew Morton Subject: Re: [PATCH v2 01/11] hugetlb: set hugetlb page flag before optimizing vmemmap Message-ID: <20231018015824.GA2942027@ik1-406-35019.vs.sakura.ne.jp> References: <20230905214412.89152-1-mike.kravetz@oracle.com> <20230905214412.89152-2-mike.kravetz@oracle.com> <20231013125856.GA636971@u2004> <20231017032140.GA3680@monkey> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231017032140.GA3680@monkey> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 18:58:55 -0700 (PDT) On Mon, Oct 16, 2023 at 08:21:40PM -0700, Mike Kravetz wrote: > On 10/13/23 21:58, Naoya Horiguchi wrote: > > On Tue, Sep 05, 2023 at 02:44:00PM -0700, Mike Kravetz wrote: > > > > > > Fixes: f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with each HugeTLB page") > > > Signed-off-by: Mike Kravetz > > > > I saw that VM_WARN_ON_ONCE() in hugetlb_vmemmap_restore is triggered when > > memory_failure() is called on a free hugetlb page with vmemmap optimization > > disabled (the warning is not triggered if vmemmap optimization is enabled). > > I think that we need check folio_test_hugetlb() before dissolve_free_huge_page() > > calls hugetlb_vmemmap_restore_folio(). > > > > Could you consider adding some diff like below? > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -2312,15 +2312,16 @@ int dissolve_free_huge_page(struct page *page) > > * Attempt to allocate vmemmmap here so that we can take > > * appropriate action on failure. > > */ > > - rc = hugetlb_vmemmap_restore_folio(h, folio); > > - if (!rc) { > > - update_and_free_hugetlb_folio(h, folio, false); > > - } else { > > - spin_lock_irq(&hugetlb_lock); > > - add_hugetlb_folio(h, folio, false); > > - h->max_huge_pages++; > > - spin_unlock_irq(&hugetlb_lock); > > + if (folio_test_hugetlb(folio)) { > > + rc = hugetlb_vmemmap_restore_folio(h, folio); > > + if (rc) { > > + spin_lock_irq(&hugetlb_lock); > > + add_hugetlb_folio(h, folio, false); > > + h->max_huge_pages++; > > + goto out; > > + } > > } > > + update_and_free_hugetlb_folio(h, folio, false); > > > > return rc; > > } > > > > Hi Naoya, > > I believe we need to set 'rc = 0' in the !folio_test_hugetlb(). I put > together the following patch based on mm-stable. Please take a look. Hi Mike, the patch looks good to me, and I confirmed that my test programs showed no new problem on latest mm-stable + this patch. Thank you very much. Naoya Horiguchi > > From f19fbfab324d7d17de4a1e814f95ee655950c58e Mon Sep 17 00:00:00 2001 > From: Mike Kravetz > Date: Mon, 16 Oct 2023 19:55:49 -0700 > Subject: [PATCH] hugetlb: check for hugetlb folio before vmemmap_restore > > In commit d8f5f7e445f0 ("hugetlb: set hugetlb page flag before > optimizing vmemmap") checks were added to print a warning if > hugetlb_vmemmap_restore was called on a non-hugetlb page. This > was mostly due to ordering issues in the hugetlb page set up and > tear down sequencees. One place missed was the routine > dissolve_free_huge_page. Naoya Horiguchi noted: "I saw that > VM_WARN_ON_ONCE() in hugetlb_vmemmap_restore is triggered when > memory_failure() is called on a free hugetlb page with vmemmap > optimization disabled (the warning is not triggered if vmemmap > optimization is enabled). I think that we need check > folio_test_hugetlb() before dissolve_free_huge_page() calls > hugetlb_vmemmap_restore_folio()." > > Perform the check as suggested by Naoya. > > Fixes: d8f5f7e445f0 ("hugetlb: set hugetlb page flag before optimizing vmemmap") > Suggested-by: Naoya Horiguchi > Signed-off-by: Mike Kravetz > --- > mm/hugetlb.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 36b40bc9ac25..13736cbb2c19 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2290,17 +2290,23 @@ int dissolve_free_huge_page(struct page *page) > * need to adjust max_huge_pages if the page is not freed. > * Attempt to allocate vmemmmap here so that we can take > * appropriate action on failure. > + * > + * The folio_test_hugetlb check here is because > + * remove_hugetlb_folio will clear hugetlb folio flag for > + * non-vmemmap optimized hugetlb folios. > */ > - rc = hugetlb_vmemmap_restore(h, &folio->page); > - if (!rc) { > - update_and_free_hugetlb_folio(h, folio, false); > - } else { > - spin_lock_irq(&hugetlb_lock); > - add_hugetlb_folio(h, folio, false); > - h->max_huge_pages++; > - spin_unlock_irq(&hugetlb_lock); > - } > + if (folio_test_hugetlb(folio)) { > + rc = hugetlb_vmemmap_restore(h, &folio->page); > + if (rc) { > + spin_lock_irq(&hugetlb_lock); > + add_hugetlb_folio(h, folio, false); > + h->max_huge_pages++; > + goto out; > + } > + } else > + rc = 0; > > + update_and_free_hugetlb_folio(h, folio, false); > return rc; > } > out: > -- > 2.41.0 >