From patchwork Thu Feb 8 06:26:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13549358 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 7CC60C4828F for ; Thu, 8 Feb 2024 06:26:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EE1E6B009E; Thu, 8 Feb 2024 01:26:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5775E6B009F; Thu, 8 Feb 2024 01:26:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 415206B00A2; Thu, 8 Feb 2024 01:26:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0C8B86B009E for ; Thu, 8 Feb 2024 01:26:29 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4986140282 for ; Thu, 8 Feb 2024 06:26:28 +0000 (UTC) X-FDA: 81767652456.13.9EDF435 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf02.hostedemail.com (Postfix) with ESMTP id E392B80024 for ; Thu, 8 Feb 2024 06:26:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.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=1707373587; 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=spqFjy3T0gpP0JlWZDv37LH7oDKTIyxcKtVFEpfUZ1FOC2BlIkrkMkN8GuWsoHEN4Sl9lu ZsyUxW6OMO7y57lgNMp+YqUXvdP687MCzLHXfQeX+X0vWJy6t4brNdwA4NwZAugiD80IUU b4PRSj8CMLHyrkB9T/Me1Q1Ip+v7ELk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf02.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=1707373587; a=rsa-sha256; cv=none; b=mMgQ9CJEQx0SQo/P66ywiZFLySuqUwLbgf+zBCVKGXQKPxRhJe0RpacpT9OHtgy5SMIvYP 4x9VRpD/3WSQUlJrY8jaJwpuLSYxN1wJGh7LM6lnzndZ1VdUjcmwHuzh0G3Co+N0ToW2hq tjTGj+kgd//WZK8GViodrgBHNNFkpJs= X-AuditID: a67dfc5b-d85ff70000001748-86-65c4740be438 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: [RESEND PATCH v7 5/8] mm: Separate move/undo doing on folio list from migrate_pages_batch() Date: Thu, 8 Feb 2024 15:26:05 +0900 Message-Id: <20240208062608.44351-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208062608.44351-1-byungchul@sk.com> References: <20240208062608.44351-1-byungchul@sk.com> X-Brightmail-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2sXjsnHWX3WPBplKPzSu0PBbv ecnksWlVJ5vHpk+T2D3enTvH7nFixm8Wj3knAz3e77vK5rH4xQcmj62/7Dwap15j8/i8Sc7j 3fy3bAECUVw2Kak5mWWpRfp2CVwZN97fZS/o16lYNOchewPjSuUuRk4OCQETibPz37GC2GwC 6hI3bvxkBrFFBMwkDrb+Ye9i5OJgFvjIJLH6ewcLSEJYIEXi6+lmNhCbRUBVYuu/24wgNq+A qcT7JyvZIYbKS6zecABsECfQoJ3bToEtEAKqeTF7MtsERq4FjAyrGEUy88pyEzNzTPWKszMq 8zIr9JLzczcxAsN7We2fiTsYv1x2P8QowMGoxMN7ovxwqhBrYllxZe4hRgkOZiURXrMdB1KF eFMSK6tSi/Lji0pzUosPMUpzsCiJ83qFpyYICaQnlqRmp6YWpBbBZJk4OKUaGPVl5+yQcXTs e6p7f5FPv0Xi/QeMy/bW2y032XDl8e5t2UKOfnN3+XmyCCltOL2rp4o5Q/bb/NLNGic+el44 zs23pmP7nMJPMfXn2WrMr75WnqzV/5WDZRrTz3vbDS8cPpZwfuMj7tpo0eosDtsUH639kdwm n0puic3iyj/ldXTihb9TlvfyuSqxFGckGmoxFxUnAgBFmRGYawIAAA== X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E392B80024 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5bn99bd14p99pmi3juope11t765999cg X-HE-Tag: 1707373586-784905 X-HE-Meta: U2FsdGVkX19lQTbQf98gEsuUXKD/2TnC/2ic/Y5NEJLssKJkR4FspuDJw3LdTmvh4Z7GlggmuW+v2ePiIjJG4Be5H8wSMR3jU1B9npktTbanAM39nA9dYCyp/M/e9e1vStdzO3cXL1J1OGI2xkfVVdqoSr5T4ocNPp0IKOVR5/UwhY861O+yUl8tnpvieOAtcWGhdugQR/2UpdOjS8KObYIHoid62K+ZQFPcGwfBC81+TT/LRTXRNohkTYPtJRgTebYgph7IE3Cu34bdB2pLTxNSWbo3P4idhJHny+4UhLaf8j395pun9Iprdv2Bk5/iWgCfdGemHtGh91TAxicbvo1FUka1WK0KYbN15Yy4Jhe1zp/UqTDQisSFzsuvn66Po+GLdnd+1NFSw8AmiWu1piB+DLTCBWiH5WVG1mAmpv92XyZsR7a4AWp4NFf3uvB/+ElKAbaonzZEVH5mabZzJE0CUrFi2CA4GdpN+a3bs369TbTufQUuEMTBKQ0EZlcWzjUQvuNLfQc+rnzGQPztXo4+I3TxYvFr89yyHMk5oc04ifOO9mFsxKVvRp7WlcO6Ux0AbvCtB9DSYHl4k6wNUfDOmRilpyiN7pdW5omWgbgVMr+yVgKMym3ej5Pk8DdXjwCy+4MzOhKFT7I3ms4Yx0mjUXC5bn50sg4+6sNGRJlCO6zDrfeZhFVPi6uErXwe2Lf/iJibioT0ImNY78I+9LtgZwtd46sq91CZEDdMbNbeoPzdiNsZWKP+7dK0+6PrlCrgZ9dpB4zrRJLt8FJzUxGiI5IGzCiGZEXCcHaXuepw/c+8MB3o3jdqm82+PPdfqRsCx3GLs1dgB1QVJceWUHjjyMs1sR2JXZfiT9IkdBmMKGMTPR70D8sThACHdBalKjElF93pIcTJQiZA8vzEcPqHuBmuG/FRPYRlOPR86CY3fz4i6XpyHQao1aHYJnBrBVAe02YWaIDKfFZBqyc 4wUiNf4+ 3z7J+6xAzVDS8Lx18Go65HeQ+gQB5QIQYzVhw 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; }