From patchwork Mon Jun 17 14:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13700849 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 280FCC2BA15 for ; Mon, 17 Jun 2024 14:39:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 573B16B01F8; Mon, 17 Jun 2024 10:39:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FBE86B01F9; Mon, 17 Jun 2024 10:39:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 328016B01FA; Mon, 17 Jun 2024 10:39:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1235E6B01F8 for ; Mon, 17 Jun 2024 10:39:37 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 801C7A180B for ; Mon, 17 Jun 2024 14:39:36 +0000 (UTC) X-FDA: 82240639152.06.4EF66D0 Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151]) by imf15.hostedemail.com (Postfix) with ESMTP id 41084A001C for ; Mon, 17 Jun 2024 14:39:32 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=SwoQeyQD; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=RfrE+bpW; spf=pass (imf15.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.151 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=1718635171; 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=YTcVxGJJSitBHmI81csUD7sOdb3OERyqcoYJY7uvHYk=; b=Epyc1PgUvFf7+73ahlzU1KxSyzq16xDEntyuJSMRwAoJqvXFvoxouw4/2F5ISZOD3wlb4u zVh4NohLnAcC7/hWKDWWvT4DBe9ko4wi8ltezDiEp/i4OZl4HSF1us1zWJIC2aZBtV7Jjt kLu3C6LDbm5Z0aHLUao7nmqhMcVk+OM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b=SwoQeyQD; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=RfrE+bpW; spf=pass (imf15.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.151 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=1718635171; a=rsa-sha256; cv=none; b=SewWHBJR8veR5QjYz/y2rYHVx1cRcFv13sGAisMSSF8ewrk7Ik/1yjgxrHCysCUXG4yMlW 3hNpoyZACdL+MsLOyhrsV4EB7F9arVguLNcdu40Xt0TL5IbUk8ncr4LLeBUxXqYVf5T7uz MYdNZW6j2ktObPBmgcnmasxvyRsjOsI= Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.west.internal (Postfix) with ESMTP id B53E31C00067; Mon, 17 Jun 2024 10:39:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 17 Jun 2024 10:39:31 -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:subject :subject:to:to; s=fm1; t=1718635170; x=1718721570; bh=YTcVxGJJSi tBHmI81csUD7sOdb3OERyqcoYJY7uvHYk=; b=SwoQeyQD79h0J0zshDT6H5OPdO 8i2aO3luQk1ijzRDHHZFe04KOiSxfomStah3hZZEv5lANnsX7BLBJrgyYKhzf0P9 dZCsa4IL6dFy3jZP7vd8pUFsPoI1cYS1tTbiXWpYoVXxXcee8Nbc/08rM290LFN7 F9dFwXSPOxWAF/7g1EpNwPjKbbmV9DUf+xexxN8sVhU3gb2XN1mKxSSTO0JzKjcg /zIFOA4BU+cyytieWov0Rm5DleLitafnEH2+2ZSXTr9rM53cW8Gz8N7Z1UBwDAcR sH5cxP8po9wJcWpAWoBFHUkR+8RxJM8b6X7TpOKSXQb7ot96PAERXU9R4E9Q== 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:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1718635170; x=1718721570; bh=YTcVxGJJSitBH mI81csUD7sOdb3OERyqcoYJY7uvHYk=; b=RfrE+bpWFhIRKjaGeNT1S2KQjzRs+ xdifj1Z3+ekeqXh6br9x6VMq1A8zBijVlqf5CIbS3hhGahKURIDB36oDRpXWOmTn sOKlgiEb+xY8MbT5MfhgSqHxx7hm2c+uwmupfJ+AxPnok25cCskaZKwHEhchM7hK A/mnhNwfCYivmWlFOBcZWrNwRZZSNZEiXc7AcTqp5a+zOEkUmBQorGi7UkqMRHtO CY/ErRaU0e7x1ey6aqAKe87JgMvfWurkYHEycFhSitjarP2DTtTE2azCPOxxbeuk 3TqgXE5tsu6iAB8kSUCQqDMAu3ATXvkVJt8YNR/tPP4geDrwpX0Yh4OLQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofhrggfgsedtkeertdertddtnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeeigeffgf egkeetudelueejveefieeuieffheduteetudeuffejkeffhfettdeihfenucffohhmrghi nhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Jun 2024 10:39:29 -0400 (EDT) From: Zi Yan To: Andrew Morton , Hugh Dickins , "Huang, Ying" , linux-mm@kvack.org Cc: Zi Yan , oe-lkp@lists.linux.dev, lkp@intel.com, kernel test robot , "Matthew Wilcox (Oracle)" , Yang Shi , David Hildenbrand , Yin Fengwei , linux-kernel@vger.kernel.org Subject: [PATCH] mm/migrate: fix BUG_ON in migrate_misplaced_folio() and compact_zone() Date: Mon, 17 Jun 2024 10:39:25 -0400 Message-ID: <20240617143926.1511227-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 41084A001C X-Stat-Signature: sbqnto8jwwtmcfzeh4n4ngip71e1149f X-HE-Tag: 1718635172-496113 X-HE-Meta: U2FsdGVkX19+k9kr6JXEnVLKVaK0pqzmZH5g2axIXuoqAqqQTP7W7j0vmgGRG5j04QIyk9WwQnGaoLV9ta/uj84n37cx0ab7Me1ndBLHIK1UCbsygEdVeFR+zNYSLKfWivZSknYe27e/1Z/nigp1JYGGY+p0KOXwOUTbwm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btgjXirYY5a9ncbiLs/HXzjQqOgOZC/b+W2y1V4C31hcrK6d5ZLM/IHmmSbw49lijWfHr1zx3Sfao3/6zEuVUMe5A2rkhIEBKCVem6/cpXg+dzqh08KkunZiVveSN8m2tDB/YznqpZtVd0o0FHLYlPTROpWn8qjfVr7y35XQ13kfMOMH2UUWtBPzp2Ptd3LcxLwKx6p+VgQHZZWK1TDVuE4SnwuJE4BQYHRa4V0LvwGUPO9JTefngVlRDQ+a9XI3++SNHDavC4AAMU9Tw9QXT6J0rtT2+FPWBW00mFfbcEA1CRHchR28s6ujVCP32kvUZsZKM0ZPjSNXDqVWgAivUPlzLfaI1QQmSKgRmCZlyDJhfbV+2ZuG 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: From: Zi Yan Both Hugh Dickins and kernel test bot hit an issue that migrate_pages() reports success but still leaves unmigrated pages on from list. It triggers BUG_ON in migrate_misplaced_folio() and compact_zone(). Our convention is that if migrate_pages() reports complete success (0), then the migratepages list will be empty; but if it reports an error or some pages remaining, then its caller must putback_movable_pages(). There's a new case in which migrate_pages() has been reporting complete success, but returning with pages left on the migratepages list: when migrate_pages_batch() successfully split a folio on the deferred list, but then the "Failure isn't counted" call does not dispose of them all. Since that block is expecting the large folio to have been counted as 1 failure already, and since the return code is later adjusted to success whenever the returned list is found empty, the simple way to fix this safely is to count splitting the deferred folio as "a failure". This patch is based on Hugh's fix and suggestions from Huang, Ying. [Hugh's version] Link: https://lore.kernel.org/linux-mm/46c948b4-4dd8-6e03-4c7b-ce4e81cfa536@google.com/ [Additional stats change suggested by Huang, Ying] Link: https://lore.kernel.org/linux-mm/87msnq7key.fsf@yhuang6-desk2.ccr.corp.intel.com/ Suggested-by: "Huang, Ying" Fixes: 7262f208ca68 ("mm/migrate: split source folio if it is on deferred split list") Reported-by: Hugh Dickins Closes: https://lore.kernel.org/linux-mm/46c948b4-4dd8-6e03-4c7b-ce4e81cfa536@google.com/ Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202406171436.a30c129-oliver.sang@intel.com Signed-off-by: Zi Yan --- mm/migrate.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) base-commit: 6ba59ff4227927d3a8530fc2973b80e94b54d58f diff --git a/mm/migrate.c b/mm/migrate.c index dd04f578c19c..30f9a61598ea 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1654,7 +1654,16 @@ static int migrate_pages_batch(struct list_head *from, /* * The rare folio on the deferred split list should - * be split now. It should not count as a failure. + * be split now. It should not count as a failure: + * but increment nr_failed, because, without + * doing so, migrate_pages() may report success with + * (split but unmigrated) pages still on its fromlist; + * whereas it always reports success when its fromlist + * is empty. stats->nr_thp_failed should be increased + * too, otherwise stats inconsistency will happen when + * migrate_pages_batch is called via migrate_pages() + * with MIGRATE_SYNC and MIGRATE_ASYNC. + * * Only check it without removing it from the list. * Since the folio can be on deferred_split_scan() * local list and removing it can cause the local list @@ -1669,6 +1678,8 @@ static int migrate_pages_batch(struct list_head *from, if (nr_pages > 2 && !list_empty(&folio->_deferred_list)) { if (try_split_folio(folio, split_folios) == 0) { + nr_failed++; + stats->nr_thp_failed += is_thp; stats->nr_thp_split += is_thp; stats->nr_split++; continue;