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 0C2ECC433F5 for ; Wed, 24 Nov 2021 10:30:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 784726B0075; Wed, 24 Nov 2021 05:30:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 733536B0078; Wed, 24 Nov 2021 05:30:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 649836B007B; Wed, 24 Nov 2021 05:30:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id 564CF6B0075 for ; Wed, 24 Nov 2021 05:30:25 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 18F42184B1FD0 for ; Wed, 24 Nov 2021 10:30:15 +0000 (UTC) X-FDA: 78843453990.21.B6800C0 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by imf31.hostedemail.com (Postfix) with ESMTP id 2830C104631F for ; Wed, 24 Nov 2021 10:30:05 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Uy7GoT3_1637749807; Received: from 30.21.164.55(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Uy7GoT3_1637749807) by smtp.aliyun-inc.com(127.0.0.1); Wed, 24 Nov 2021 18:30:08 +0800 Message-ID: <76c241cc-5de7-d083-312c-373645ee8a77@linux.alibaba.com> Date: Wed, 24 Nov 2021 18:30:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH 1/3] mm: migrate: Fix the return value of migrate_pages() To: Mike Kravetz , akpm@linux-foundation.org Cc: ziy@nvidia.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <6486fabc3e8c66ff613e150af25e89b3147977a6.1636275127.git.baolin.wang@linux.alibaba.com> <13b2c5d1-ef3b-3e29-32fe-cb4294bb1531@oracle.com> From: Baolin Wang In-Reply-To: <13b2c5d1-ef3b-3e29-32fe-cb4294bb1531@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2830C104631F X-Stat-Signature: bq4ffbm5chm64d9q1a3mjiw4kuf3yx8s Authentication-Results: imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.45 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-HE-Tag: 1637749805-288393 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: On 2021/11/24 2:46, Mike Kravetz wrote: > On 11/7/21 01:57, Baolin Wang wrote: >> As Zi Yan pointed out, the syscall move_pages() can return a non-migrated >> number larger than the number of pages the users tried to migrate, when a >> THP page is failed to migrate. This is confusing for users. >> >> Since other migration scenarios do not care about the actual non-migrated >> number of pages except the memory compaction migration which will fix in >> following patch. Thus we can change the return value to return the number >> of {normal page, THP, hugetlb} instead to avoid this issue, and the number >> of THP splits will be considered as the number of non-migrated THP, no matter >> how many subpages of the THP are migrated successfully. Meanwhile we should >> still keep the migration counters using the number of normal pages. >> >> Co-developed-by: Zi Yan >> Signed-off-by: Zi Yan >> Signed-off-by: Baolin Wang >> --- >> mm/migrate.c | 63 +++++++++++++++++++++++++++++++++++++++++++++--------------- >> 1 file changed, 47 insertions(+), 16 deletions(-) >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index a11e948..9aafdab 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -1428,7 +1428,7 @@ static inline int try_split_thp(struct page *page, struct page **page2, >> * @mode: The migration mode that specifies the constraints for >> * page migration, if any. >> * @reason: The reason for page migration. >> - * @ret_succeeded: Set to the number of pages migrated successfully if >> + * @ret_succeeded: Set to the number of normal pages migrated successfully if >> * the caller passes a non-NULL pointer. >> * >> * The function returns after 10 attempts or if no pages are movable any more >> @@ -1436,7 +1436,9 @@ static inline int try_split_thp(struct page *page, struct page **page2, >> * It is caller's responsibility to call putback_movable_pages() to return pages >> * to the LRU or free list only if ret != 0. >> * >> - * Returns the number of pages that were not migrated, or an error code. >> + * Returns the number of {normal page, THP} that were not migrated, or an error code. >> + * The number of THP splits will be considered as the number of non-migrated THP, >> + * no matter how many subpages of the THP are migrated successfully. >> */ >> int migrate_pages(struct list_head *from, new_page_t get_new_page, >> free_page_t put_new_page, unsigned long private, >> @@ -1445,6 +1447,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, >> int retry = 1; >> int thp_retry = 1; >> int nr_failed = 0; >> + int nr_failed_pages = 0; >> int nr_succeeded = 0; >> int nr_thp_succeeded = 0; >> int nr_thp_failed = 0; >> @@ -1456,13 +1459,16 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, >> int swapwrite = current->flags & PF_SWAPWRITE; >> int rc, nr_subpages; >> LIST_HEAD(ret_pages); >> + LIST_HEAD(thp_split_pages); >> bool nosplit = (reason == MR_NUMA_MISPLACED); >> + bool no_subpage_counting = false; >> >> trace_mm_migrate_pages_start(mode, reason); >> >> if (!swapwrite) >> current->flags |= PF_SWAPWRITE; >> >> +thp_subpage_migration: >> for (pass = 0; pass < 10 && (retry || thp_retry); pass++) { >> retry = 0; >> thp_retry = 0; >> @@ -1511,18 +1517,20 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, >> case -ENOSYS: >> /* THP migration is unsupported */ >> if (is_thp) { >> - if (!try_split_thp(page, &page2, from)) { >> + nr_thp_failed++; >> + if (!try_split_thp(page, &page2, &thp_split_pages)) { > > Does thp_split_pages need to be initialized before this call? The declaration "LIST_HEAD(thp_split_pages);" already did list initialization, right?