Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11211477rwl; Mon, 2 Jan 2023 16:38:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsaUFUbe1t+JSsQQ2px9pRCGZlmvpa00RCW3twsy4M/7ty6OX5M1XHytASv3E0vJYoRXN6h X-Received: by 2002:a05:6a20:4295:b0:a8:8714:233b with SMTP id o21-20020a056a20429500b000a88714233bmr66933598pzj.57.1672706317478; Mon, 02 Jan 2023 16:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672706317; cv=none; d=google.com; s=arc-20160816; b=Fb87XA4suSoYqrk6H9k95wSlcWx+QLAe/ziaXXOo5Y8VCA/0fxVrKVpxGz6COok4KU Eto7Oo2mmc0k50SrttZc6qAuqxCpMgckAhKfM5afV6Bsj9iNTo0M2Yfw07oVFj3kUQCd DUMxtpgmSzGxDRGZdx6H2zbHZx8e3hFY6qHaniNy6a5kuTPCR8UsO/jsrFv2uXoMX59v II+p1w8Ls0XnKYsiIS/wfOU2XhmMjUevLGQohk/mdJDIv6qbrmswa+prIh7sD58k20C7 nXmW3IqwD1vxbUL0Vg5JRERZgSrYgDSiTAnmnQmsgHzsztbQUhR546J6W7SmdjNnnQ+/ X25w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=95CQbU+zcOknYECwMv5ASW6ZetRKOqEhOAEFfojbLro=; b=a55WcLEf9+t3tWoqRoU9guYXOjgZoJAUr7o9E3kV3aMB5qCrbzjKgKAFqHvamLqnhi 5Ueor9WzmzLstyyDfELAReIWVxyhpabjFF3f/YFfx5LHyDYysrHLpU1RuVAaU9SpuwZt TKhCvlgCu3yR6Aug+OBMfrhdTwqgzhPbPMsQ/c98UfRMrAN8d3fgO1MdjmNPgNA3y5o2 RtrYGa0GVLPDULQS80usI1PLfxit/CCqpJfP7lsxHcWtAiwJHrn5GRQHnVm38OQNflyI uMedXB/bI1XK5mNwqqM2uSsBHQvEmu31EF9jCkqIgs8MMplHFau6LKwV2JavAImHbVMY plHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aanDE+h4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bg3-20020a056a02010300b00477abe15f06si31068361pgb.63.2023.01.02.16.38.28; Mon, 02 Jan 2023 16:38:37 -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=@intel.com header.s=Intel header.b=aanDE+h4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjABXyd (ORCPT + 62 others); Mon, 2 Jan 2023 18:54:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjABXyb (ORCPT ); Mon, 2 Jan 2023 18:54:31 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF959593 for ; Mon, 2 Jan 2023 15:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672703669; x=1704239669; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=aR3K3ex1SxuJ6C4KEDB9xBXcz30I39NL7soRBCm7lKo=; b=aanDE+h4kQdXdVWdWmUwHNjzkKBzqJi9j5CkwVJfZghitnzfXv0qFlBj 9KYxqEn046vpI9mMMYkvCehUeFRlI1+ZskshN37vsE0YplZTaBthcnE95 q4clMPnKRh1CG0L7KgLGYVH+Odk3pX8CuWr4GpfSDJ0S//J5Tvn5ls3DF AY+7TdYxcyy7JbA0mYuCksQN8KSzyptXXPSLCoJIJPzroa+44udVE02Dm H9m4NkqD3OR48WNovj+tL7NxJb7gz1Z/FVdGE2uXJT1M67YQkRGb0w8eh IRHIV5zYwx+69f7Fm5PUjoBSy20YDO/PSoVXqloozGk2dpTXUsYCLSpfn w==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="383850910" X-IronPort-AV: E=Sophos;i="5.96,295,1665471600"; d="scan'208";a="383850910" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2023 15:54:28 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="685197615" X-IronPort-AV: E=Sophos;i="5.96,295,1665471600"; d="scan'208";a="685197615" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2023 15:54:25 -0800 From: "Huang, Ying" To: Andrew Morton 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 References: <20221227002859.27740-1-ying.huang@intel.com> <20221227002859.27740-3-ying.huang@intel.com> <20221228151735.e855bde30c1782bb45b97930@linux-foundation.org> Date: Tue, 03 Jan 2023 07:53:31 +0800 In-Reply-To: <20221228151735.e855bde30c1782bb45b97930@linux-foundation.org> (Andrew Morton's message of "Wed, 28 Dec 2022 15:17:35 -0800") Message-ID: <87a630xzlw.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 Andrew Morton writes: > 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? This is inherited from the original max pass number from migrate_pages(). Which is introduced in commit 49d2e9cc4544 ("[PATCH] Swap Migration V5: migrate_pages() function"). From the code and commit message, I don't find out why. I guess that we need some magic number anyway. Now, because the magic number is used in 2 places (migrate_pages() and migrate_hugetlbs()), it's better to define it as a constant macro? >> + 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. Sure. Will do that in the next version. Best Regards, Huang, Ying