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 X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 072E3C07E9A for ; Wed, 14 Jul 2021 11:37:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD624613AF for ; Wed, 14 Jul 2021 11:37:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231162AbhGNLjw (ORCPT ); Wed, 14 Jul 2021 07:39:52 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:11276 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbhGNLjw (ORCPT ); Wed, 14 Jul 2021 07:39:52 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4GPwLd0rQxz1CJld; Wed, 14 Jul 2021 19:31:21 +0800 (CST) Received: from [10.174.178.125] (10.174.178.125) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 14 Jul 2021 19:36:58 +0800 Subject: Re: [PATCH 1/5] mm/vmscan: put the redirtied MADV_FREE pages back to anonymous LRU list To: Matthew Wilcox , Michal Hocko , Yu Zhao CC: , , , , , , , , , , , , References: <20210710100329.49174-1-linmiaohe@huawei.com> <20210710100329.49174-2-linmiaohe@huawei.com> <9409189e-44f7-2608-68af-851629b6d453@huawei.com> From: Miaohe Lin Message-ID: Date: Wed, 14 Jul 2021 19:36:57 +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.178.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/7/13 21:34, Matthew Wilcox wrote: > On Tue, Jul 13, 2021 at 09:13:51PM +0800, Miaohe Lin wrote: >>>> When the MADV_FREE pages are redirtied before they could be reclaimed, the pages >>>> should be put back to anonymous LRU list by setting SwapBacked flag, thus the >>>> pages will be reclaimed in normal swapout way. >>> >>> Agreed. But the question is why this needs an explicit handling here >>> when we already do handle this case when trying to unmap the page. >> >> This makes me think more. It seems even the page_ref_freeze call is guaranteed to >> success as no one can grab the page refcnt after the page is successfully unmapped. > > NO! This is wrong. Every page can have its refcount speculatively raised > (and then lowered). The two prime candidates for this are lockless GUP > and page cache lookups, but there can be others too. > Many thanks for pointing this out. My overlook! Sorry! So, it seems lockless GUP can redirty the MADV_FREE page. But is it ok to just release a redirtied MADV_FREE pages? Because we hold the last reference here and the page will be freed anyway... > . >