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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54D77C61D97 for ; Sun, 29 Jan 2023 01:47:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A74DB6B0072; Sat, 28 Jan 2023 20:47:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A25076B0073; Sat, 28 Jan 2023 20:47:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ED216B0074; Sat, 28 Jan 2023 20:47:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7DC336B0072 for ; Sat, 28 Jan 2023 20:47:52 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1B11E406A3 for ; Sun, 29 Jan 2023 01:47:52 +0000 (UTC) X-FDA: 80406150384.08.D939D9A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf21.hostedemail.com (Postfix) with ESMTP id 8ADD41C0003 for ; Sun, 29 Jan 2023 01:47:48 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674956870; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3VaNn+4bIANcaMiqfG1WY3IL4Dof8ibTBn5l8aNTbng=; b=vK/mYg8PokkOqa7bYTOsowasgF18n4ok59Z39NKkMLMaCuKz7cdg/FYq8IXMpsxlpY5mab eUGpOAYzojen6ZGQ3NTSQSLj41QOk5mo77i8oKTrS5rI7/nMTh/IIw6Q9GwETZhfuxC4CK t5vaggP/V53793AzAYuZEC8EUTywGr8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=chenwandun@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674956870; a=rsa-sha256; cv=none; b=bZk16cSUdPjYWGDyImCgY1M9883NUTVKJ5UjVFO50nqJCOMkzFsfMc+EVQAvwQGc49AXBF Wsu3qyRSEpjrMOOZKcXKlFYProH8uT5Iqkk8j9zkdq5LTB9zzAvKNk57qhzRJVGFQgYdLY 278Mg5oDoj5QKyUv355K+Y7LJf7walQ= Received: from dggpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4P4Dhn752wzfYkR; Sun, 29 Jan 2023 09:47:37 +0800 (CST) Received: from [10.174.178.178] (10.174.178.178) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sun, 29 Jan 2023 09:47:43 +0800 Message-ID: Date: Sun, 29 Jan 2023 09:47:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: Re: [PATCH -v3 2/9] migrate_pages: separate hugetlb folios migration To: "Huang, Ying" CC: Andrew Morton , , , Baolin Wang , Zi Yan , Yang Shi , Oscar Salvador , Matthew Wilcox , Bharata B Rao , Alistair Popple , haoxin , Minchan Kim References: <20230116063057.653862-1-ying.huang@intel.com> <20230116063057.653862-3-ying.huang@intel.com> <87edrech21.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Chen Wandun In-Reply-To: <87edrech21.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.178] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 8ADD41C0003 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: esxt91onbuejdb16w6hj31pwf8dpqyih X-HE-Tag: 1674956868-378083 X-HE-Meta: U2FsdGVkX19lGBr3hnGPsAem1BbfYm7tvoizr5V8o8WE+Uz33Cu98QpuZXXyY3S9xSgbSpQr3rwcCV1txtRiT8gmfAx5q6SwjuQe33DKxNWJ41CBrDOF/E4Zj+++zEGvK1q7bu0uCnpZN2VUlrm/aKzKPH/sbbJxQhk3Jd+fqY4jJVFVLNsSx5p9F3wHzmYKkFURlUi3B5UZCAoQ5vXcxsMppBUklWELTh7u84zcdby4ATPvJevNEPavwCKECfo0K7/wlIvMPD5kVd9nD+BfMAAvBlr0/MHN8x98d3e56Zd4sjJDmIBobW/9UAIZFrJzMAuIP8Auzj065jQaw4YP4UrQZjpzTxH4f0FOB/D3m/OACNSAyY+eRKId+qnF9RS5RDmxLfA0KRkTNtUYqiv8JKvhGXs12PZMat4TR6oIlswp9IzT509IXvu63uL9zcIRw2xUeFOg3AVMSrErr0MOH0qduxZ5BviG/lNxiyEgoR0cNE178/d5+BBn6OajdMLVe6nq9xYv90fi9oEDL4mNChJuJvJwuIWnHDafAbo48PmoGbe70z5v/keW4Ulyr2qBj2ssIDaczq18AKJXnTvjdANx8k4rPgKgRY0Ic6Gg7CxPnSYAJSpQzYEowwJuWmpKDzQK1lxuK9HaESN9rfV0xXE5P8CxdMNea1Ins5g830ua9nJves+y96wryWybn5AEmGGvtdqMSw7+EwUAuwHXqGdhn8LvxgIhrIN0Xde/r/0PGHeCdpg7HS3Mhh9XmiSR/9nEevMWdxBrD07OC11P+EGBR2ytsvi4wpG7USgQuOLsr8UYf4xrlpUiFPni2pm/TMTSgbBKnh53IzilSP8ygYutj9PK9iTSnk2uyrMCO53OAfu3qZ/8sR230CeP7IxBYPYQQ+Z3bIelvKbtb4VFjya1tGYwo5yho/t5JJc8omYJM0Uh5VihMfhe11FAIyDxZWXyVdnxaprvVasYScW 5+Ur3S9C nulhGCUHJW3hWxv5BZlK1/Xc7ILDll+nInztbvq6uIBmWU+oZpjb3XtAX1AEAGtCubqxFDbsIrQHmvsu4/aw9NaoDEbf6t8j4f6k3Aj1DMFKjTxxS6fcYQiwVDZoqB5eGJS/qMqcRkjVqOCea7C+2tZFIybdNqzdZWgjWbyb55DahGjw9M0dBA3/EMY9C0nB6kPqq0sEPwVzPiHpznqA9NofL8Pl1LW4O7uu/VX0Hk8vCboG9aS4yOCvH2VOe7+DCEpZoIjNNUOX9Smhi4eQbGWkCiH8fZTUCsP+0KJxvO/cZs2fGrzbZN655KobJHM0MxQqc4snE0xu8+0ojNC9+BFP+jQy4SHPeELuc09tTJxtN8pycmXvn7PHvKXiyrIGEQVt0cjSySWnuVP+6Wny0p58EkJevBTfnsdJNiCSA3iQLqzBqaIEY48l4Arl0r47ooCD1PEPGZIQTBcw= 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: 在 2023/1/29 8:36, Huang, Ying 写道: > Chen Wandun writes: > >> On 2023/1/16 14:30, 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. >>> >>> Signed-off-by: "Huang, Ying" >>> Reviewed-by: Baolin Wang >>> Cc: Zi Yan >>> Cc: Yang Shi >>> Cc: Oscar Salvador >>> Cc: Matthew Wilcox >>> Cc: Bharata B Rao >>> Cc: Alistair Popple >>> Cc: haoxin >>> Cc: Minchan Kim >>> --- >>> mm/migrate.c | 141 +++++++++++++++++++++++++++++++++++++++++++-------- >>> 1 file changed, 119 insertions(+), 22 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index ef388a9e4747..be7f37523463 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -1396,6 +1396,8 @@ static inline int try_split_folio(struct folio *folio, struct list_head *split_f >>> return rc; >>> } >>> +#define NR_MAX_MIGRATE_PAGES_RETRY 10 >>> + >>> struct migrate_pages_stats { >>> int nr_succeeded; /* Normal and large folios migrated successfully, in >>> units of base pages */ >>> @@ -1406,6 +1408,95 @@ struct migrate_pages_stats { >>> int nr_thp_split; /* THP split before migrating */ >>> }; >>> +/* >>> + * Returns the number of hugetlb folios that were not migrated, or an error code >>> + * after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no hugetlb folios are movable >>> + * any more because the list has become empty or no retryable hugetlb folios >>> + * exist any more. It is caller's responsibility to call putback_movable_pages() >>> + * only if ret != 0. >>> + */ >>> +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, nr_pages; >>> + >>> + for (pass = 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && retry; pass++) { >>> + 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. >>> + */ >>> + stats->nr_failed_pages += nr_pages + nr_retry_pages; >>> + return -ENOMEM; >>> + 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; >>> + } >>> + } >>> + } >>> + /* >>> + * nr_failed is number of hugetlb folios failed to be migrated. After >>> + * NR_MAX_MIGRATE_PAGES_RETRY attempts, give up and count retried hugetlb >>> + * folios as failed. >>> + */ >>> + nr_failed += retry; >>> + stats->nr_failed_pages += nr_retry_pages; >>> + >>> + return nr_failed; >>> +} >>> + >>> /* >>> * migrate_pages - migrate the folios specified in a list, to the free folios >>> * supplied as the target for the page migration >>> @@ -1422,10 +1513,10 @@ struct migrate_pages_stats { >>> * @ret_succeeded: Set to the number of folios migrated successfully if >>> * the caller passes a non-NULL pointer. >>> * >>> - * The function returns after 10 attempts or if no folios are movable any more >>> - * because the list has become empty or no retryable folios exist any more. >>> - * It is caller's responsibility to call putback_movable_pages() to return folios >>> - * to the LRU or free list only if ret != 0. >>> + * The function returns after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no folios >>> + * are movable any more because the list has become empty or no retryable folios >>> + * exist any more. It is caller's responsibility to call putback_movable_pages() >>> + * only if ret != 0. >>> * >>> * Returns the number of {normal folio, large folio, hugetlb} that were not >>> * migrated, or an error code. The number of large folio splits will be >>> @@ -1439,7 +1530,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, >>> int retry = 1; >>> int large_retry = 1; >>> int thp_retry = 1; >>> - int nr_failed = 0; >>> + int nr_failed; >>> int nr_retry_pages = 0; >>> int nr_large_failed = 0; >>> int pass = 0; >>> @@ -1456,38 +1547,45 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, >>> trace_mm_migrate_pages_start(mode, reason); >>> memset(&stats, 0, sizeof(stats)); >>> + rc = migrate_hugetlbs(from, get_new_page, put_new_page, private, mode, reason, >>> + &stats, &ret_folios); >>> + if (rc < 0) >>> + goto out; >> How about continue migrate small page for -ENOMEM case? maybe >> there are still >> free small pages. > Sounds reasonable to me. How about do that on top of this series? Do > you have interest to do that? Happy to do that, thanks for you reply. Best Regards, Wandun > > Best Regards, > Huang, Ying > > .