From patchwork Tue Oct 17 16:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13425619 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 2E57BCDB474 for ; Tue, 17 Oct 2023 16:31:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 938C780042; Tue, 17 Oct 2023 12:31:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E75C8003F; Tue, 17 Oct 2023 12:31:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AEE580042; Tue, 17 Oct 2023 12:31:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6C9358003F for ; Tue, 17 Oct 2023 12:31:42 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 479231602E8 for ; Tue, 17 Oct 2023 16:31:42 +0000 (UTC) X-FDA: 81355494444.11.6CD7E3A Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by imf04.hostedemail.com (Postfix) with ESMTP id 0BBB840004 for ; Tue, 17 Oct 2023 16:31:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=3yJnaArN; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=unfNfFs2; spf=pass (imf04.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.24 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=1697560300; 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=0wvr21T8TH7ZbDsGZ1CdyvPwondpshaJK0kYT+cScfw=; b=EGkZ68o+25kKl5B+g2ofdDqFHEPGUd1dL8KmYVdqrKJhDeqIKXzOMIkcfF6CyKJeljhIAf UJA0Zs69Eim2SXMwkrGn1b59r2B6wAyhCBH0oRsZ/4mIKyufyREQ02unKflz+akG0+DbhG mUx8lEhBL27kqN7isUTWLSr3Q3E781M= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=3yJnaArN; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=unfNfFs2; spf=pass (imf04.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.24 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697560300; a=rsa-sha256; cv=none; b=SMrrHQfIDVXoU4sZlxekbwLEu1jD86zdBJjcj5/a4yyuqTccGqCvoTvydtoftW+++xclZC rNgv3EPP5Da4NzinusOtRS8CcdjzAp1RiPKSi9xceJq2AQMsGMsaMOelT2QyZnm3tDcj95 0fGBdkqEGEoQKA7xM4w2KfTWPArbDkg= Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id C0EFA320097F; Tue, 17 Oct 2023 12:31:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 17 Oct 2023 12:31:38 -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=1697560297; x=1697646697; bh=0w vr21T8TH7ZbDsGZ1CdyvPwondpshaJK0kYT+cScfw=; b=3yJnaArN4SOYAmO1fp K+rmCwdS25C4YRLbYb0xacBS/armI4TMiZSw+anRkphttaPnf81i/MUhL4bTV55z ravLE/h5yQ4iGHaa9q+lHzdu2UTcYuwOa32+huyKdw2QNSGWNr8o8KqCwbnbQLxE WDZFZsAAqo+2HbVXG7gsU8kKCxbgtuz298uj2xt0bbycxccYD7NyZFOAsPRqDawn Z6HlnGXzLQSwHv7rPotAhmldY4xVBkO3EzXyUvtYzWJPHtl497Z9PatJ1yJ3nY3J ubAJCG0ZFs1uHMiVak5L3GNe/sxDWg7xocktRhJJFZvNRUJHnUpSEAJ7q69xnCDx 6xyQ== 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=1697560297; x=1697646697; bh=0 wvr21T8TH7ZbDsGZ1CdyvPwondpshaJK0kYT+cScfw=; b=unfNfFs2TOOscLvAF rtISXudCcuRuLCPnvkyTpJifO7QIISSb3fmEx9IHVybsZWcTf+QCy1nfKYraT5uP 5sY0vQQytBofwThnmDC1UHIE2JCAHDIh1zxN6bWP9zwDhlqHEN/mwy+gSfyeYPM1 zUEyKLpE7axpayZRP8cwKcUauSPCm/XR9NGvmH3E45hoZ3k1IK8ecXr+oRN18A0d Ia+cr/9I8OcTqW/pdRNBS7pwUihug/MyG94NZLIeW774ls2gIH92rUi9LKZNqy9Q 0u4rqE+jFZKvLndXMnAUGVNHe/+14vPmt3jOBh8OFrCsnoBBFgFBkDx3cFa8q1bd kId/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjedvgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkfforhgggfestdekredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepffejueeife ejudejudfgiedtfeeltdfgueffhfdulefgtdekteekfeejheekhedtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvghnth drtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 17 Oct 2023 12:31:36 -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 v3 1/2] mm/migrate: correct nr_failed in migrate_pages_sync() Date: Tue, 17 Oct 2023 12:31:28 -0400 Message-ID: <20231017163129.2025214-1-zi.yan@sent.com> X-Mailer: git-send-email 2.42.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 0BBB840004 X-Rspam-User: X-Stat-Signature: e8rsih9an13k8wmpcxgx4t8tenm1p3d8 X-Rspamd-Server: rspam01 X-HE-Tag: 1697560299-386059 X-HE-Meta: U2FsdGVkX18CkRFPGNhK+Ec8wdO1PZ+5dA2JNnZVRYweaqVRA2i6Us/VugJ9GkSmkksWjlf7PmD+RPLhzW4tYR9vvznt3kLOz1NBZv4WSwn/P2osKEEbln2cAevT4zQK7Bo5COY3hxv8y1cd2SeWXtmZxBRHdsYTla59+iiIQiSVao+bHVyWdI1Gb0j9Q2QRsw9+XHSIDnHoYDKqgdt21epxb0DU1qqLbe3viMuGtAGhgMJf3U4yAmznwR/Sfvp0KJTZyibay0e2qZJABEmH0Lo84cza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w6PPIQ62voIITels3EBIbEJqIfRTjj4GKdEO0AsNXVUulOh+PXRi81IgDjVoWtDhCd8wMlmg/+m3D4x9mQ4vFLkeE1KRp5GdkxxjO7jEuZ478Ha9i1+l6ZoCBLBB0bv2ZnUA3MRcUaavGx3+pQRrSYk/uyV5WvwGUGvZrlY5qTXDjwuU1DbjHNYuEeO+o7g3C3kM1xES+ioyAZJbeLZCoYvIrBYjW6MKRpTCZUyMzNRUY= 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 Cc: Baolin Wang Cc: David Hildenbrand Cc: Huang Ying Cc: Matthew Wilcox Reviewed-by: "Huang, Ying" Reviewed-by: Baolin Wang --- mm/migrate.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c602bf6dec97..fc2e70b17704 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 += is_large; 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,11 @@ 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; + /* + * Do not count rc, as pages will be retried below. + * Count nr_split only, since it includes nr_thp_split. + */ + nr_failed += astats.nr_split; /* * Fall back to migrate all failed folios one by one synchronously. All * failed folios except split THPs will be retried, so their failure