From patchwork Mon Jan 22 01:00:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13524734 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 3E7C2C47422 for ; Mon, 22 Jan 2024 02:48:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C55856B0074; Sun, 21 Jan 2024 21:48:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B693B6B0078; Sun, 21 Jan 2024 21:48:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96C9A6B007B; Sun, 21 Jan 2024 21:48:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8351C6B0074 for ; Sun, 21 Jan 2024 21:48:15 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5CAB780746 for ; Mon, 22 Jan 2024 02:48:15 +0000 (UTC) X-FDA: 81705412950.10.A525843 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf08.hostedemail.com (Postfix) with ESMTP id 797EF16000E for ; Mon, 22 Jan 2024 02:48:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.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=1705891693; 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=hj/OU3wk3OzsqULfJnD2mvtgwTJyJb/ndDOd9gzDe6E=; b=sHC+tB31LNQ79HX2rgU/phzo482dXqtb4/OUOdD5bJPBHmB4qc/LXcFlI1wX9spel4cLis MsveMw/pNdEWuVoX/TxXgk72TFv3hHXiIPLGC3KCmbe/5h5ck2r+ZGAtmocTj85Eh1OIfp /LyZ5l+nie3+pORHgAnZjDSKlCauKGk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.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=1705891693; a=rsa-sha256; cv=none; b=fWdW9hGAByuDNDERNe0UHdPZG4ADMkZUJGPXooRwBoA4rA84LblJzJeqzOrfnrU1uBOYLu dIkdC1hXar+0yNYHdROPJ26ifH2nLnrJ6QsItWvdjrTTbiexK2iNK7iMLMsOXFbvSqAOY3 +nGXy0athrOWBxBlDIjN7q5GcJf76k8= X-AuditID: a67dfc5b-d85ff70000001748-84-65adbe43617b 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, namit@vmware.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 v7 5/8] mm: Separate move/undo doing on folio list from migrate_pages_batch() Date: Mon, 22 Jan 2024 10:00:37 +0900 Message-Id: <20240122010040.74346-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240122010040.74346-1-byungchul@sk.com> References: <20240122010040.74346-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA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 85LJY9OqTjaPTZ8msXu8O3eO3ePEjN8sHvNOBnq833eVzWPxiw9MHlt/2Xk0Tr3G5vF5k5zH u/lv2QIEorhsUlJzMstSi/TtErgybry/y17Qr1OxaM5D9gbGlcpdjJwcEgImEhfOz2cGsdkE 1CVu3PgJZosImEkcbP3D3sXIxcEs8JFJYvX3DhaQhLBArMSqhV2sIDaLgKrE2f2PwGxeAVOJ C9M2sUAMlZdYveEA2CBOoEFTfnUxgdhCQDVzP+xknMDItYCRYRWjSGZeWW5iZo6pXnF2RmVe ZoVecn7uJkZgeC+r/TNxB+OXy+6HGAU4GJV4eB3Y16YKsSaWFVfmHmKU4GBWEuHlV12VKsSb klhZlVqUH19UmpNafIhRmoNFSZzXKzw1QUggPbEkNTs1tSC1CCbLxMEp1cB47ckGe8Z5rqdO b6u78sza8ZXU6/fhrgwTfFvZbzQ2zj76ZG3tYqE1Yq8l1bRuLQ1JWcijw922cfFj/crVak9v f8+V5vc13FRVzFhjeqQyu1vSQ47rTb1S+wwLj6k8NizivzR2/lwse8THzIxHcm3JjqyC8qjF DSrHI8sPLVM1vmJwcmdmP78SS3FGoqEWc1FxIgDyA45IawIAAA== X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 797EF16000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 46zaw93ymwh9ck9n178fyts6i8mifjrk X-HE-Tag: 1705891693-341465 X-HE-Meta: U2FsdGVkX1/82XhGfnUrXuNVI2Gvot+DqhVxQ3dA4cZ9BrKkOdIJ1MYxcxMIuHlXvtyW/XH0aDDkKA2wlEytLSRCtwFMiCdbgA9y5o29ef0WaU2/R5jrCkptU6VvxodRLGDVfDcIkS3LjepPuoFiKVZE3P6TzUYdzRIlnYAEUECmZ8dQapM5QzfLY7JiR3q2LcO9mvNcLtkel/YNry3Utggk1lUsGwSdAQ8r5Madk7WYF8OzxNIp+2NTbDkU7nZh4TJ8o/saTEayKCNZJFjy9OwhaAU9Hq2LERWP9lcYfJQaVIL8CiRAxg2VsD4FqCCjHdwG8oMmYSxdr6VkuHn0H3kp4kqK/RE56svWTPxjR3MWyTa6ySGOy2GluH7Wkj2rpXYsdpVvVg47af8Lx4YXJy8hJ7RpQRTS085kVtXbJ7VKcBWNuSgjadIX5cHE/n5d/W7T/QydrEx/ObTRYbUgG4NDKu7pDeTfUPlkROSLn8EePgLjc8YYLLETV5VwZcHu3DGt0WMr/AWXqyTORM8QRs/2JeOcet5EYu2Cl7+eOqObcCegVT9edXJPA/QUsiLmfahqux3kSpB4ULRGoQzbCCJPUZCUP3V+IGwaPy6XjMF+zfZ5TVVdGadnnv/PmrEu4DOlDt9Sodphqfhb6qouQ0nYQzG8LkHXahT3yhWu6QrluIGuBWoZNsYTE0cdTN9Wf+rh71IsgXDl1W1T7F1GtfMflgVMDpkMKuwhSVG4mMsH3DwQ2CADUEbzlYoPPlIIVrPP18UTa6Jc8FJQDyz1JGnRs1kcCiqiNWVfFOVUT0TKJEdkhycIe3QNDpbBKPta99X9A+8Aod/YOn+hORcn6CPh0BSIPwzAKR73FN0kCs083xdEzeIaT2iGfH1W4QmpOwMXvZRaGzyUgsNkZ1B3JOWMf+ebG6aH2FDkmoRV4J2YE5ucda46D7Vvuo/n1ABZ7tv9glDv5p6FFFXPncF Oy7v5HBz 2reajEgsKqp3uOVoAYE04iWmeKAdn/gJtUzpu0TVHOobID3b+7n0KT++DL5X5ON7emyDp4Ux4SPhTV+D3s/7iTBqJK/qyu3kl+Q8qdaAJlxRnbjxWrN0CjVK1Xpjf5rXUKcGH9sHpsjWfwesVoqZPXUZ4Rg== 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 separate folio lists for its own handling at migration. Refactored migrate_pages_batch() and separated move and undo parts operating on folio list, 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 397f2a6e34cb..bbe1ecef4956 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1611,6 +1611,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. @@ -1633,7 +1708,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); @@ -1769,42 +1844,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; @@ -1813,20 +1857,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; }