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 8CC65C54E58 for ; Fri, 15 Mar 2024 06:25:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21F6380100; Fri, 15 Mar 2024 02:25:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CF59800B4; Fri, 15 Mar 2024 02:25:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 070BA80100; Fri, 15 Mar 2024 02:25:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E7836800B4 for ; Fri, 15 Mar 2024 02:25:19 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 92E421A0786 for ; Fri, 15 Mar 2024 06:25:19 +0000 (UTC) X-FDA: 81898286358.01.D7AA991 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf14.hostedemail.com (Postfix) with ESMTP id 101BE100005 for ; Fri, 15 Mar 2024 06:25:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.191 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=1710483916; 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=+AZQNn9bU0iPofku2ILrD+R28TQD3hQdM7qPYlGCIYo=; b=lrk+KONx1zJCTRLE3dOBV+3i9DhXU4BYks5OdO7LPl/UWtDU51pagkzHC4bpvW2+DInvHD SsA3fV0nbEgLfFXj8+5SspzQTP2QDkMmvSAjs3icIplZYP3/nmRv2mWAhhpacob3cUdpD2 A6ItDSYMCaqTPFxP9LG8Iui1FfrcDZI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710483916; a=rsa-sha256; cv=none; b=7gEE7JHjPcTgy31k5ZJ9WYJcOL8Y9pDoszruVt84gCYTtQ1aef+NHoH97L5eA9jVNY5MEX a9s4iQ8OL8yhOHmvRYlMvPBNbC1L5XMmZ4mM8md3UfiHbtbekr0HbeLwi8OInYVIQMARAj nDUiZbpWO1VGCLz0NiTSgDpm9iHK+uA= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TwvLV5szlz1h2HD; Fri, 15 Mar 2024 14:22:42 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id 7F1BE1A016C; Fri, 15 Mar 2024 14:25:11 +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; Fri, 15 Mar 2024 14:25:11 +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: Fri, 15 Mar 2024 14:25:10 +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: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.135.154] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-Rspamd-Queue-Id: 101BE100005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 8w8gzqo7xicmur5ykgxs8df3p9sctick X-HE-Tag: 1710483915-599194 X-HE-Meta: U2FsdGVkX1975KaSgDAwMkgGJTqVxdLyXg64AXlqxN+vAyXnFZLh9L65Wznl4wfWrR6b7AExUbvXidmnzh0pZ3ISMH0NW+z8Kdxs+JxlQE5udoon2PZ5F0wL0XLTbJpirQjJZ6qLjqfRsGpNHU0Gh3gw4QuGaaI8zvb9qaouIZg8S3Uhf20u7isDvZH5Ftzq0JAGiXYUwk9t+lmcRDp18xmaYZi/Pw2lL+38JY2YUXRkDpPL4f+dvfE+ztHRxY4OraHh3ogGZSLvt2yg79hs5gQesc+P/nLl2yqEv5UcGyUCgMnYmqjgbl/Np4C/RI96l8cCy+JuwuyRZK+2NPgEiP5f0FNBBfddAlPiEFuWBktPiVUrSwazP47ONoWolXtVKWMqD/DJFuZMw7EDYLeKa3d4DMdl2asIesp0U2LaVUAT4X8AXfvEYIr/LE2D/DAWX/HPHwhaoGPGcmzOZ6/RsGGisiLw3/WMOJ9+2SysGiCaG8u5ShXW91ZTgOCf7DFTmgYcXO+3k3ZdjgSxvfw4FS2LofcpRjINEyI4fPxkBVZA6/A+yZqj6/uIRZe7Ht53FjZFtQ+TgL5hSTj871uRxeksfwZjruiZaXSaZeOcXDRv4DlgYoflR4iySlOMAAMs/1JImOcSWcGrwVhKFT7Awk1/FHYZ5T/S5Sx2LZPIc5S+R8V8IhuiuFYhyaF0mSIdWU8KZ2pGl4LHedzWnG7dMTdq66osJ+FMIJvy4CAsVYuZPYD+CQQ9bwwMGHhRLdKhAls1fzSsBaUe4woUYmnJzqXepRhRoOXEyt9Ha1fDloQPGuax4Hsir/DtAYMJ3abzgiYrOZwMkkHX2aRXfLCT1D6oiRDTZEIn 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/15 2:15, Jane Chu wrote: > On 3/13/2024 7:34 PM, Miaohe Lin wrote: > >> 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; >>     } > Not sure of what scenario it was meant to deal with.  How about adding a warning instead of removal? It'll be interesting to see how the warning got triggered. But if after a while nothing happens, then remove it. This sounds like a good alternative. Thanks.