Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5251470rwl; Wed, 28 Dec 2022 15:45:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXvWkfm9nXcHfyyUdVHRBWhM5khKrBmE4GCQOLvuUwA41FXb4u1YeOQj82ZAh1xnIVD8/3yt X-Received: by 2002:a05:6402:d4e:b0:46f:9fa5:ec14 with SMTP id ec14-20020a0564020d4e00b0046f9fa5ec14mr20160428edb.35.1672271121641; Wed, 28 Dec 2022 15:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672271121; cv=none; d=google.com; s=arc-20160816; b=WRKMR93JUl3T8qy2l9t4jyMZNnLqeDOUH106rjJvQIkWJv8e3Oj13MBEg3cmINIV9B fv+gEZtm/d4ryBYzYT7emRNj2Il7Ouam5rd7fXLOdAGpAVrx3cP6KiFUTc+uRX4C/GS5 nQgZljXBB0T1w2hgdR2CKTcpuSbvNDhLLc7CKXLLITncBWlKBWW+2AxlYz/ip7OIbjSI 0K2/66Vn1TYFQPJI8KfR6mhYMvPb+1IVeZ/fvrhP/bj5qHDjNnEr5zQCJQZ5Xs4GVKsW /uiZwHN3eXVTPhQgiWM5IqnfUROYBT4s25syQmj4wSaDtpxt5idzdsfr6qezDyQTdEDi OXLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=raUhdUuM59ezc3dod3/lMT8e1Tv5xKqAnrr3SIxD6Ic=; b=EEGOc/r3DDOVdPr/Gs8rUX0pkERDH5w1q9hVmiARdC8HqxLbYSb8s7e+Ctt3oeonDN UVaaZE6xReupXv8jDWDuVFHaZcv6f/VTiSYADIMWSeCHyTKrn+WPPZvtdMh4qcKl0rEB aFw6h3X+MdntneMT4R9SvH9n0OAl+wGYb6xBcNaQ1GjrHnnQYJkCBs7/vSxbvYdP7HKj afZqmc8iJliAFzjVStDTM3qeTHKW0BfUSsPV1XQQiu/0FG1mDgRq8mWOW442lKLTS0j9 92bSbPf0SQyHYFaddFpJmSZ16V4bKSUD5nEzfkcg5jn6EAd3smGcbr8Uk7nlK0jvUE1Q of7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Eq9n3BwV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020a056402521300b004855f09023csi8444951edd.231.2022.12.28.15.45.06; Wed, 28 Dec 2022 15:45:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Eq9n3BwV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiL1XRl (ORCPT + 62 others); Wed, 28 Dec 2022 18:17:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbiL1XRj (ORCPT ); Wed, 28 Dec 2022 18:17:39 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C70F913D77 for ; Wed, 28 Dec 2022 15:17:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E9DA961645 for ; Wed, 28 Dec 2022 23:17:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE2FFC433EF; Wed, 28 Dec 2022 23:17:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1672269457; bh=w3Rr9ivFjnV3esspD85qFy2NhTPDUghMYW5Ck9kdk10=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Eq9n3BwVPz9gSgeeWeqlP+VVTCilTbLEiOWa7G9/tNTYlilXjazrIGwcV5D0NwaWF KVLQcC4Eq5BNimUIMLMOi9rdEPTAUMvytFEBUaJR+pZOLA9IiLukXjRcFDb0nyqBFD 19oTrX8kCxgCZciOFh3YUtD70hZF0q8v6Wp4MMH0= Date: Wed, 28 Dec 2022 15:17:35 -0800 From: Andrew Morton To: Huang Ying Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , Yang Shi , Baolin Wang , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin Subject: Re: [PATCH 2/8] migrate_pages: separate hugetlb folios migration Message-Id: <20221228151735.e855bde30c1782bb45b97930@linux-foundation.org> In-Reply-To: <20221227002859.27740-3-ying.huang@intel.com> References: <20221227002859.27740-1-ying.huang@intel.com> <20221227002859.27740-3-ying.huang@intel.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 27 Dec 2022 08:28:53 +0800 Huang Ying wrote: > This is a preparation patch to batch the folio unmapping and moving > for the non-hugetlb folios. Based on that we can batch the TLB > shootdown during the folio migration and make it possible to use some > hardware accelerator for the folio copying. > > In this patch the hugetlb folios and non-hugetlb folios migration is > separated in migrate_pages() to make it easy to change the non-hugetlb > folios migration implementation. > > ... > > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1404,6 +1404,87 @@ struct migrate_pages_stats { > int nr_thp_split; > }; > > +static int migrate_hugetlbs(struct list_head *from, new_page_t get_new_page, > + free_page_t put_new_page, unsigned long private, > + enum migrate_mode mode, int reason, > + struct migrate_pages_stats *stats, > + struct list_head *ret_folios) > +{ > + int retry = 1; > + int nr_failed = 0; > + int nr_retry_pages = 0; > + int pass = 0; > + struct folio *folio, *folio2; > + int rc = 0, nr_pages; > + > + for (pass = 0; pass < 10 && retry; pass++) { Why 10? > + retry = 0; > + nr_retry_pages = 0; > + > + list_for_each_entry_safe(folio, folio2, from, lru) { > + if (!folio_test_hugetlb(folio)) > + continue; > + > + nr_pages = folio_nr_pages(folio); > + > + cond_resched(); > + > + rc = unmap_and_move_huge_page(get_new_page, > + put_new_page, private, > + &folio->page, pass > 2, mode, > + reason, ret_folios); > + /* > + * The rules are: > + * Success: hugetlb folio will be put back > + * -EAGAIN: stay on the from list > + * -ENOMEM: stay on the from list > + * -ENOSYS: stay on the from list > + * Other errno: put on ret_folios list > + */ > + switch(rc) { > + case -ENOSYS: > + /* Hugetlb migration is unsupported */ > + nr_failed++; > + stats->nr_failed_pages += nr_pages; > + list_move_tail(&folio->lru, ret_folios); > + break; > + case -ENOMEM: > + /* > + * When memory is low, don't bother to try to migrate > + * other folios, just exit. > + */ > + nr_failed++; > + stats->nr_failed_pages += nr_pages; > + goto out; > + case -EAGAIN: > + retry++; > + nr_retry_pages += nr_pages; > + break; > + case MIGRATEPAGE_SUCCESS: > + stats->nr_succeeded += nr_pages; > + break; > + default: > + /* > + * Permanent failure (-EBUSY, etc.): > + * unlike -EAGAIN case, the failed folio is > + * removed from migration folio list and not > + * retried in the next outer loop. > + */ > + nr_failed++; > + stats->nr_failed_pages += nr_pages; > + break; > + } > + } > + } > +out: > + nr_failed += retry; > + stats->nr_failed_pages += nr_retry_pages; > + if (rc != -ENOMEM) > + rc = nr_failed; > + > + return rc; > +} The interpretation of the return value of this function is somewhat unobvious. I suggest that this function be fully commented. Why does a retry contribute to nr_failed. What is the interpretation of nr_failed. etcetera.