From mboxrd@z Thu Jan 1 00:00:00 1970 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 06809C54E67 for ; Tue, 26 Mar 2024 15:17:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78E296B00A0; Tue, 26 Mar 2024 11:17:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73E796B00A3; Tue, 26 Mar 2024 11:17:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62D2A6B00A4; Tue, 26 Mar 2024 11:17:25 -0400 (EDT) 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 542B06B00A0 for ; Tue, 26 Mar 2024 11:17:25 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 051CDC041E for ; Tue, 26 Mar 2024 15:17:24 +0000 (UTC) X-FDA: 81939544050.14.4D25BA0 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf06.hostedemail.com (Postfix) with ESMTP id E14B3180019 for ; Tue, 26 Mar 2024 15:17:20 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RAcQN9+Y; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711466242; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LJQmTQE2BThbacVB/qSQ5Zu1gkc4s6kLgcT1epLF09k=; b=xBSPykpMEAwK7ncAZGzsN6arNdQ95oBXyfKqp3Rv5KuIYuX0iG8KrLxy1UpbwLjIB3AX4C dTolmjUUv7l6OmgbO8Inz0/RCgxj1qHFZG28s+ROgIp7STS46gLlcbJJFhMmH73YNUYIP1 sBxkLlKeHYp9yOIksDK84CdN7asVEYE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711466242; a=rsa-sha256; cv=none; b=qL5OOCBc3EV4j5fCG/d9w0aqUcZbXkrq/9zjS3mCZpGRlyjSKAp6oBveJpbtcDX8l3WOjw NXDnG6A/oNV1yE853YYZAmi/hno8Z2E34zyfWpYV28t50pDCQiU9rkyL93aU/3/7bXa3uO jT1A3iab6bhAcLryvIE1qoAWjfuJ2rY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=RAcQN9+Y; spf=pass (imf06.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1711466235; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=LJQmTQE2BThbacVB/qSQ5Zu1gkc4s6kLgcT1epLF09k=; b=RAcQN9+YwgY9Vm8ZJWsp7LM9ixpQNQf5q0VmBJtMdfWRSDKPRH/SNihRKbldWAMEKwqViARm5neySplgczr0CD/KBgKfb+psZoC3qWMbrMy45DVimoGI23wljRTVjxSNFEiiOSWFj3QjUwDiGr8bcrSB8Og97LYjBk6NRPBaoTc= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W3Lj8Lz_1711466233; Received: from 192.168.0.106(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W3Lj8Lz_1711466233) by smtp.aliyun-inc.com; Tue, 26 Mar 2024 23:17:14 +0800 Message-ID: Date: Tue, 26 Mar 2024 23:17:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6] mm/migrate: split source folio if it is on deferred split list To: Zi Yan , linux-mm@kvack.org Cc: Andrew Morton , "Matthew Wilcox (Oracle)" , Yang Shi , Huang Ying , "Kirill A . Shutemov" , Ryan Roberts , "Yin, Fengwei" , SeongJae Park , linux-kernel@vger.kernel.org References: <20240326150031.569387-1-zi.yan@sent.com> From: Baolin Wang In-Reply-To: <20240326150031.569387-1-zi.yan@sent.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: E14B3180019 X-Rspam-User: X-Stat-Signature: gbhs5ubigz3dt3z3qyzegped1pukign5 X-Rspamd-Server: rspam03 X-HE-Tag: 1711466240-683880 X-HE-Meta: U2FsdGVkX1/0ngaIV/14ZFu3O51Nve5nLewhU3Yj/6QjNKN/gR7HOM6+RSS6HxYZ9Wxf6xUI+9Z4SGPHQrI3IcNCVZH3i5uVAIK7D9s36GWMnMVptbZ4MFQNifwuBL9d93/8AdLAy5cS9bEE1R8E2Hq7HTRZKfwEVGUPYMRAXq5cxyDbkrf2I4MblzD5bLiwH1sH3XN+EnhP4GU/cKxwY0wCyPS1vFBqTefuZyqpcBVBQ+bMBCP0gWvakWLu1+z/YbetKDWJZu2U8iC7dbgT1cqz2XZGwUmrNbz7lqh7EtJQE1wLoa3kmun7v9SeNhc0SCSwHqlJSmGMbeGaK4bVq3cu627WMD6cw7iBGiA0vl6+Sx3FlO9t4uTyYxwHdM9ThuPO6T+nvozzbLly9P8KSIGyNWAgjdkT8fsQVXks4vJt/JEmzyrjExcOkUvJEI9nmGwwviATHSNj31RPMZqEd7xx/3dqLiE7KL6nE43iigQ7uC4tfAINuQa510hOW8GlIUNu+/VkY/+TKHjHgeg2acUAGyyt5LhfKnTuTYtrQr26N1XKADYiRgMvay0t6CkJctzlaPDioaMhDKZYtu5LX6Gw3dAgoRVpQ9YSgyTVqAVI+ENS9XECxr2yDFawEfPUJXxstOq8KwwQNBeJtxb19wS4EfEOccEDMHT60HZL3WlbU2jjoyYlnsT3/cN8NRGcj77WWyBVowCvGFyu1lPv0LQwvjUGx+IuRnCS45wQvg1ppafdZwpUAEloY6aNPXxveW3PYnpluAqQ746vKzHWFvqJV1V7W0QF9EuoinHT+r64G/xSg4yAxtHyIURgbrPmBhNVI3KxayDuDlzSjzjG0CbldCRTNVMCLT/N6YyKGEa1f4uKZB4TYqUxFb4rrT97ezP0/njIZjOCrKav258HDiacr0BfvzBo 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: On 2024/3/26 23:00, Zi Yan wrote: > 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 v5: > 1. Fixed an error in migrate_misplaced_folio() reported by Baolin Wang[3]. > > 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/ > [3]: https://lore.kernel.org/linux-mm/df9a644c-a007-46ac-98e3-61d4014fcfff@linux.alibaba.com/ > > Fixes: 616b8371539a ("mm: thp: enable thp migration in generic path") > Signed-off-by: Zi Yan LGTM. Feel free to add: Tested-by: Baolin Wang Reviewed-by: Baolin Wang > --- > mm/migrate.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 1dbe5bd927de..a31aa75d223d 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, split_folios) == 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