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 F1211C433EF for ; Fri, 27 May 2022 08:04:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32CE28D0007; Fri, 27 May 2022 04:04:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DBCA8D0002; Fri, 27 May 2022 04:04:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EC7E8D0007; Fri, 27 May 2022 04:04:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 115518D0002 for ; Fri, 27 May 2022 04:04:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D38B960BFD for ; Fri, 27 May 2022 08:04:44 +0000 (UTC) X-FDA: 79510786488.04.79D4CED Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf04.hostedemail.com (Postfix) with ESMTP id 172DF40012 for ; Fri, 27 May 2022 08:04:26 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4L8ck25QBbzbbqP; Fri, 27 May 2022 16:03:06 +0800 (CST) Received: from huawei.com (10.175.124.27) 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, 27 May 2022 16:04:39 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH] mm/vmscan: don't try to reclaim freed folios Date: Fri, 27 May 2022 16:04:51 +0800 Message-ID: <20220527080451.48549-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 172DF40012 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: xiggosh17f81h5gacus45oxmao7oqf67 X-Rspamd-Server: rspam05 X-HE-Tag: 1653638666-879425 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: If folios were freed from under us, there's no need to reclaim them. Skip these folios to save lots of cpu cycles and avoid possible unnecessary disk IO. Signed-off-by: Miaohe Lin --- mm/vmscan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f7d9a683e3a7..646dd1efad32 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1556,12 +1556,18 @@ static unsigned int shrink_page_list(struct list_head *page_list, folio = lru_to_folio(page_list); list_del(&folio->lru); + nr_pages = folio_nr_pages(folio); + if (folio_ref_count(folio) == 1) { + /* folio was freed from under us. So we are done. */ + WARN_ON(!folio_put_testzero(folio)); + goto free_it; + } + if (!folio_trylock(folio)) goto keep; VM_BUG_ON_FOLIO(folio_test_active(folio), folio); - nr_pages = folio_nr_pages(folio); /* Account the number of base pages */ sc->nr_scanned += nr_pages; -- 2.23.0