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 37968C30658 for ; Wed, 26 Jun 2024 07:24:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B946F6B0092; Wed, 26 Jun 2024 03:24:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4E946B0096; Wed, 26 Jun 2024 03:24:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E37A6B0095; Wed, 26 Jun 2024 03:24:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 807E16B0092 for ; Wed, 26 Jun 2024 03:24:55 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2F822A084F for ; Wed, 26 Jun 2024 07:24:55 +0000 (UTC) X-FDA: 82272202950.19.C5A643D Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 0BE8F1C0015; Wed, 26 Jun 2024 07:24:50 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719386672; 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=XKtNDL7axLo9LGY+7XnCq6wSJW+gQeeZ3uFhFZxqKyU=; b=7QRIsFp9iTsDpDXjPU8iGDKlSgEHf1o93sf9EMPw1Lj9xp+VzD4+6gBB+psqNbA+K7Psyz k92/06KmLJBTTQpvhxjCYUb4QKm0O6PSIchwUxU+CeilRZ0Ly1wnxplwDkTM4jPnwSiBgj MmNWXP6xy3DFCxJsPBjXY9luMHAL7Uo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719386672; a=rsa-sha256; cv=none; b=TJojozcAUUsF8BZ67iN2KrISyX7hod1wi7RF1C6w+BFiqo21mi/oK4SQuotJnTwPfDoN+i qlfGmbYOgtFov+DxOKWJWbTxamY+Wf2daA+Gyv0TxjUAJ5UXgh64QCHItSVIN5Tj4PrKPE S9OR8wr+b/UpVicgPfXJGPce3yzjCNw= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4W8Cps0cXgz1xt2P; Wed, 26 Jun 2024 15:23:17 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 89189140381; Wed, 26 Jun 2024 15:24:46 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Jun 2024 15:24:45 +0800 Message-ID: <318664cb-76e8-49df-b372-b671f4cc3451@huawei.com> Date: Wed, 26 Jun 2024 15:24:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH mm-unstable] mm: migrate: folio_ref_freeze() under xas_lock_irq() Content-Language: en-US To: Hugh Dickins CC: Andrew Morton , , Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Zi Yan , Jiaqi Yan , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador References: <07edaae7-ea5d-b6ae-3a10-f611946f9688@google.com> <3346dbd7-b6f6-c191-b9b2-070f2ae60567@google.com> From: Kefeng Wang In-Reply-To: <3346dbd7-b6f6-c191-b9b2-070f2ae60567@google.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0BE8F1C0015 X-Stat-Signature: j5czrfsu6ronn6c13g6bypgpd3pjfam7 X-Rspam-User: X-HE-Tag: 1719386690-138512 X-HE-Meta: U2FsdGVkX1+5iXyv06PXfm/PGCoi50ETHplI38qHBhDLH7rUQx1eaxKOqN16JGcfkg3/IZzGBgeS44hjCqvRcsJ7qmmhYJnT+xs1Ex0XNKidiyBK/dq0oUBTgMMR9hSVhUjuihafopZDyDooT8V9fQo/fkBfWoiEaruds4rXD4RiON5bjELUVpbson94WIVqUy2G65XeY7vnc86h2ELgWu7y24Ba8O0bUlD0DPfx04FfMAlTQkT65Tw9UbMHv9yrNkEEjQVbeKjtadX6AxLDlmMi0qGLMEBgQA11GUfX2+qMVrxOOys1DMdc8+hSnsFd/+mDSUMNqDPEnCtjtEQAJ2JaTwtuqlXrx7uuFpGbLPrSbpRDpunU+Zq+GQsaQJZwhOWwXObHX4n4pbuzJ5AKAK3YfhZNSGDtGLRFa+vkdzDYRVAcNnjMsAemTP8XJkZOVKpY0MMKG/nC1z1VeUUrLi8rCeDUkaGytw/cnxU9/st+0ILEwQC1ibNnrIOK4forQV9P52qVJDc/4ZGwzcy5Lh/PxIQ9WPbHwzc6XbcNYrmWTqRHIC5jTWMWotdCXUAp1DlcAEXE/hWtAy7Xb/9+aUATX0xDPUZqPVDtMzNFe4zOQbRi45L5ej0kTvdqPSQqzDc2XTS71kg2C86YnDcPR+3IIr86hTPTHjFEJmso2IGOFOtbPv0OOEmgmvlqXipxkOox/3YCwX4/MG/YSzGMjovAm7+cN4Gzvc5hn1pj8yJHUlzJR1lDR1n7i1dyfjU0GsG1p52LZUEpHQMz7t2BDLOT05mHsRSdq5MabxzhOb03mKy29sAQTN7i0IzxK9/K1ECDJuHYhZoaZXNhhnn3hehdnR4Rb++4Xv4cbrMrvZnk91cUlFixLm8EG5es2yHmna4YhGN5XZn6JIcBO7hzR6Ky/Sp5jsGULcotOIq65RsUt/heJ0XPeaeItH6OmXjAkUry3aPdm+ALSHoWwRs NyaHaZrN /dt26Xv7qXQXgz/cQYrvOAqfbS0A2NICL6LfreFAvCHjqaLTrYZF8wQSdPkcCs/uFl64xe2ejx2dIx0F+mSNWh4hrYAviakpm4S4B6IiLkRP86qx+mcqmo5ZOboWrFeKjRaYieKMt0vxz3Fok5fYFswdIMbUIYpJwIl7ZynaQcMH9OrHL5ftC7Vm1zd9EcSBb764XtxUKTiHgB5OFxy6gaq+S7gPGK7OslgbYi6yhD71kdsQbJUpzdpLxTcBoXKthniqilaG9ToK1bbFt5zvR7SdH63jq9vXPzckmIR3IZ3PtNaFwGAfPrnm4xRpzudifGaePHxaeu3BS8oEBEl+EtWDUsRvTpYp8ZK3QvvQFNNCNS/jAO9G+i89VQzq7uJPyFEX8DK/DQQrt1J8qutsuRCfDDqJATb1BgPMI 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/6/26 3:51, Hugh Dickins wrote: > On Tue, 25 Jun 2024, Kefeng Wang wrote: >> On 2024/6/25 13:04, Hugh Dickins wrote: >>> Commit "mm: migrate: split folio_migrate_mapping()" drew attention to >>> "Note, the folio_ref_freeze() is moved out of xas_lock_irq(), Since the >>> folio is already isolated and locked during migration, so suppose that >>> there is no functional change." >>> >>> That was a mistake. Freezing a folio's refcount to 0 is much like taking >>> a spinlock: see how filemap_get_entry() takes rcu_read_lock() then spins >>> around until the folio is unfrozen. If the task freezing is preempted (or >>> calls cond_resched(), as folio_mc_copy() may do), then it risks deadlock: >>> in my case, one CPU in zap_pte_range() with free_swap_and_cache_nr() >>> trying to reclaim swap while PTL is held, all the other CPUs in reclaim >>> spinning for that PTL. >> >> Oh, thanks for pointing this out, I didn't take that into account. >>> >>> I'm uncertain whether it's necessary for interrupts to be disabled as >>> well as preemption, but since they have to be disabled for the page >>> cache migration, it's much the best to do it all together as before. >>> So revert to folio_ref_freeze() under xas_lock_irq(): but keep the >>> preliminary folio_ref_count() check, which does make sense before >>> trying to copy the folio's data. >> >> This is what my RFC version[1] does, which adds same reference check to >> avoid the unnecessary folio_mc_copy(). >> >> Should I resend all patches, or Andrew directly pick this one? > > Andrew asks for a resend: I was only aiming to fix the bug, and > have no perspective on how much of the series remains worthwhile. > >> >> >> Thanks. >> >> [1] >> https://lore.kernel.org/linux-mm/20240129070934.3717659-7-wangkefeng.wang@huawei.com/ >> >> >>> >>> Use "expected_count" for the expected count throughout. >>> >>> Signed-off-by: Hugh Dickins >>> --- >>> mm/migrate.c | 59 +++++++++++++++++++++++++--------------------------- >>> 1 file changed, 28 insertions(+), 31 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index 27f070f64f27..8beedbb42a93 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -400,8 +400,8 @@ static int folio_expected_refs(struct address_space >>> *mapping, >>> * 2 for folios with a mapping >>> * 3 for folios with a mapping and PagePrivate/PagePrivate2 set. >>> */ >>> -static void __folio_migrate_mapping(struct address_space *mapping, >>> - struct folio *newfolio, struct folio *folio, int expected_cnt) >>> +static int __folio_migrate_mapping(struct address_space *mapping, >>> + struct folio *newfolio, struct folio *folio, int >>> expected_count) >> >> We can rename it back to folio_migrate_mapping(). > > Almost. I did want to remove the __ layer, but internally the last > parameter is expected_count, whereas externally it is extra_count: > each has merit in its place, so I left them as is. Indeed, I refresh all patches, we still need this __filemap_migrate_mapping, thanks. > > Hugh >