From patchwork Wed Apr 17 07:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13632933 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 F08A1C4345F for ; Wed, 17 Apr 2024 07:19:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAE766B0092; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C77036B009B; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B2976B0092; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4951D6B0098 for ; Wed, 17 Apr 2024 03:19:09 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 19EACC0D60 for ; Wed, 17 Apr 2024 07:19:09 +0000 (UTC) X-FDA: 82018172418.22.915026A Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf16.hostedemail.com (Postfix) with ESMTP id 31BD9180006 for ; Wed, 17 Apr 2024 07:19:06 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713338347; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=GRdfmcANeTUuYVpdeIOK+o3p+1sSMk02VifRozGkWaY=; b=QOptPywtJiYeVAH+HDKDMfOdnTvoe9jfBs89qZuXBn+ayktgAeZu48URBZVjtt13MTgX9K G54m0PpIMRGlIIZEydiUir+XGZ4n0PS6wfV4KXdsiql60z3lMydZHuNwF/7MJfQFQtc5Iz klqHjvnek+jWEWZesSU6P2uMdluGkFk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713338347; a=rsa-sha256; cv=none; b=FQgF6bngGzvHP41/lt4arSdOmIg9+uOlOEUhygA9fGhM9JvDZOxCYSHOXU2YNs4CwB2Ua1 JxEYyre+BH5P+mXKbNh9F1dW+ASuqi5FX7b5T/xbZ663+UfJ3Yun+DwiicYyxcowArHPK6 QorzB4e3KJc7Pb2NBHJMUHFb4c0nNnQ= X-AuditID: a67dfc5b-d6dff70000001748-a7-661f77e22826 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [PATCH v9 5/8] mm: separate move/undo parts from migrate_pages_batch() Date: Wed, 17 Apr 2024 16:18:44 +0900 Message-Id: <20240417071847.29584-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240417071847.29584-1-byungchul@sk.com> References: <20240417071847.29584-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRm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3MtDj/b6rbB6LX3xg8tj6y86jceo1No/Pm+QC+KO4bFJS czLLUov07RK4Mj7eOspc8F27onHaUdYGxunKXYycHBICJhJr9l9kB7HZBNQlbtz4yQxiiwiY SRxs/QMWZxa4yyRxoJ+ti5GDQ1jAX+L7bx2QMIuAqkTn7N+sIDavgKlE06RpTBAj5SVWbzgA NoYTaMzm5jVsILYQUM33Ex/ZJjByLWBkWMUokplXlpuYmWOqV5ydUZmXWaGXnJ+7iREYxstq /0zcwfjlsvshRgEORiUeXoMouTQh1sSy4srcQ4wSHMxKIrwtwrJpQrwpiZVVqUX58UWlOanF hxilOViUxHm9wlMThATSE0tSs1NTC1KLYLJMHJxSDYwh1+w64rKdty7ffpGv4Vh9dPKcZ9KS xrvjXtn+3Trx895M86ObBRK7tkypvLtDXpXH7x/rRZXtzuWNmcdklduXVp8SCmxy/M4ddm5q 5vFIZ73y8Ff9vguOyAU4TmQ4L5R46dzezlydah0Hzm0SZYwaOiFPr/itb+nbcqyNP616Hvea G9wlIUosxRmJhlrMRcWJAKjdQyJfAgAA X-CFilter-Loop: Reflected X-Stat-Signature: s86jwozw8yyeig1xzjkr81reepswuifi X-Rspamd-Queue-Id: 31BD9180006 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1713338346-14800 X-HE-Meta: U2FsdGVkX18qICdo3x2BwSMWyqMf/kvsu8v8jsS9QJaZe9yBWgEUik2beJA7K6iqx08FXgh1CvhZC7s2xOHtOst3frv99miZ2hnpYOGgEi7FoCFEwI4KINUnqUf8HH6qD+z8Z8IfSAuasOBGqipeyGHi2equr6wssgEIckuB2KVBGnogpOuS9uEn/Hq4cGFLs2ujiGnBapjp+zWydGd0IPY46Awd7HWoMntQHnxbj7yMzNr+masClK4FTsIFjCOqt1pBrf12nI4DNhPh7jU7zJ6BfsjvNvJXUKKLGEhiJZZDQ3FQJPF4NvD1mJD0lzOY23UrWLmla7gXkDZur/W73RBbQ+6Qhs27/mTBf/NAtwJOrCdJPjxSyrEQUGIHhkgMj8iJBXguWPZG+aF5cF6psHFSzkK+SWgCjrluust1Wsf3YXu8J146tLI1zKfHi134k65mNZnf3sPfy1FbcH79eilPq56fnKxbPgAPthyp1mnWMcpieuPkTt7oh79JFCOq8yIDi8zBKi0LSpf1UYodFELxRCJZsaoIvBaAd8r3ezmrGHVSPNLsQ4O1PljFCI/kiA0PTjCMMBgyCpatYBGF3hhMQ5XnVa8nAovo+WkKD7U5YBkuWgco584e729FMm6nSvMXzTocujvcrbP+mWEnFY2cGp4DATAzQEMlkDzc1RQV4FovkdOWy3iL21s+d7iCWl5AqJQh0Ou6qrfNNO/imP7eqj90g15UTG/actNhkVrqDn12rMv7Yc9Y3AV/ic5hkYyJE44azmOYIKVbCoID8tB7OY2VPWkH07uvJ6VkXhHtLj+VBVLZfFbmQRWkGvtGgsTA7wuAwyupgMaGuHnhRXxN+JL/UWdXDD+FsZK+wdLXxS4MX+XedQD3Yot/qb8FtOogZnhtvjENh+MeacViemmnNEtSgRQhbOUURq87DdArb4NOPnlcD9e7r82o/VfL8Q1sVTy6F2STz5d9NAH 6WPSISe6 Saas+Bc82tiNn9+AnovvN/cEeKQvkYmLEk0AC 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: List-Subscribe: List-Unsubscribe: Functionally, no change. This is a preparation for migrc mechanism that requires to use separated folio lists for its own handling during migration. Refactored migrate_pages_batch() and separated move/undo parts from migrate_pages_batch(). Signed-off-by: Byungchul Park --- mm/migrate.c | 134 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 73a052a382f1..fed3a65e9bbe 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1609,6 +1609,81 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, return nr_failed; } +static void migrate_folios_move(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + enum migrate_mode mode, int reason, + struct list_head *ret_folios, + struct migrate_pages_stats *stats, + int *retry, int *thp_retry, int *nr_failed, + int *nr_retry_pages) +{ + struct folio *folio, *folio2, *dst, *dst2; + bool is_thp; + int nr_pages; + int rc; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); + nr_pages = folio_nr_pages(folio); + + cond_resched(); + + rc = migrate_folio_move(put_new_folio, private, + folio, dst, mode, + reason, ret_folios); + /* + * The rules are: + * Success: folio will be freed + * -EAGAIN: stay on the unmap_folios list + * Other errno: put on ret_folios list + */ + switch(rc) { + case -EAGAIN: + *retry += 1; + *thp_retry += is_thp; + *nr_retry_pages += nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded += nr_pages; + stats->nr_thp_succeeded += is_thp; + break; + default: + *nr_failed += 1; + stats->nr_thp_failed += is_thp; + stats->nr_failed_pages += nr_pages; + break; + } + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + +static void migrate_folios_undo(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + struct list_head *ret_folios) +{ + struct folio *folio, *folio2, *dst, *dst2; + + dst = list_first_entry(dst_folios, struct folio, lru); + dst2 = list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + int old_page_state = 0; + struct anon_vma *anon_vma = NULL; + + __migrate_folio_extract(dst, &old_page_state, &anon_vma); + migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, + anon_vma, true, ret_folios); + list_del(&dst->lru); + migrate_folio_undo_dst(dst, true, put_new_folio, private); + dst = dst2; + dst2 = list_next_entry(dst, lru); + } +} + /* * migrate_pages_batch() first unmaps folios in the from list as many as * possible, then move the unmapped folios. @@ -1631,7 +1706,7 @@ static int migrate_pages_batch(struct list_head *from, int pass = 0; bool is_thp = false; bool is_large = false; - struct folio *folio, *folio2, *dst = NULL, *dst2; + struct folio *folio, *folio2, *dst = NULL; int rc, rc_saved = 0, nr_pages; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); @@ -1767,42 +1842,11 @@ static int migrate_pages_batch(struct list_head *from, thp_retry = 0; nr_retry_pages = 0; - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); - nr_pages = folio_nr_pages(folio); - - cond_resched(); - - rc = migrate_folio_move(put_new_folio, private, - folio, dst, mode, - reason, ret_folios); - /* - * The rules are: - * Success: folio will be freed - * -EAGAIN: stay on the unmap_folios list - * Other errno: put on ret_folios list - */ - switch(rc) { - case -EAGAIN: - retry++; - thp_retry += is_thp; - nr_retry_pages += nr_pages; - break; - case MIGRATEPAGE_SUCCESS: - stats->nr_succeeded += nr_pages; - stats->nr_thp_succeeded += is_thp; - break; - default: - nr_failed++; - stats->nr_thp_failed += is_thp; - stats->nr_failed_pages += nr_pages; - break; - } - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + /* Move the unmapped folios */ + migrate_folios_move(&unmap_folios, &dst_folios, + put_new_folio, private, mode, reason, + ret_folios, stats, &retry, &thp_retry, + &nr_failed, &nr_retry_pages); } nr_failed += retry; stats->nr_thp_failed += thp_retry; @@ -1811,20 +1855,8 @@ static int migrate_pages_batch(struct list_head *from, rc = rc_saved ? : nr_failed; out: /* Cleanup remaining folios */ - dst = list_first_entry(&dst_folios, struct folio, lru); - dst2 = list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - int old_page_state = 0; - struct anon_vma *anon_vma = NULL; - - __migrate_folio_extract(dst, &old_page_state, &anon_vma); - migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, - anon_vma, true, ret_folios); - list_del(&dst->lru); - migrate_folio_undo_dst(dst, true, put_new_folio, private); - dst = dst2; - dst2 = list_next_entry(dst, lru); - } + migrate_folios_undo(&unmap_folios, &dst_folios, + put_new_folio, private, ret_folios); return rc; }