From patchwork Fri May 10 06:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13660941 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 63DF9C25B10 for ; Fri, 10 May 2024 06:52:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AAF36B00A3; Fri, 10 May 2024 02:52:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 808F46B00A0; Fri, 10 May 2024 02:52:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 633B26B00A2; Fri, 10 May 2024 02:52:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 367276B009F for ; Fri, 10 May 2024 02:52:29 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E1719121762 for ; Fri, 10 May 2024 06:52:28 +0000 (UTC) X-FDA: 82101567576.02.C7F70A2 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf10.hostedemail.com (Postfix) with ESMTP id 0AF8EC0011 for ; Fri, 10 May 2024 06:52:26 +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=1715323947; 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=u2mjUnFQvLeiyt0EIbd9RAlKFlEDSFVl1qIOuPU7u6k=; b=T+nc3CHeltgxJBrFyG5TAC6zsEGdXThFSvsZK2VpUG+0f7YZYSkGcH0zk9/OGNQRkh8s2o iYkUkL/nc6pvea2WXCKfGMunu+dIPMVGwgE3IE9VoY/+9PrNkVrzVZO97IiJ+GhUUBCCxx T8rwrpwJrSy+gQxZwVxUt0XuaR5GYUY= 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=1715323947; a=rsa-sha256; cv=none; b=WZm77+vSHOLUBBU7ei/O3CCLBZYxF625pFZOjrgZQsKWyUHDnWwftZGjnEyLqiS1OEQnD8 h4b3f/oufoSmkH90/c7BY6KSQmrc3zdNWYWSI7cRc+Qpbl2z2YsRHE/KAOWFijynqyK+1x adR7P070txjq1OGV/8CDJApoiSQv/cU= X-AuditID: a67dfc5b-d6dff70000001748-f1-663dc4215f8d 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 v10 10/12] mm: separate move/undo parts from migrate_pages_batch() Date: Fri, 10 May 2024 15:52:04 +0900 Message-Id: <20240510065206.76078-11-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240510065206.76078-1-byungchul@sk.com> References: <20240510065206.76078-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCLMWRmVeS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HvZKDH+31X2TwWv/jA5LH1l51H49RrbB6fN8kF8Edx2aSk 5mSWpRbp2yVwZWyZtJyl4Kd2xe17q1kbGKcrdzFyckgImEh0nJ/NAmKzCahL3LjxkxnEFhEw kzjY+ocdxGYWuMskcaCfDcQWFgiSOLz8OFMXIwcHi4CqRNP/IpAwL1D539ObmSBGykus3nAA bAwnUPzDshlgcSEBU4mOBxMZJzByLWBkWMUokplXlpuYmWOqV5ydUZmXWaGXnJ+7iREYxstq /0zcwfjlsvshRgEORiUe3h2bbdKEWBPLiitzDzFKcDArifBW1VinCfGmJFZWpRblxxeV5qQW H2KU5mBREuf1Ck9NEBJITyxJzU5NLUgtgskycXBKNTBKOWfcnmPxb/6zrp0OdqXrHZ9vUmg2 6GbZuoLdt/PNh2DHnDsFPj1Kp6bX3cu9e71uj/e60JeLUm6EWV8Ui3nvoqg4w2P9NIfjSTUp 2d3WXzaWejw/fFb5fFTZ35v6t59IxfKz/r7X4jSjUprB4d31iRW8q39YXT8Y4eajnTU3xOm/ oZX1HQUlluKMREMt5qLiRACpUG94XwIAAA== X-CFilter-Loop: Reflected X-Stat-Signature: 6667mu3nu1e3hey4wcxetar784qnhxb9 X-Rspamd-Queue-Id: 0AF8EC0011 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1715323946-972483 X-HE-Meta: U2FsdGVkX19eKci7tcZujEmT2CWW/0CmWGmlcYEg6bVnNWRVGdiMxYhysaldi0RA0AtayFkEdbcnRz6AZeue+ZL27MgN2PAvFKdT3vem7FsU7NmH3gX0wDi4IacUsMDhYB6rKkEQ5GxYlVcZLKZljBwMqZE+Q+Bi72hEOkP9Ve0vxkALmgvvkvpfQoBK6/bnlJTjWEqYACDsQmHTTcUOWfI56fxU02vshhvHsDpg5+lSgaNpLdJYcNzZmRr/gVjbrduJ64sxFZNsjma9nTUDNN20cbWPdZMmdyWNZxSdgJpukq9ZaI/ke++VDPfN36lyFxReEECs0ZjKBupeE7EMCUlEaQuf3ou2cKwiQ2eQTnASR+oeZml0QFDZmmWuRXxNimY+5hZFf+veHjFh4zKRAuuuTF6KUBHtL0/QsYTu6PTWM1oPrzBJgfUpKILz92zaDGRvnjOYFEciji/h/1C8ShS5xbDa/FThEIgMZ6wloSfCEXw1Eq0TGy3pBWAg9tKTqCk28EUvE4h7TVvIYleJEq5px/mT8eF1ov1BaPujoE8E375acZsVgfjBLQoT1NlADCy4H8ZijRssfGqjC5thx6exkeGKwtMvP/fNJaWag2ddYJcyheVdXA1VW0Jyve+kWGfcoUrP7dkgpigcg2Jsw2aFvm3m1w6cn1veFtOBqqUDnwI1gETWMBDANT3TkWe2l7zEY0cn0ZSMRNxDIKnCvtBF/P7GQzuJu3aWAnVB6jJ2y6HJk0nEPXKN29GsUnkdoXEy7gqJLWGbuWQet/MBNzs6sQxO9KmSUXLnV63quT71wtZOiP3rRPkwMNb763HpjQELVmFKKCcqRFR08w96PGr7zNgXj9L7S0k9eQSoagwERn4iHu9o4GhIe9kq4SiymZArOcYY6kaCacV26uo08LpcL81u7iu+AGSX//a5TAf/Y5Kg6+GDMN7Zr4S8GIzuVzjDLc/FuovjqCDCXhr plbIpdiH 9gQWaE9PdguorhcT4vEpYioTy21PK2NxbbNfT 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 c7692f303fa7..f9ed7a2b8720 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); @@ -1790,42 +1865,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; @@ -1834,20 +1878,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; }