From patchwork Fri May 31 09:19:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13681406 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 D7762C27C44 for ; Fri, 31 May 2024 09:20:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCD376B00A3; Fri, 31 May 2024 05:20:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2E1C6B00A4; Fri, 31 May 2024 05:20:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95A7E6B00A5; Fri, 31 May 2024 05:20:22 -0400 (EDT) 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 73F546B00A3 for ; Fri, 31 May 2024 05:20:22 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 05D921A0B9B for ; Fri, 31 May 2024 09:20:22 +0000 (UTC) X-FDA: 82178145084.04.B77EDD4 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf10.hostedemail.com (Postfix) with ESMTP id 2FDA8C002B for ; Fri, 31 May 2024 09:20:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.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=1717147220; 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=lwRYNIdgQG2CoR5OJgy3frCHcjMYFOQSIuWHhdwmIxo=; b=NYkXC3wY8KjMvDtTnxSD4WfNcC8wl3y0M2vg1OK9764IH43yTPJHbpWeZ4FnXbfqL8RBTI 9qxpocOoRPunb2TJ5uCopWfrlulgPff2g32NpNvzaciBdH/1JbSDlNOcZG0QGzaTO00eEK C7yUMvJC1pBviCnjbjyfXjQ8x/kQW8g= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.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=1717147220; a=rsa-sha256; cv=none; b=jBnk/eTWz5IupRXnfxPCkoQTjO6j6dZMvfPb8KFnE600kBvwmcWxgW2anGBcxqvIvs0aN+ 3o49HDYqZalGqorIUgHHEKE8vsLDrKSLvRmEOzgqVQhyaBtRZG3AOQdbHzNG1XYp83rDaX bF4NrsjxV9CwBQhFsiZvT46iK7THYY0= X-AuditID: a67dfc5b-d85ff70000001748-71-6659964c48ee 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 v11 10/12] mm: separate move/undo parts from migrate_pages_batch() Date: Fri, 31 May 2024 18:19:59 +0900 Message-Id: <20240531092001.30428-11-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240531092001.30428-1-byungchul@sk.com> References: <20240531092001.30428-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRmVe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D1OzPjN4jHvZKDH+31X2TwWv/jA5LH1l51H49RrbB6fN8kF8Edx2aSk 5mSWpRbp2yVwZUza1spW8FO74smuPqYGxunKXYycHBICJhIfr2xkB7HZBNQlbtz4yQxiiwiY SRxs/QMWZxa4yyRxoJ8NxBYWCJLYv6+JFcRmEVCV+Lp/DlCcg4MXqP7DaXaIkfISqzccABvD CRQ+8PcOI4gtJGAqseh/L+MERq4FjAyrGEUy88pyEzNzTPWKszMq8zIr9JLzczcxAsN4We2f iTsYv1x2P8QowMGoxMMbUBGRJsSaWFZcmXuIUYKDWUmE91c6UIg3JbGyKrUoP76oNCe1+BCj NAeLkjivV3hqgpBAemJJanZqakFqEUyWiYNTqoExrqdV8t2/qR1ef4pYd7D0LVR5Ip0mHLxC znjDU6cJUyYarLhzY0NCgv+Ba75Lv7a6hvZ9TPwp2sMlUnwldduion+sJoH2nzIt/+fO/aQe +KbYrmD1MvVlyef/rKyM75vaeXp7+bUl+3onTmQ2nx8oMS0+VeveQ9GKWGstJafpXyLzF63/ Nz9JiaU4I9FQi7moOBEAAlW2u18CAAA= X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 2FDA8C002B X-Stat-Signature: h6p1fhznsbrybk1dr7tqs6arjjiooz9y X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717147219-908547 X-HE-Meta: U2FsdGVkX19BbZP45MGsou333lyfzc8iZeWlJ1utupD6b2+X9f0YwAOrB3fNkmNzXzvbDVXgP2h3HThNp9K2SrVuLufyVrND6wZs0aRE8h2+AKELYB65Lw0Nk6mCL07MY4VR8hKbZOYFMf42Idi1d+qRsLKSV98bOxlVgCg2lkCP/JXe3GXUjcBN5NK+WSWPaQDXetEALmAUL7Ny8iEGTJ2bpZe5NSEfQsOT8imDGaWxfcx5XwGHn1U/hS7RaOMPJrh+veMbfdUMOTCYK/Kvr8MhnvGbebamDkoe6qgT6ALBXrzj9UuaDX/KhlMAe03D+vdQGGFIVShF1VPrw63tlgEn8DD4P7T2GRPMEbWkoIytUIjYBncy2JkP9SY7Vj9UMFXWhyXYyypGGTPL3kKgQ8kyBf/sdiqit3Z0AUATRmiXGtHNv3Bco25Z89ofJbbiKaTlqBzgtGiPvrNhhgKGEWan4NTOBGKJ9mvgSdFwjhl7Ep8mT+USzxbxC58y1SF/Lp/W5luAF9yRJYzONAweCekTPh9kLa237U8wM16He2B88EqxCrepc6h1AxDw23UcMDcHZTJYB2CLj4EPAVGQvmwyTlNAsfz8MUTcwZKFnr5bRajwMg/NRCI6SCfJLXDvRV252FWbS9eqmcYAYvTKPax05SYvaZEPgHEIKGpfidqPO2hTYRDD5klm5lyIUX+tHvqiMMpaF3/bYs9egdcCZaU9FW5jHo+fmJSPoQnIOniVnPdTwa1tIYLcfDQJcQNe4/7mlbcSC4CvJ4Nx/GjGAhd9cDWggVZatZoYi7AL6Y3zGJ04O6b0JxGKnE/yZsUrLwljpmy1ptQJ5vnGhJAHxGnygypkqtpuTDeCJaPGIMHjuF9OURutp7oTzBE4g+sNHDuq7KshxNuwpq01Cih/TNnF6O1qAOrCtbbPgJKdci9V2LpcjiDyNF6ZNRXVO2GmE75Bc5Z2WZCNad/viaj LoDhcCbt fMIHl2yEvH79X4evzDw2toWf9LaCpSlMnVd20 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 luf mechanism that requires to use separated folio lists for its own handling during migration. Refactored migrate_pages_batch() so as to separate 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 e04b451c4289..6c22a1402923 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1584,6 +1584,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. @@ -1606,7 +1681,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); @@ -1765,42 +1840,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; @@ -1809,20 +1853,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; }