From nobody Tue Apr 28 23:19:29 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E8AC433F5 for ; Fri, 27 May 2022 08:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239389AbiE0IFA (ORCPT ); Fri, 27 May 2022 04:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242900AbiE0IEn (ORCPT ); Fri, 27 May 2022 04:04:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BD8243EDE for ; Fri, 27 May 2022 01:04:42 -0700 (PDT) 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: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_he= ad *page_list, folio =3D lru_to_folio(page_list); list_del(&folio->lru); =20 + nr_pages =3D folio_nr_pages(folio); + if (folio_ref_count(folio) =3D=3D 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; =20 VM_BUG_ON_FOLIO(folio_test_active(folio), folio); =20 - nr_pages =3D folio_nr_pages(folio); =20 /* Account the number of base pages */ sc->nr_scanned +=3D nr_pages; --=20 2.23.0