Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp344958rwb; Wed, 21 Sep 2022 23:44:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48ElhnjnzO4yzwCCOXCS0uTbBch0ZuZPTC6/0tsnaOA47ks7ny8V5A6xP0SQ2ABJSsnSFX X-Received: by 2002:a17:907:1b03:b0:6ff:78d4:c140 with SMTP id mp3-20020a1709071b0300b006ff78d4c140mr1525742ejc.554.1663829090572; Wed, 21 Sep 2022 23:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663829090; cv=none; d=google.com; s=arc-20160816; b=hS78fchOOv/6s+4oFDRV3SYgjpgnoP/MiUS/Lon1cdERpgFwrEFeeSKskDZI59SW45 q3nFRDVt9Q78XzQitNWRqtxgyHU4g+vMHklSo//pTd+XCnvyUwV4xs3AomEGH9P0+ZhP dPGzrBSA+I12usegLbb07SGxxG65tkuFhz/8lXI4AToJ2yz/mZQlc3O4aBkcmVg6bG9f 5J5a7Ymyv3dg3hU1xZIQSXGuNdeGCy6Q6L2jtB3RwU+RVGaa9PTAbBXwBOw1cf/dY8oG +bwMZcpM+jav6pz7EX7/CE5Eu01+VEpNlJzr3JMws1+odqKRmu6SatAFtGdYiCUwZsI6 6Rig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=71JdlM018XynYvKifIVO+nx98P3JsHkD4k+O+7efrXg=; b=QvADkUND1NQx0O9ou03B4uAUQd4Zshg80fGAP6o3/FjiCpcTBo0tNlZ4FEe2tz2c9+ pAjQeqsxPm8kfXynPLiMgmuGjiWhDt0YvGVh7q3zEH9WNbC8457DRCzKF3nmiYJCzSTX A7l+VGzVKT8OFNCma5Ij9mRtmm+IznTmqK45TDWGBNtoZrAo9n8UPSMEAVyx7nVoe7Io OdnsQxgbx5MWfZdMHzfmZEGNZfLEb6Vwx/CKScmtij7mReXDpXr2ZKfD99UnJf9XS10x BsHsx4iEe8RaZRZEBT4xDYQUvV+quCCC4LvTt3ho1gDxUvntapvqUj+sXQY9gvL/nWDi bdTw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020a50fb8f000000b0044e85e58093si3942904edq.581.2022.09.21.23.44.24; Wed, 21 Sep 2022 23:44:50 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbiIVGDy (ORCPT + 99 others); Thu, 22 Sep 2022 02:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbiIVGDs (ORCPT ); Thu, 22 Sep 2022 02:03:48 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C459B4431 for ; Wed, 21 Sep 2022 23:03:41 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R401e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VQQzvIj_1663826617; Received: from 30.97.48.87(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VQQzvIj_1663826617) by smtp.aliyun-inc.com; Thu, 22 Sep 2022 14:03:39 +0800 Message-ID: <0a41c051-7d7e-cb1b-8273-192252e74b94@linux.alibaba.com> Date: Thu, 22 Sep 2022 14:03:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [RFC 1/6] mm/migrate_pages: separate huge page and normal pages migration To: Huang Ying , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Zi Yan , Yang Shi , Oscar Salvador , Matthew Wilcox References: <20220921060616.73086-1-ying.huang@intel.com> <20220921060616.73086-2-ying.huang@intel.com> From: Baolin Wang In-Reply-To: <20220921060616.73086-2-ying.huang@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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 9/21/2022 2:06 PM, Huang Ying wrote: > This is a preparation patch to batch the page unmapping and moving for > the normal pages and THPs. Based on that we can batch the TLB > shootdown during the page migration and make it possible to use some > hardware accelerator for the page copying. > > In this patch the huge page (PageHuge()) and normal page and THP > migration is separated in migrate_pages() to make it easy to change > the normal page and THP migration implementation. > > Signed-off-by: "Huang, Ying" > Cc: Zi Yan > Cc: Yang Shi > Cc: Baolin Wang > Cc: Oscar Salvador > Cc: Matthew Wilcox > --- > mm/migrate.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 64 insertions(+), 9 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 571d8c9fd5bc..117134f1c6dc 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1414,6 +1414,66 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, > > trace_mm_migrate_pages_start(mode, reason); > > + for (pass = 0; pass < 10 && retry; pass++) { > + retry = 0; > + > + list_for_each_entry_safe(page, page2, from, lru) { > + nr_subpages = compound_nr(page); > + cond_resched(); > + > + if (!PageHuge(page)) > + continue; > + > + rc = unmap_and_move_huge_page(get_new_page, > + put_new_page, private, page, > + pass > 2, mode, reason, > + &ret_pages); > + /* > + * The rules are: > + * Success: hugetlb page 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_pages list then splice to > + * from list > + */ > + switch(rc) { > + case -ENOSYS: > + /* Hugetlb migration is unsupported */ > + nr_failed++; > + nr_failed_pages += nr_subpages; > + list_move_tail(&page->lru, &ret_pages); > + break; > + case -ENOMEM: > + /* > + * When memory is low, don't bother to try to migrate > + * other pages, just exit. > + */ > + nr_failed++; > + nr_failed_pages += nr_subpages + nr_retry_pages; > + goto out; > + case -EAGAIN: > + retry++; > + nr_retry_pages += nr_subpages; > + break; > + case MIGRATEPAGE_SUCCESS: > + nr_succeeded += nr_subpages; > + break; > + default: > + /* > + * Permanent failure (-EBUSY, etc.): > + * unlike -EAGAIN case, the failed page is > + * removed from migration page list and not > + * retried in the next outer loop. > + */ > + nr_failed++; > + nr_failed_pages += nr_subpages; > + break; > + } > + } > + } > + nr_failed += retry; Seems we should also record the nr_retry_pages? since the second loop will reset the nr_retry_pages. nr_failed_pages += nr_retry_pages; Besides, I also agree with Zi Yan's comment to simplify this larger function.