From patchwork Mon Oct 16 15:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13423602 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 2328DCDB465 for ; Mon, 16 Oct 2023 15:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FB3B8D00AA; Mon, 16 Oct 2023 11:42:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AB858D0001; Mon, 16 Oct 2023 11:42:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 799FA8D00AA; Mon, 16 Oct 2023 11:42:13 -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 6B1DB8D0001 for ; Mon, 16 Oct 2023 11:42:13 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2D56D1409FA for ; Mon, 16 Oct 2023 15:42:13 +0000 (UTC) X-FDA: 81351740946.04.EA9EDE9 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf26.hostedemail.com (Postfix) with ESMTP id F2AC0140019 for ; Mon, 16 Oct 2023 15:42:10 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=ao+hJIbV; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=LV6+i1vJ; spf=pass (imf26.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697470931; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=UemfV4Gp6AsBHDDvuajuUvalvcQkOw1ynNlnNSjNndE=; b=geZVUGjePOKlRtGvNGJcvCOd6vbXkU3cq3Rjyf+C3LeerRwFEM04zqjp6MLXQU+o81pbBX NLEnJPVv1NWsuKZJ1gXDrkmkgpYlCualDB5Ct49dK66H6cQxTmSUCoYDItgWKydu71uZyG zFLchNIAhiRUdKRXKMVkgS1SX7cBbJo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697470931; a=rsa-sha256; cv=none; b=u62lOCGsXExnn9e4ORbPePOUT4UKV47sE0UXu1Fnz4WKN1T4DgdZe/mdA4+txsdD+3rA7s okakgVC76LiJVFSAc1pv15Uk+2iCQrDvQ1NoVuVlUgPHSxVPH0ZRGtuccIRgARtXa38CyX 49mYb+vCjfpNjExI4lc8dssmC2aUfjM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=ao+hJIbV; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=LV6+i1vJ; spf=pass (imf26.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 28F2D5C02AE; Mon, 16 Oct 2023 11:42:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 16 Oct 2023 11:42:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:reply-to:sender :subject:subject:to:to; s=fm3; t=1697470930; x=1697557330; bh=Ue mfV4Gp6AsBHDDvuajuUvalvcQkOw1ynNlnNSjNndE=; b=ao+hJIbVMlCc80+xz1 DRb0PAtMUumDou9lEsn8CRT1G6I0BmztwUbPoD4L2YWNDxmWqknotRCGoRkpF4ny sryhoY3t/7imJJ0uC67mo44/1kmrWwCERxL7gYdwJkoXQZh2Y2cgi0yrsjDudXt5 dK49EOiCu1AsXiuv1rkcqZwKC4fFdeyxyinrrgVvMS1TN5HwYP5QUCLe3eT8+Gra Xhx8ue74igoAiNc7FyXMx0XCYDuQAyZ4VV9xhTd4UPoHhx4WzNWD/DczodFIjPsm /oZq+OH3Bcfp03Y2qqn4g7zUCKUQ27+395J7RoBKGu3gugy0D/jqe/b3WbTV3U3V Q2Rg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1697470930; x=1697557330; bh=U emfV4Gp6AsBHDDvuajuUvalvcQkOw1ynNlnNSjNndE=; b=LV6+i1vJKKFDJwS4U uus6PGhNnzg+DejED9ZlPibFMH0fAS6GSY2dElvzMpPo034PYRmwRLFbOMUJNzZi z3PQjtCeT5sujStIojMmv+I2sufJ1pfHGFep+5FkvgpcLeQYD/c0H+KeihQ9jYgr qn4z4QiC9Ua/WzCxJsnpPJ8tyfAGTVtkh07dM9NlzeeQYX7HlQ9GI7gXIPP4vknY YeOr/KsYtcWWYbNZT6n5Z0SxGy11Tvk1gRkqQ5ab140sHxgW+Q5rGIkdHj9IY1z7 VcCwh0hQ5vRgS/NlU2P5fbEQ+pn3tcB3tA2qGA5/xLs6VS0Za12ddh+s0M8BfvDB imT8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjedtgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnheptdfghfdtte eltdekiefhfeeuueehvdduhfdvieefvedtkedttefgieeijeeuhfdtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvghnth drtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 16 Oct 2023 11:42:09 -0400 (EDT) From: Zi Yan To: Huang Ying , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , Baolin Wang Subject: [PATCH v2] mm/migrate: correct nr_failed in migrate_pages_sync() Date: Mon, 16 Oct 2023 11:41:56 -0400 Message-ID: <20231016154156.1948815-1-zi.yan@sent.com> X-Mailer: git-send-email 2.42.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Stat-Signature: iztb47niapzxrwtbbyefo7kumtnx9kfq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F2AC0140019 X-Rspam-User: X-HE-Tag: 1697470930-279208 X-HE-Meta: U2FsdGVkX1//xRjZ5Uyv+G9HSqgvKWgYWnTp5EGnK+nQit9bydidDckNqvyByPRZKAdZiNEQayWVTk51ftABam8NyIkHNYvn1Etf+4gYoKIeRj0QUwGJdEl52ieVvzyulTaMrTqeaVllTtM98V5ya+OVmrdmxUlrcFb3CX9p28z8XciK24d1OXOl4AhDHzPwTE0F1ZCcgWdD6EGKHQHvpwntgDq7YuZIQmzLaD6rFqHyxHqN77R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ps+8s/ynPxLydQfEEfmSwjK19yhG5Vx7j46V16qmku30N4hIqEj6R9zdfuTbJGXt/H0B9A/DJOfyL498FHXOy0EH4z7593k+UvjHq6VSq0SsSm84UlxY 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: From: Zi Yan nr_failed was missing the large folio splits from migrate_pages_batch() and can cause a mismatch between migrate_pages() return value and the number of not migrated pages, i.e., when the return value of migrate_pages() is 0, there are still pages left in the from page list. It will happen when a non-PMD THP large folio fails to migrate due to -ENOMEM and is split successfully but not all the split pages are not migrated, migrate_pages_batch() would return non-zero, but astats.nr_thp_split = 0. nr_failed would be 0 and returned to the caller of migrate_pages(), but the not migrated pages are left in the from page list without being added back to LRU lists. Fix it by adding a new nr_split counter for large folio splits and adding it to nr_failed in migrate_page_sync() after migrate_pages_batch() is done. Fixes: 2ef7dbb26990 ("migrate_pages: try migrate in batch asynchronously firstly") Signed-off-by: Zi Yan --- include/trace/events/migrate.h | 24 ++++++++++++++---------- mm/migrate.c | 15 +++++++++++---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/trace/events/migrate.h b/include/trace/events/migrate.h index 061b5128f335..0190ef725b43 100644 --- a/include/trace/events/migrate.h +++ b/include/trace/events/migrate.h @@ -49,10 +49,11 @@ TRACE_EVENT(mm_migrate_pages, TP_PROTO(unsigned long succeeded, unsigned long failed, unsigned long thp_succeeded, unsigned long thp_failed, - unsigned long thp_split, enum migrate_mode mode, int reason), + unsigned long thp_split, unsigned long large_folio_split, + enum migrate_mode mode, int reason), TP_ARGS(succeeded, failed, thp_succeeded, thp_failed, - thp_split, mode, reason), + thp_split, large_folio_split, mode, reason), TP_STRUCT__entry( __field( unsigned long, succeeded) @@ -60,26 +61,29 @@ TRACE_EVENT(mm_migrate_pages, __field( unsigned long, thp_succeeded) __field( unsigned long, thp_failed) __field( unsigned long, thp_split) + __field( unsigned long, large_folio_split) __field( enum migrate_mode, mode) __field( int, reason) ), TP_fast_assign( - __entry->succeeded = succeeded; - __entry->failed = failed; - __entry->thp_succeeded = thp_succeeded; - __entry->thp_failed = thp_failed; - __entry->thp_split = thp_split; - __entry->mode = mode; - __entry->reason = reason; + __entry->succeeded = succeeded; + __entry->failed = failed; + __entry->thp_succeeded = thp_succeeded; + __entry->thp_failed = thp_failed; + __entry->thp_split = thp_split; + __entry->large_folio_split = large_folio_split; + __entry->mode = mode; + __entry->reason = reason; ), - TP_printk("nr_succeeded=%lu nr_failed=%lu nr_thp_succeeded=%lu nr_thp_failed=%lu nr_thp_split=%lu mode=%s reason=%s", + TP_printk("nr_succeeded=%lu nr_failed=%lu nr_thp_succeeded=%lu nr_thp_failed=%lu nr_thp_split=%lu nr_split=%lu mode=%s reason=%s", __entry->succeeded, __entry->failed, __entry->thp_succeeded, __entry->thp_failed, __entry->thp_split, + __entry->large_folio_split, __print_symbolic(__entry->mode, MIGRATE_MODE), __print_symbolic(__entry->reason, MIGRATE_REASON)) ); diff --git a/mm/migrate.c b/mm/migrate.c index c602bf6dec97..4caf405b6504 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1495,6 +1495,7 @@ struct migrate_pages_stats { int nr_thp_succeeded; /* THP migrated successfully */ int nr_thp_failed; /* THP failed to be migrated */ int nr_thp_split; /* THP split before migrating */ + int nr_split; /* Large folio (include THP) split before migrating */ }; /* @@ -1614,6 +1615,7 @@ static int migrate_pages_batch(struct list_head *from, int nr_retry_pages = 0; int pass = 0; bool is_thp = false; + bool is_large = false; struct folio *folio, *folio2, *dst = NULL, *dst2; int rc, rc_saved = 0, nr_pages; LIST_HEAD(unmap_folios); @@ -1629,7 +1631,8 @@ static int migrate_pages_batch(struct list_head *from, nr_retry_pages = 0; list_for_each_entry_safe(folio, folio2, from, lru) { - is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio); + is_large = folio_test_large(folio); + is_thp = is_large && folio_test_pmd_mappable(folio); nr_pages = folio_nr_pages(folio); cond_resched(); @@ -1649,6 +1652,7 @@ static int migrate_pages_batch(struct list_head *from, stats->nr_thp_failed++; if (!try_split_folio(folio, split_folios)) { stats->nr_thp_split++; + stats->nr_split++; continue; } stats->nr_failed_pages += nr_pages; @@ -1677,11 +1681,12 @@ static int migrate_pages_batch(struct list_head *from, nr_failed++; stats->nr_thp_failed += is_thp; /* Large folio NUMA faulting doesn't split to retry. */ - if (folio_test_large(folio) && !nosplit) { + if (is_large && !nosplit) { int ret = try_split_folio(folio, split_folios); if (!ret) { stats->nr_thp_split += is_thp; + stats->nr_split++; break; } else if (reason == MR_LONGTERM_PIN && ret == -EAGAIN) { @@ -1827,6 +1832,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio, stats->nr_succeeded += astats.nr_succeeded; stats->nr_thp_succeeded += astats.nr_thp_succeeded; stats->nr_thp_split += astats.nr_thp_split; + stats->nr_split += astats.nr_split; if (rc < 0) { stats->nr_failed_pages += astats.nr_failed_pages; stats->nr_thp_failed += astats.nr_thp_failed; @@ -1834,7 +1840,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio, return rc; } stats->nr_thp_failed += astats.nr_thp_split; - nr_failed += astats.nr_thp_split; + nr_failed += astats.nr_split + astats.nr_thp_split; /* * Fall back to migrate all failed folios one by one synchronously. All * failed folios except split THPs will be retried, so their failure @@ -1969,7 +1975,8 @@ int migrate_pages(struct list_head *from, new_folio_t get_new_folio, count_vm_events(THP_MIGRATION_SPLIT, stats.nr_thp_split); trace_mm_migrate_pages(stats.nr_succeeded, stats.nr_failed_pages, stats.nr_thp_succeeded, stats.nr_thp_failed, - stats.nr_thp_split, mode, reason); + stats.nr_thp_split, stats.nr_split, mode, + reason); if (ret_succeeded) *ret_succeeded = stats.nr_succeeded;