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 D1AFCC433F5 for ; Wed, 9 Mar 2022 08:30:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AE948D001E; Wed, 9 Mar 2022 03:30:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55D4F8D0001; Wed, 9 Mar 2022 03:30:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44C7D8D001E; Wed, 9 Mar 2022 03:30:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 356668D0001 for ; Wed, 9 Mar 2022 03:30:39 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E0E97181CB145 for ; Wed, 9 Mar 2022 08:30:38 +0000 (UTC) X-FDA: 79224176556.24.1A5EBC9 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id AAFC618000A for ; Wed, 9 Mar 2022 08:30:37 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KD4yf2TnQz1GC2R; Wed, 9 Mar 2022 16:25:46 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 9 Mar 2022 16:30:34 +0800 Subject: Re: [PATCH 2/4] mm/memory-failure.c: fix wrong user reference report To: Yang Shi CC: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , "akpm@linux-foundation.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" References: <20220228140245.24552-1-linmiaohe@huawei.com> <20220228140245.24552-3-linmiaohe@huawei.com> <20220304082714.GB3778609@hori.linux.bs1.fc.nec.co.jp> <227af111-9264-02fd-9e46-744d39ecfed0@huawei.com> <8a35d8d8-3078-89ad-4061-358a500c5d61@huawei.com> From: Miaohe Lin Message-ID: <343fff27-f421-9724-a60e-eb35148b226b@huawei.com> Date: Wed, 9 Mar 2022 16:30:34 +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 X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AAFC618000A X-Stat-Signature: p613osjbzdj8gzqamyus1fchu1zneko1 Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1646814637-845542 Content-Transfer-Encoding: quoted-printable 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: On 2022/3/9 2:51, Yang Shi wrote: > On Tue, Mar 8, 2022 at 5:11 AM Miaohe Lin wrote: >> >> On 2022/3/8 4:14, Yang Shi wrote: >>> On Mon, Mar 7, 2022 at 3:26 AM Miaohe Lin wrot= e: >>>> >>>> On 2022/3/4 16:27, HORIGUCHI NAOYA(=E5=A0=80=E5=8F=A3 =E7=9B=B4=E4=B9= =9F) wrote: >>>>> On Mon, Feb 28, 2022 at 10:02:43PM +0800, Miaohe Lin wrote: >>>>>> The dirty swapcache page is still residing in the swap cache after= it's >>>>>> hwpoisoned. So there is always one extra refcount for swap cache. >>>>> >>>>> The diff seems fine at a glance, but let me have a few question to >>>>> understand the issue more. >>>>> >>>>> - Is the behavior described above the effect of recent change on sh= mem where >>>>> dirty pagecache is pinned on hwpoison (commit a76054266661 ("mm: = shmem: >>>>> don't truncate page if memory failure happens"). Or the older ker= nels >>>>> behave as the same? >>>>> >>>>> - Is the behavior true for normal anonymous pages (not shmem pages)= ? >>>>> >>>> >>>> The behavior described above is aimed at swapcache not pagecache. So= it should be >>>> irrelevant with the recent change on shmem. >>>> >>>> What I try to fix here is that me_swapcache_dirty holds one extra pi= n via SwapCache >>>> regardless of the return value of delete_from_lru_cache. We should t= ry to report more >>>> accurate extra refcount for debugging purpose. >>> >>> I think you misunderstood the code. The delete_from_lru_cache() >>> returning 0 means the page was on LRU and isolated from LRU >>> successfully now. Returning -EIO means the page was not on LRU, so it >>> should have at least an extra pin on it. >>> >>> So MF_DELAYED means there is no other pin other than hwpoison and >>> swapcache which is expected, MF_FAILED means there might be extra >>> pins. >>> >>> The has_extra_refcount() raised error then there is *unexpected* refc= ount. >> >> Many thanks for your explanation. It seems you're right. If page is he= ld on >> the lru_pvecs when we try to do delete_from_lru_cache, and after that = it's >> drained to the lru list( so its refcnt might be 2 now). Then we might = have >> the following complain if extra_pins is always true: >> "Memory failure: ... still referenced by 0 users\n" >> >> But it seems the origin code can not report the correct reason too bec= ause >> if we retry, page can be delete_from_lru_cache and we can succeed now. >=20 > Retry is ok, but it seems overkilling to me IMHO. >=20 Anyway, it seems I misunderstood the code. So I will drop this patch. Tha= nks for comment. >> >> Anyway, many thanks for pointing this out. >> >>> >>>> >>>>> I'm trying to test hwpoison hitting the dirty swapcache, but it see= ms that >>>>> in my testing memory_faliure() fails with "hwpoison: unhandlable pa= ge" >>>> >>>> Maybe memory_faliure is racing with page reclaim where page is isola= ted? >>>> >>>>> warning at get_any_page(). So I'm still not sure that me_pagecache= _dirty() >>>>> fixes any visible problem. >>>> >>>> IIUC, me_pagecache_dirty can't do much except for the corresponding = address_space supporting >>>> error_remove_page which can truncate the dirty pagecache page. But t= his may cause silent data >>>> loss. It's better to keep the page stay in the pagecache until the f= ile is truncated, hole >>>> punched or removed as commit a76054266661 pointed out. >>>> >>>> Thanks. >>>> >>>>>> Thanks, >>>>> Naoya Horiguchi >>>>> >>>>>> >>>>>> Signed-off-by: Miaohe Lin >>>>>> --- >>>>>> mm/memory-failure.c | 6 +----- >>>>>> 1 file changed, 1 insertion(+), 5 deletions(-) >>>>>> >>>>>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>>>>> index 0d7c58340a98..5f9503573263 100644 >>>>>> --- a/mm/memory-failure.c >>>>>> +++ b/mm/memory-failure.c >>>>>> @@ -984,7 +984,6 @@ static int me_pagecache_dirty(struct page_stat= e *ps, struct page *p) >>>>>> static int me_swapcache_dirty(struct page_state *ps, struct page = *p) >>>>>> { >>>>>> int ret; >>>>>> - bool extra_pins =3D false; >>>>>> >>>>>> ClearPageDirty(p); >>>>>> /* Trigger EIO in shmem: */ >>>>>> @@ -993,10 +992,7 @@ static int me_swapcache_dirty(struct page_sta= te *ps, struct page *p) >>>>>> ret =3D delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED; >>>>>> unlock_page(p); >>>>>> >>>>>> - if (ret =3D=3D MF_DELAYED) >>>>>> - extra_pins =3D true; >>>>>> - >>>>>> - if (has_extra_refcount(ps, p, extra_pins)) >>>>>> + if (has_extra_refcount(ps, p, true)) >>>>>> ret =3D MF_FAILED; >>>>>> >>>>>> return ret; >>>>>> -- >>>>>> 2.23.0 >>>> >>>> >>> . >>> >> > . >=20