From patchwork Thu Jan 11 06:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13516783 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 6C5CEC4707B for ; Thu, 11 Jan 2024 06:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F18806B0092; Thu, 11 Jan 2024 01:08:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECA086B0093; Thu, 11 Jan 2024 01:08:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D41A66B0095; Thu, 11 Jan 2024 01:08:16 -0500 (EST) 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 C443C6B0092 for ; Thu, 11 Jan 2024 01:08:16 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C173C031A for ; Thu, 11 Jan 2024 06:08:16 +0000 (UTC) X-FDA: 81666000192.16.F4A1479 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf16.hostedemail.com (Postfix) with ESMTP id AE70F180028 for ; Thu, 11 Jan 2024 06:08:14 +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=1704953295; 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=TEOS869C82ckmgOv3PFpKj54mg51a0Y4OwYWzWEv0hJ7jmy/a0phPjJQQ9AEAvaW5V8IU4 XXot63sR8Oko+k4ndQ0tfGnRAQLMVkC8WJcKD8i1/FwKjtYwoGQfP2XzHPxeV7Mi5rmDFf hBdvZtvL4EoTmYE+++YwMiKyOYkZlZw= 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=1704953295; a=rsa-sha256; cv=none; b=JJzxi5BlhX1/yaZfL2SxTkWInJbY9yiPRR46rGOxKLcabJT1ykGq5FKgAb8+UaovOZj39G tgP/91wzbtKXeCFcqYAO2c9NbzgEvOunpddYlj7EUy2KPwKXlrqYcjDgn6zLM7YHF7Xe6D ZXKuZmns1cuUtMDyV7NpAesJIM6Rp3E= X-AuditID: a67dfc5b-d6dff70000001748-ed-659f85c894c4 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, xhao@linux.alibaba.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 Subject: [v5 4/7] mm: Separate move/undo doing on folio list from migrate_pages_batch() Date: Thu, 11 Jan 2024 15:07:54 +0900 Message-Id: <20240111060757.13563-5-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240111060757.13563-1-byungchul@sk.com> References: <20240111060757.13563-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+N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8eJGb9ZPHY+tPSYdzLQ4/2+q2wei198YPLY+svO4/MmOY9389+yBfBHcdmkpOZk lqUW6dslcGXceH+XvaBfp2LRnIfsDYwrlbsYOTkkBEwkVk3awwpiswmoS9y48ZMZxBYRMJM4 2PqHvYuRi4NZ4AGTxNy3KxhBEsIC4RKNFyeD2SwCqhLrps9nB7F5BUwlri5oZoIYKi+xesMB sEGcQIMuHJ4FVM/BIQRU86itbgIj1wJGhlWMIpl5ZbmJmTmmesXZGZV5mRV6yfm5mxiBQbys 9s/EHYxfLrsfYhTgYFTi4TV4OS9ViDWxrLgy9xCjBAezkgivwuc5qUK8KYmVValF+fFFpTmp xYcYpTlYlMR5vcJTE4QE0hNLUrNTUwtSi2CyTBycUg2M8zb8P3GI4dD5fyp7tjzven33zOGC MNOZ3Sy+HKaPF+z/tVomrDJccdruk9Jsh040fpl/OUni5UT52En2k76L3FrUK/y79/TbtBWW Kg8sfk+eMFv1f2z0aVcF07A4YbYZtkf0U57mzirk+vXO6erlLS8vbvPpmca+a+NcxZJN2Ykd l317d9lzRSixFGckGmoxFxUnAgA/JYEJXgIAAA== X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: AE70F180028 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: disped1m4ii44k3czsg16kud4g5dcnhi X-HE-Tag: 1704953294-933946 X-HE-Meta: U2FsdGVkX1/GRPOlaYLIDCz9SoJyGldNh2we9IkPouwznr6keFv3p5GusmDgHyCTkK4xwaO297FxEU/daGBRgFKcHwy6UgwtQb/J61XtxYzNYN46ZCbrI50ihU3mj/gtEdlwjPn46oKvOB+jiKcPzsp4htsxitZAwunfZe+on0juGwzX06TXwCgEy2WjnYw2CFS9x0B2RZftF1cvMWPfO2JOmO/I5SCgiNTl7epfp6uec2CdJuICHJK0oKjrAXw4PWuTTinJ5LiVyyUHwZyv/mAzUfTj3kG3j+p6/XXNWnwBjYhmFYWQH/XVXWx6K6OXWGwWnIMXMAUc2z0HGMKLYTQQnZMuKHYVOGN1or1v+Ip/PNFqbEOGmU9TSIFFMkir2KnveHC1L1fW5okUbClQTTHyQYp4a2FvHWhxIQNfP6fVOl0eN0NBTRT4JDYEdQIBrPWxFdWYBqJTTq51FAME9QxJOC2RMetnZOwUnKF9oLXzgGAs7G2rjRsIFDylYVczZ584evSjl6GzdTOh7V7ZTY6LUAdlqedm0RcJP+90MM0D8dhOxJX1XagikJEmMQhpyQ3pVnaBLyQCp+3pJmdbRHTF9MAtowYLI50os4LEf0RNXHtM+fgI1hgCRx0e5CljpXW6s4AAROsPyWP3oXMWHgGJtNOwYlmYd8Y3HwAQnqYVEvuqcV0c8Tl6M+Yo5Q0D8Hu5SRLodPxplc5pJjvBIJRpZjf+RNMELRmvDIpqYfny6ipw8+Sz5SKZui7yXRxdlw2dj82ryiyOncKPSkJvpAoevrtUWWQsWOSJJDXb+X/Mln/yfbAZQIvYaQSjmiWHXrcsCgBIv6w+AwV1KCER9qvogSz2CDw8COqHq7CowPopn1H+WsAh/Hu3iuPtftDe1x30q7giCpchvzFogtW8B2NPWP+yA81U4btE50QJL1hU8SiwueegyYyrhCBk+UwlwOFfPtDIyyc8kyBSj3q dJXcsKHz myJUYUT0oduuFhBb5RVBXqrYZsIkd16ZT/gpn 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; }