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 5DD09C433F5 for ; Fri, 22 Apr 2022 02:47:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B03E16B0072; Thu, 21 Apr 2022 22:47:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB25E6B0073; Thu, 21 Apr 2022 22:47:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 979F86B0074; Thu, 21 Apr 2022 22:47:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 849036B0072 for ; Thu, 21 Apr 2022 22:47:38 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 60A8B604D9 for ; Fri, 22 Apr 2022 02:47:38 +0000 (UTC) X-FDA: 79382979396.21.1121012 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf23.hostedemail.com (Postfix) with ESMTP id D074014001D for ; Fri, 22 Apr 2022 02:47:34 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KkzGy2CN9zCrfg; Fri, 22 Apr 2022 10:43:06 +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 10:47:32 +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 10:47:32 +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: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D074014001D X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: f5x5kt4ihiptkonfcgoedfg5twm7k7j6 X-HE-Tag: 1650595654-722787 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/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. > >> + 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? Thanks a lot! > Thanks, >