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 CFA3DC54E66 for ; Thu, 14 Mar 2024 02:34:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17E9C80078; Wed, 13 Mar 2024 22:34:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12FD480073; Wed, 13 Mar 2024 22:34:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F385D80078; Wed, 13 Mar 2024 22:34:22 -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 E478980073 for ; Wed, 13 Mar 2024 22:34:22 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 79C211A085E for ; Thu, 14 Mar 2024 02:34:22 +0000 (UTC) X-FDA: 81894075564.05.D82C8F1 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf25.hostedemail.com (Postfix) with ESMTP id 54458A0007 for ; Thu, 14 Mar 2024 02:34:18 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710383660; 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=PBFSh6TUyeSHu3NfcTIcJMMmKc/2kjGkd0y3OEswKwM=; b=c6AesOoi5D4lkkjsK70ovhH7xXlPaq/b5EkP0YLXh20tjxNZZUIkQBZSAMLdsbMUJK+glr 4aJWP3AJCp+QHu5GiSlwIEqI+9sAouACkqS+lqwtp3q6SOdiOVa+9QVGTTzE9jrZmvZKVM U50iT+0+XqyvrrcW4/JUCJaWezeFXuA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710383660; a=rsa-sha256; cv=none; b=7QHix6SixvVplsJeSQwnrJkdJ4Zy1+cCKn54GozYN5dfJIFjEkElTk3KcxfFA5Lu2k+Ex6 zeyHHZ7dbyjNpppCQzZS0vf1rPv/Ko7bbrQ+pokLNjWlzrVK+GXz2IFRVK5O6mJQrsw6R7 KWB4wxYAqerJ+mCyrQ2GXMgrPOhPyfg= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4TwBGW0F1Kz1QBM0; Thu, 14 Mar 2024 10:31:47 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id 38AD91401E0; Thu, 14 Mar 2024 10:34:15 +0800 (CST) Received: from [10.173.135.154] (10.173.135.154) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 14 Mar 2024 10:34:14 +0800 Subject: Re: [PATCH 6/8] mm/memory-failure: Convert memory_failure() to use a folio To: Jane Chu , Matthew Wilcox CC: , Naoya Horiguchi , Andrew Morton , References: <20240229212036.2160900-1-willy@infradead.org> <20240229212036.2160900-7-willy@infradead.org> <5eab08d7-ae38-4f99-401f-f361466e34e0@huawei.com> <196d00e3-4335-4f8f-ac51-5ccfa5ef5f75@oracle.com> From: Miaohe Lin Message-ID: Date: Thu, 14 Mar 2024 10:34:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <196d00e3-4335-4f8f-ac51-5ccfa5ef5f75@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.135.154] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-Rspamd-Queue-Id: 54458A0007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bx7hfufujftce9ayr8hqrebkodmh6mhz X-HE-Tag: 1710383658-6509 X-HE-Meta: U2FsdGVkX19/ISA8mhNVLwjwPF6UqENZjglHGQbp4pJpY4m41DQK1410jLIdN4nIs2T+scJueNNthU9izVkfkU/HgUXd4ceuMK1wFwBFJFwjGhvAEtpks+vlvyPGeBJBZn9uZqS+Bbg22bwZ/KQR7JrxTY8fd+WGhVhlkPHpV1DvIhF0Fmkhdu6cioRRl9My051ZiBF1pw+Y6YdjKq0k00qyTLsP/gV07NwVY0LUhoNlOr2aV0rE4YMM6bc/yj6jD72b2ula8Z+qKEFhRsxGC3kPq41+8mu38RceGwPEecHzl1WUsDeSEyJJVtprGXR5vQ0fmyFX4hEt6wgao6kpTy2f5E2eHPOFnG+XeTBne5zr+hMohe1XxmYZhj2Pv+UEsp3GlMT/XaF5BzkUdZBotOCGlzvHHUXu8a4Qn1bFZ0RRzWrTIJQjSoURT94H9OwpmX1lJoexw46ym8BDrA4GGbnmoXeFZh8ou6klM6XVC76cxHJY4B0P0LZ9JHivmxGhopKwEHOORdTcKZ4ANLk2JViCYC5DYFAOBYapIUlXlcS3pKrD8tbVkK8IPtDoz1Lt3Ob99lGpz5ZZC1W7A+QJ5XVTinh2yjECByhS6g6GRBN7PM8EpVeg8mD0o+v2imp57/xHiaNLxeiyM6l8O6ZMqOWZXi5j1zLG2n8D8bbUv62PRUiMPMJYt1V10PMHWWopMAVWVdy9IHNsHiJycqOIE+pNWHNbTfVtbja2pi1vLLlU67uj3P8cipGZVdLFaiYNkVwgStlu6mBggq2MN6TAaG8T0FCUhkgSC8nOEAxjiyffPizJPb1f1Ov7bK4e+xu0wJbalO9HPD9wt7z69CT2SZDz6haxzL7D 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/13 9:23, Jane Chu wrote: > On 3/12/2024 7:14 AM, Matthew Wilcox wrote: > >> On Tue, Mar 12, 2024 at 03:07:39PM +0800, Miaohe Lin wrote: >>> On 2024/3/11 20:31, Matthew Wilcox wrote: >>>> Assuming we have a refcount on this page so it can't be simultaneously >>>> split/freed/whatever, these three sequences are equivalent: >>> If page is stable after page refcnt is held, I agree below three sequences are equivalent. >>> >>>> 1    if (PageCompound(p)) >>>> >>>> 2    struct page *head = compound_head(p); >>>> 2    if (PageHead(head)) >>>> >>>> 3    struct folio *folio = page_folio(p); >>>> 3    if (folio_test_large(folio)) >>>> >>>> . >>>> >>> But please see below commit: >>> >>> """ >>> commit f37d4298aa7f8b74395aa13c728677e2ed86fdaf >>> Author: Andi Kleen >>> Date:   Wed Aug 6 16:06:49 2014 -0700 >>> >>>      hwpoison: fix race with changing page during offlining >>> >>>      When a hwpoison page is locked it could change state due to parallel >>>      modifications.  The original compound page can be torn down and then >>>      this 4k page becomes part of a differently-size compound page is is a >>>      standalone regular page. >>> >>>      Check after the lock if the page is still the same compound page. >> I can't speak to what the rules were ten years ago, but this is not >> true now.  Compound pages cannot be split if you hold a refcount. >> Since we don't track a per-page refcount, we wouldn't know which of >> the split pages to give the excess refcount to. > > I noticed this recently > >  * GUP pin and PG_locked transferred to @page. Rest subpages can be freed if >  * they are not mapped. >  * >  * Returns 0 if the hugepage is split successfully. >  * Returns -EBUSY if the page is pinned or if anon_vma disappeared from under >  * us. >  */ > int split_huge_page_to_list(struct page *page, struct list_head *list) > { > > I have a test case with poisoned shmem THP page that was mlocked and > > GUP pinned (FOLL_LONGTERM|FOLL_WRITE), but the split succeeded. Thanks for points this out. Compound pages can be split even if extra refcnt is held. So folio_test_large check is not stable if we hold a refcnt now? Will it introduce some obscure races? Except from that, I think a page cannot become a subpage of a THP when extra refcnt is held now. So below code can be removed. Any thought? /* * We're only intended to deal with the non-Compound page here. * However, the page could have changed compound pages due to * race window. If this happens, we could try again to hopefully * handle the page next round. */ if (PageCompound(p)) { if (retry) { ClearPageHWPoison(p); unlock_page(p); put_page(p); flags &= ~MF_COUNT_INCREASED; retry = false; goto try_again; } res = action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); goto unlock_page; } Thanks. > > thanks, > > -jane > > .