Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1363571lqp; Fri, 22 Mar 2024 12:33:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXeUivVVcmCpqfMPI4H8eYlzbWnlcaJMh08/sPqDo7BId8qc+NerEoU4Ts5eCC4uA/5pkKIxJ8xhm2eRjgco7K6r4R/OUOVqCjRacjBMw== X-Google-Smtp-Source: AGHT+IFvAn5qHsv0D/iUyI6Mm6tlIu1qU/v+FbZdhy6YZrIpkOrmD4tKeyJR+abQvVxOQ9k2G/XV X-Received: by 2002:a05:6a00:2301:b0:6e6:cf11:a7cf with SMTP id h1-20020a056a00230100b006e6cf11a7cfmr839544pfh.25.1711136009124; Fri, 22 Mar 2024 12:33:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711136009; cv=pass; d=google.com; s=arc-20160816; b=h8iGLgOfOqWQ6Nu8XfbkxXfD6bqhIZex5gUifjx11PSPe2Q59EW8qOW5z4bm62t06+ Qm/+vYLBrah0SS92gSVOH63qcQILIPMqAnM4OFx+PtpFIxZwwt8R8W+1eHYBhgtAGimc eoavsu77VCWt4uaP5tODT1339slutMupCDvZgiWHJsKA8MIiEsUtdOGI+Buk/G32tN/o cJ38w8sMoT5HH6UJ2EqsSsvDytQO93B9bdt2f9CdX37FfrGBSmUqTIybBwqIP+tamC9U mHzdTrFq0J9AHSHnP4KgnBew79TFIYZE0ukKnNzMcWW27GJGmbCKDXeDBgEug5ibQ36r FGgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:message-id:date:subject :cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=Z4qwXiUVtIySYeeeDHMpOYt0KW6NAQHnh4gQJgkXoJ4=; fh=0SnJ87RJni787+3mD8GPeuSJMeVnrb05uDR0gj1ch8Y=; b=lB59lE45s/WZm1F/s7kjCLfeq4wIuYQFAov3Z5uxpx5SQAp8AR645IhcPBlhvlGBEb n8DZJeNfYBeCpowR2bHkfor4Q+Wyydq8lgddGCR32d54nDKdaZBb/7O1T3O9nYxUsWX8 FzN981cJy+JQnFAgTjjiqYfnBWUj0y1XUVObbgSdTrqHr7C+3sDOSyGAiGChzo4vhsNI CkKBgirjCS2UrBNlImEjvfHYXIJdlxgfFx+U8++pIX8PprV00LNcKBZ6dMpjf195/MyT 7O2uE07iWiKd9HA3slmvJATp7rkkZOD6yXpKliXaOaK9kh6tuHTv4Rcsu79PJMC+79sv ukaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=JjKgd0LD; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=FgVjeW9o; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-111999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h13-20020a056a00000d00b006ea92adbb9csi194188pfk.169.2024.03.22.12.33.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 12:33:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=JjKgd0LD; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=FgVjeW9o; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-111999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 31AC2B2220A for ; Fri, 22 Mar 2024 19:33:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4E0F7AE51; Fri, 22 Mar 2024 19:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="JjKgd0LD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FgVjeW9o" Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02EA37AE44 for ; Fri, 22 Mar 2024 19:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711136000; cv=none; b=U9e+pvwxAaMJ4n9p9JESpCbmbqSe0/1EnaHiV1abNU1Y4PWHyvB4OcNEsImnTB5ZKWJQga9tAiEFKcvrGWS0dgpSFnHYWs21JQpxj6+YRfTlK52Yo5NmiOSVkDvNhsYvw6fgwhi4XejBe5d9cEIzNv7Wo63q2pCpNVRF7YQ9Fig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711136000; c=relaxed/simple; bh=6aXe99vy9NwkLcaUAxwc/CBOxXdrV4VqdlEFRv/Uuoo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=HlMLYmVcEpONmEN5YlKP+HOoKJGG8uEcilP1/wT4LH6YA+3gBaBihLz6ac7Y0cQc/lVNTVmDH91aKYtwhOrgl6KiKvfgOOoqUEFZLo7LepA3gLWwrLW9YhlGLHcUTfsTiO0b5O/w2fsbaybFairYFtvgJQwgYRlfcQip+OOaMHw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com; spf=pass smtp.mailfrom=sent.com; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b=JjKgd0LD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FgVjeW9o; arc=none smtp.client-ip=103.168.172.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sent.com Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id D261C13800C8; Fri, 22 Mar 2024 15:33:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 22 Mar 2024 15:33:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:message-id:mime-version:reply-to :reply-to:subject:subject:to:to; s=fm2; t=1711135996; x= 1711222396; bh=Z4qwXiUVtIySYeeeDHMpOYt0KW6NAQHnh4gQJgkXoJ4=; b=J jKgd0LDJusRF0knrNa/Y3vIZsqA0w4UKM57xw1itDNsuPwP6aPkIFBrl7zrN7il4 bNqLYIutwLOFKI8x7Z2EVdRDCXvqszrdQXGpUVWZ6Iv8YlGoPUzT1sKnrXJ9KaCj P7xoO+4KFQRE8QfWfptIi+uFGoXs6HCqYO+iL5kBZoThkCK+JYlI/3a4V70zYoyl PNIfqjrGonZNaaSulKPstQXQ0kqlKk9qUV7ao8E/1qHHKdFooQbyobSKo2d2RGwT YlhMGPd6YGLCvLGgvCnU/XzaaKALJLmjjDnu6YSX2E4bxiPJNIDQ9y0ohhU5yKgr ZTl9Nobi4OpJZPh8lBk2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=fm2; t=1711135996; x=1711222396; bh=Z 4qwXiUVtIySYeeeDHMpOYt0KW6NAQHnh4gQJgkXoJ4=; b=FgVjeW9osSLt3u5fV U6dMfnZUjQK+MnEXnWIY45U5l8YS29AcPodXP4MYaLWP8CVZLqDuteQoGN/+MbIA MkQy5yj7FDEKPB/ZXjekF4JOSLp/b6BRbaHY954hleESgi8exrQdLUvTDBrlLp9F RFixnQTy3RkYjUMz5WIev1vLCMHtvAUyKuzayP44l5r3zvEtQ2tfY8xhFBSItMkV fsnu3VCOV7c1ZZYqLMiTBfGM3ilqXSWaVvvFOV6wm40REDF2Nr18VHvd8VeR+ihA ZulIXqjVdExBpdXcVrA50n49XB9EaBl/fqmHAnznBINyaSP3xKdv2uuDsk9H3+O/ PA3wA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtvddgiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofhrgggtgfesthekredtredtjeenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepteduve ehteehheeiteeihfejveejledtgfdvieeuiedutefftdevtdfhteevtdffnecuffhomhgr ihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 15:33:15 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Zi Yan , Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Huang Ying , "Kirill A . Shutemov" , Ryan Roberts , Baolin Wang , "Yin, Fengwei" , SeongJae Park , linux-kernel@vger.kernel.org Subject: [PATCH v5] mm/migrate: split source folio if it is on deferred split list Date: Fri, 22 Mar 2024 15:33:04 -0400 Message-ID: <20240322193304.522496-1-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 Reply-To: Zi Yan Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit From: Zi Yan If the source folio is on deferred split list, it is likely some subpages are not used. Split it before migration to avoid migrating unused subpages. Commit 616b8371539a6 ("mm: thp: enable thp migration in generic path") did not check if a THP is on deferred split list before migration, thus, the destination THP is never put on deferred split list even if the source THP might be. The opportunity of reclaiming free pages in a partially mapped THP during deferred list scanning is lost, but no other harmful consequence is present[1]. From v4: 1. Simplify _deferred_list check without locking and do not count as migration failures. (per Matthew Wilcox) From v3: 1. Guarded deferred list code behind CONFIG_TRANSPARENT_HUGEPAGE to avoid compilation error (per SeongJae Park). From v2: 1. Split the source folio instead of migrating it (per Matthew Wilcox)[2]. From v1: 1. Used dst to get correct deferred split list after migration (per Ryan Roberts). [1]: https://lore.kernel.org/linux-mm/03CE3A00-917C-48CC-8E1C-6A98713C817C@nvidia.com/ [2]: https://lore.kernel.org/linux-mm/Ze_P6xagdTbcu1Kz@casper.infradead.org/ Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path") Signed-off-by: Zi Yan --- mm/migrate.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index ab9856f5931b..6bd9319624a3 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1652,6 +1652,29 @@ static int migrate_pages_batch(struct list_head *from, cond_resched(); + /* + * The rare folio on the deferred split list should + * be split now. It should not count as a failure. + * 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 + * corruption. Folio split process below can handle it + * with the help of folio_ref_freeze(). + * + * nr_pages > 2 is needed to avoid checking order-1 + * page cache folios. They exist, in contrast to + * non-existent order-1 anonymous folios, and do not + * use _deferred_list. + */ + if (nr_pages > 2 && + !list_empty(&folio->_deferred_list)) { + if (try_split_folio(folio, from) == 0) { + stats->nr_thp_split += is_thp; + stats->nr_split++; + continue; + } + } + /* * Large folio migration might be unsupported or * the allocation might be failed so we should retry base-commit: 08a487ab26d541a3bd0adaee144f684b724d233b -- 2.43.0