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 CCB0AC433F5 for ; Sat, 28 May 2022 06:24:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A6E38D0003; Sat, 28 May 2022 02:24:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 552E28D0002; Sat, 28 May 2022 02:24:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41C0A8D0003; Sat, 28 May 2022 02:24:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2F5FE8D0002 for ; Sat, 28 May 2022 02:24:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id F162880B82 for ; Sat, 28 May 2022 06:24:41 +0000 (UTC) X-FDA: 79514163162.16.B59B443 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf15.hostedemail.com (Postfix) with ESMTP id D8531A0025 for ; Sat, 28 May 2022 06:24:19 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L9BS52BdBz1JBYf; Sat, 28 May 2022 14:23:01 +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; Sat, 28 May 2022 14:24:35 +0800 Subject: Re: [PATCH] mm/vmscan: don't try to reclaim freed folios To: Matthew Wilcox CC: , , References: <20220527080451.48549-1-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: <354f9b86-44fe-493b-eac4-07c5eeb573cf@huawei.com> Date: Sat, 28 May 2022 14:24: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 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: D8531A0025 X-Stat-Signature: rte9n1ae7kfbsg8e9cq4o4b1ke9iibus Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam09 X-HE-Tag: 1653719059-40519 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/5/28 11:13, Matthew Wilcox wrote: > On Sat, May 28, 2022 at 10:52:11AM +0800, Miaohe Lin wrote: >> On 2022/5/27 23:02, Matthew Wilcox wrote: >>> What? No. This can absolutely happen. We have a refcount on the folio, >>> which means that any other thread can temporarily raise the refcount, >> >> IIUC, the folio is only in the isolated page_list now and it's not in the page cache, swap cache, pagetable or >> under any use. So there should be no way that any other thread can temporarily raise the refcount when >> folio_ref_count == 1. Or am I miss something? > > Take a look at something like GUP (fast). If this page _was_ mapped to > userspace, something like this can happen: > > Thread A Thread B > load PTE > unmap page > refcount goes to 1 > vmscan sees the page > try_get_ref > refcount is now 2. WARN_ON. > > Thread A will see that the PTE has changed and will now drop its > reference, but Thread B already spat out the WARN. > > A similar thing can happen with the page cache. Oh, I see. Many thanks for your patient explanation! :) > > If this is a worthwhile optimisation (does it happen often that we find > a refcount == 1 page?), we could do something like ... No, It should be rare. > > if (folio_ref_freeze(folio, 1)) { > nr_pages = folio_nr_pages(folio); > goto free_it; > } > > ... or ... > > if (folio_ref_count(folio) == 1 && > folio_ref_freeze(folio, 1)) { > > ... if we want to test-and-test-and-clear These proposed code changes look good to me. > > But this function is far too complicated already. I really want to > see numbers that proves the extra complexity is worth it. This optimization can save lots of cpu cycles and avoid possible disk I/O in that specified case. But that is a somewhat rare case. So there's no numbers that proves the extra complexity is worth it. Should I drop this patch or proceed with the proposed code changes above in next version? :) Many thanks! > > > . >