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 56CA6C54E58 for ; Tue, 12 Mar 2024 08:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAE5E8D001B; Tue, 12 Mar 2024 04:05:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5CC78D0017; Tue, 12 Mar 2024 04:05:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B244A8D001B; Tue, 12 Mar 2024 04:05:30 -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 A302B8D0017 for ; Tue, 12 Mar 2024 04:05:30 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4B7F6A15BC for ; Tue, 12 Mar 2024 08:05:30 +0000 (UTC) X-FDA: 81887652420.21.F183853 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 8C7641A0006 for ; Tue, 12 Mar 2024 08:05:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710230728; 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; bh=3la+RgFRQCEZJDbO+LEbYTNiK8j89mtj/7odjb1o3Ts=; b=0xOg/EBm6gYqwB4IkVSAK97R4t6JdP/GS2j0Y1LIZunzb+TWwcgtyLVmQt59SrS0i/sGaO 2fuxwNczQUi0W0Giodbz7cwUJCl/AgbuRxm05cFiLzzr9s6kFjmp1iCktFRFSskb3wbBmQ QbBy/kcZSlXYiZDqcn4HqYlM5M82zm4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710230728; a=rsa-sha256; cv=none; b=iConN+3UEr66EYkWZg03ZQYTTb/+kO7k9ZNV3pqAAmvq91hKYmO7Dq/7YTIyG/pUaZohDb PTBUbiEpnNYeeagA7rUkG0Wge1JnKwwBk7sJC/x8Ljohy/GHiUOIedHoIwH6SmdeMCohZj 1RzpD0KMvZWOh5aKpEYUZnQsk4zzRFE= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82A041007; Tue, 12 Mar 2024 01:06:03 -0700 (PDT) Received: from [10.57.68.246] (unknown [10.57.68.246]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC8433F73F; Tue, 12 Mar 2024 01:05:24 -0700 (PDT) Message-ID: Date: Tue, 12 Mar 2024 08:05:23 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/migrate: put dest folio on deferred split list if source was there. Content-Language: en-GB To: Matthew Wilcox , Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , Yang Shi , Huang Ying , "Kirill A . Shutemov" , linux-kernel@vger.kernel.org References: <20240311195848.135067-1-zi.yan@sent.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8C7641A0006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: da45c6zzfc8hwu3h7iyo34rqd1ssjdg6 X-HE-Tag: 1710230727-264130 X-HE-Meta: U2FsdGVkX1/1qttOJ8wbXyrHVtSMItPply+RH6LGZFFoFRUnelMwLHqTQ6IMejk9q0vyd/aXBq5NruXKPW/sI33RtjhtTd/semSzygKK002zQSoIGMGO8AMPpix8rYWXU9Oi+m0LYE9yTt3jaIw77fuFdXVcBPXS9nBmZPozb44KW5SpecrCZohkrtZultOaeIHevZmDm5toCCd2mBEz8atc3BVjmPFDIcyUqGPc+DgkxGgSdHvwH6IQNx0IXtiZrIlLie6aqJRQ+Cw/ZmS39vAMFK8Inr9o/QbhoFPpI0rRT0XCQmfO9sJrrftLc5KqxcNgCU/JPMu9E19I18kboxpyNzvz07m695dktYuNW94d4hClFpQT6gRsp11iKGainAv7jy+3GoHL5bstMZqevakzBuX7De7fB7b/q/HibXNdZJUiLp9Io9n1cxFeR35AMyBsqtJK6BHJd2Y80WuYKDqcSSOvR29MlF+6e3ANgaA1Ax/gFFoyh/0jR64u8QSwiU/qmsm036im3+JKTTcEbxzuPNOdmEA3jIJ/VxVGeZuxY4BXqCek3lp0iPH0QP+zw5jjdlQ+kuSfy7BZiiip9RhXTy4Z3RPXZRqL5/FTryZrwZtxyMjxaTLp0t7FLaHR6T1MXmYY1ONkZxAxX2goKpnQ91qWIh4Qqm/CXbfPRPTc+J2pe0FflAZSuwkP50yCuCtoiezheH7NI9jvAa7bPrE7n4UcrEQgWisCaWxO4bWdUxT56aXp8CO5WXfrvq6YZpz7pg+IJ/IVrz9OEXTYDwY1779AvXpDclmTDpxulgCGc1raIELFgQnmCkgB9mM+YNfRhpUlabyduM6hET5ahCnJxULQRjzjIBsWQQUBtp5DIDfsgsed6zPh7KH0ccxeW8i7Sh2RJlmx/Mcd9S0E6JS693EH1fZHWGpyguPd0GzQOEwE0s7NHaKenXT+xze73BHPuO2dFPVpfE+9m06 Ft4qzlIt 0+Ej0kkblLzYUbHWbt9X8ETmp0YTebVczZPqv3kPRdC5T2FyTcv6Sqw97OD16zKR9QlxBj5zwshABiitW55nt2CG245TE8VLWfeDOz8qkX9hA0KEepCegmAj6UZ/2Zymh9Oh7QTbNX2l55zXXA3gVzJ1JOg== 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 12/03/2024 03:45, Matthew Wilcox wrote: > On Mon, Mar 11, 2024 at 03:58:48PM -0400, Zi Yan wrote: >> @@ -1168,6 +1172,17 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, >> folio_lock(src); >> } >> locked = true; >> + if (folio_test_large_rmappable(src) && I think you also need to check that the order > 1, now that we support order-1 pagecache folios? _deferred_list only exists if order > 1. >> + !list_empty(&src->_deferred_list)) { >> + struct deferred_split *ds_queue = get_deferred_split_queue(src); >> + >> + spin_lock(&ds_queue->split_queue_lock); >> + ds_queue->split_queue_len--; >> + list_del_init(&src->_deferred_list); >> + spin_unlock(&ds_queue->split_queue_lock); >> + old_page_state |= PAGE_WAS_ON_DEFERRED_LIST; >> + } > > I have a few problems with this ... > > Trivial: your whitespace is utterly broken. You can't use a single tab > for both indicating control flow change and for line-too-long. > > Slightly more important: You're checking list_empty outside the lock > (which is fine in order to avoid unnecessarily acquiring the lock), > but you need to re-check it inside the lock in case of a race. And you > didn't mark it as data_race(), so KMSAN will whinge. I've seen data_race() used around list_empty() without the lock held inconsistently (see deferred_split_folio()). What are the rules? Given that we are not doing a memory access here, I don't really understand why it is needed? list_empty() uses READ_ONCE() which I thought would be sufficient? (I've just added a similar lockless check in my swap-out series - will add data_race() if needed, but previously concluded it's not). > > Much more important: You're doing this with a positive refcount, which > breaks the (undocumented) logic in deferred_split_scan() that a folio > with a positive refcount will not be removed from the list. > > Maximally important: Wer shouldn't be doing any of this! This folio is > on the deferred split list. We shouldn't be migrating it as a single > entity; we should be splitting it now that we're in a context where we > can do the right thing and split it. Documentation/mm/transhuge.rst > is clear that we don't split it straight away due to locking context. > Splitting it on migration is clearly the right thing to do. > > If splitting fails, we should just fail the migration; splitting fails > due to excess references, and if the source folio has excess references, > then migration would fail too. This comment makes me wonder what we do in split_huge_page_to_list_to_order() if the target order is greater than 1 and the input folio is on the deferred split list. Looks like we currently just remove it from the deferred list. Is there a case for putting any output folios that are still partially mapped back on the deferred list, or splitting them to a lower order such that all output folios are fully mapped, and all unmapped portions are freed?