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 781BBC433EF for ; Fri, 22 Apr 2022 03:15:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF1406B0072; Thu, 21 Apr 2022 23:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9FD96B0073; Thu, 21 Apr 2022 23:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8E6D6B0074; Thu, 21 Apr 2022 23:15:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id BAFA06B0072 for ; Thu, 21 Apr 2022 23:15:40 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 876016017B for ; Fri, 22 Apr 2022 03:15:40 +0000 (UTC) X-FDA: 79383050040.31.7AC14B6 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf30.hostedemail.com (Postfix) with ESMTP id 308E680026 for ; Fri, 22 Apr 2022 03:15:35 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KkzzW0NMkzfZMc; Fri, 22 Apr 2022 11:14:47 +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.2375.24; Fri, 22 Apr 2022 11:15:33 +0800 Subject: Re: [PATCH v2 3/3] mm/madvise: free hwpoison and swapin error entry in madvise_free_pte_range To: Peter Xu CC: , , , , , , , , , , , , References: <20220421125348.62483-1-linmiaohe@huawei.com> <20220421125348.62483-4-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: Date: Fri, 22 Apr 2022 11:15:33 +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: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: gj4mr55scphqq5oqnnx45hyhkxoykoyu X-Rspamd-Queue-Id: 308E680026 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650597335-186615 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/4/22 10:52, Peter Xu wrote: > On Fri, Apr 22, 2022 at 10:47:32AM +0800, Miaohe Lin wrote: >> On 2022/4/21 22:28, Peter Xu wrote: >>> On Thu, Apr 21, 2022 at 08:53:48PM +0800, Miaohe Lin wrote: >>>> Once the MADV_FREE operation has succeeded, callers can expect they might >>>> get zero-fill pages if accessing the memory again. Therefore it should be >>>> safe to delete the hwpoison entry and swapin error entry. There is no >>>> reason to kill the process if it has called MADV_FREE on the range. >>>> >>>> Suggested-by: Alistair Popple >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/madvise.c | 13 ++++++++----- >>>> 1 file changed, 8 insertions(+), 5 deletions(-) >>>> >>>> diff --git a/mm/madvise.c b/mm/madvise.c >>>> index 4d6592488b51..5f4537511532 100644 >>>> --- a/mm/madvise.c >>>> +++ b/mm/madvise.c >>>> @@ -624,11 +624,14 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, >>>> swp_entry_t entry; >>>> >>>> entry = pte_to_swp_entry(ptent); >>>> - if (non_swap_entry(entry)) >>>> - continue; >>>> - nr_swap--; >>>> - free_swap_and_cache(entry); >>>> - pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); >>> >>> Nitpick: IMHO you don't need to invert non_swap_entry() then it'll generate >>> a smaller diff, just add the new code above "continue". >> >> I tried this way, but that lead to long line splitting, so I rewrote the code like this. >> If you prefer to just add the new code above "continue", I will do it in the next version. > > No worry then, feel free to keep it as is Will keep it. Thanks! >> >>> >>>> + if (!non_swap_entry(entry)) { >>>> + nr_swap--; >>>> + free_swap_and_cache(entry); >>>> + pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); >>>> + } else if (is_hwpoison_entry(entry) || >>>> + is_swapin_error_entry(entry)) { >>>> + pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); >>> >>> Since it's been discussed and you're reposting a new version anyway, why >>> not start with either reusing hwpoison or pte markers? Or do you think it >>> should be for future to drop the new swap entry again? >>> >> >> IMHO if reusing hwpoison markers, there are some places that we need to distinguish them and do >> different processing (and maybe also well comment them) which will make code more complicated and >> somewhat hard to follow. And the "swapin error marker" here is most straightforward. And If pte markers >> will support the "swapin error case" in the future, I think it's fine to change to use it then. >> Does this make sense for you? > > Yeah it's fine. If the pte marker things can finally land as expected, > maybe I can try it out as the 2nd user of it. :) Sounds good to me. And if needed, I am glad to do it then. Thanks! ;) >