From nobody Sun May 10 19:52:34 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 5C4ECC433EF for ; Mon, 25 Apr 2022 11:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241700AbiDYLPs (ORCPT ); Mon, 25 Apr 2022 07:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241705AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C222A279 for ; Mon, 25 Apr 2022 04:12:11 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Kk5yjbzCsKn; Mon, 25 Apr 2022 19:07:38 +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; Mon, 25 Apr 2022 19:12:09 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 1/6] mm/vmscan: add a comment about MADV_FREE pages check in folio_check_dirty_writeback Date: Mon, 25 Apr 2022 19:12:27 +0800 Message-ID: <20220425111232.23182-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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" The MADV_FREE pages check in folio_check_dirty_writeback is a bit hard to follow. Add a comment to make the code clear. Suggested-by: Huang, Ying Signed-off-by: Miaohe Lin Reviewed-by: Christoph Hellwig Reviewed-by: Oscar Salvador --- mm/vmscan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 99a572f01cb4..913eb565140c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1438,7 +1438,10 @@ static void folio_check_dirty_writeback(struct folio= *folio, =20 /* * Anonymous pages are not handled by flushers and must be written - * from reclaim context. Do not stall reclaim based on them + * from reclaim context. Do not stall reclaim based on them. + * MADV_FREE anonymous pages are put into inactive file list too. + * They could be mistakenly treated as file lru. So further anon + * test is needed. */ if (!folio_is_file_lru(folio) || (folio_test_anon(folio) && !folio_test_swapbacked(folio))) { --=20 2.23.0 From nobody Sun May 10 19:52:34 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 39683C433F5 for ; Mon, 25 Apr 2022 11:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbiDYLQd (ORCPT ); Mon, 25 Apr 2022 07:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AF92A275 for ; Mon, 25 Apr 2022 04:12:11 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Qk43fVzhYkZ; Mon, 25 Apr 2022 19:11:58 +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; Mon, 25 Apr 2022 19:12:09 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 2/6] mm/vmscan: introduce helper function reclaim_page_list() Date: Mon, 25 Apr 2022 19:12:28 +0800 Message-ID: <20220425111232.23182-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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" Introduce helper function reclaim_page_list() to eliminate the duplicated code of doing shrink_page_list() and putback_lru_page. Also We can separate node reclaim from node page list operation this way. No functional change intended. Signed-off-by: Miaohe Lin --- mm/vmscan.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 913eb565140c..7dcc8cf4526f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2539,14 +2539,12 @@ static void shrink_active_list(unsigned long nr_to_= scan, nr_deactivate, nr_rotated, sc->priority, file); } =20 -unsigned long reclaim_pages(struct list_head *page_list) +static unsigned int reclaim_page_list(struct list_head *page_list, + struct pglist_data *pgdat) { - int nid =3D NUMA_NO_NODE; - unsigned int nr_reclaimed =3D 0; - LIST_HEAD(node_page_list); struct reclaim_stat dummy_stat; - struct page *page; - unsigned int noreclaim_flag; + unsigned int nr_reclaimed; + struct folio *folio; struct scan_control sc =3D { .gfp_mask =3D GFP_KERNEL, .may_writepage =3D 1, @@ -2555,6 +2553,24 @@ unsigned long reclaim_pages(struct list_head *page_l= ist) .no_demotion =3D 1, }; =20 + nr_reclaimed =3D shrink_page_list(page_list, pgdat, &sc, &dummy_stat, fal= se); + while (!list_empty(page_list)) { + folio =3D lru_to_folio(page_list); + list_del(&folio->lru); + folio_putback_lru(folio); + } + + return nr_reclaimed; +} + +unsigned long reclaim_pages(struct list_head *page_list) +{ + int nid =3D NUMA_NO_NODE; + unsigned int nr_reclaimed =3D 0; + LIST_HEAD(node_page_list); + struct page *page; + unsigned int noreclaim_flag; + noreclaim_flag =3D memalloc_noreclaim_save(); =20 while (!list_empty(page_list)) { @@ -2570,28 +2586,12 @@ unsigned long reclaim_pages(struct list_head *page_= list) continue; } =20 - nr_reclaimed +=3D shrink_page_list(&node_page_list, - NODE_DATA(nid), - &sc, &dummy_stat, false); - while (!list_empty(&node_page_list)) { - page =3D lru_to_page(&node_page_list); - list_del(&page->lru); - putback_lru_page(page); - } - + nr_reclaimed +=3D reclaim_page_list(&node_page_list, NODE_DATA(nid)); nid =3D NUMA_NO_NODE; } =20 - if (!list_empty(&node_page_list)) { - nr_reclaimed +=3D shrink_page_list(&node_page_list, - NODE_DATA(nid), - &sc, &dummy_stat, false); - while (!list_empty(&node_page_list)) { - page =3D lru_to_page(&node_page_list); - list_del(&page->lru); - putback_lru_page(page); - } - } + if (!list_empty(&node_page_list)) + nr_reclaimed +=3D reclaim_page_list(&node_page_list, NODE_DATA(nid)); =20 memalloc_noreclaim_restore(noreclaim_flag); =20 --=20 2.23.0 From nobody Sun May 10 19:52:34 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 2499FC433EF for ; Mon, 25 Apr 2022 11:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241699AbiDYLQT (ORCPT ); Mon, 25 Apr 2022 07:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241619AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B972A277 for ; Mon, 25 Apr 2022 04:12:12 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Qg00JGzhYlj; Mon, 25 Apr 2022 19:11:54 +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; Mon, 25 Apr 2022 19:12:10 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 3/6] mm/vmscan: activate swap-backed executable folios after first usage Date: Mon, 25 Apr 2022 19:12:29 +0800 Message-ID: <20220425111232.23182-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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" We should activate swap-backed executable folios (e.g. tmpfs) after first usage so that executable code gets yet better chance to stay in memory. Suggested-by: Huang, Ying Signed-off-by: Miaohe Lin Reviewed-by: Huang, Ying Cc: Joonsoo Kim --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 7dcc8cf4526f..82e6fa83c472 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1415,9 +1415,9 @@ static enum page_references folio_check_references(st= ruct folio *folio, return PAGEREF_ACTIVATE; =20 /* - * Activate file-backed executable folios after first usage. + * Activate executable folios after first usage. */ - if ((vm_flags & VM_EXEC) && !folio_test_swapbacked(folio)) + if (vm_flags & VM_EXEC) return PAGEREF_ACTIVATE; =20 return PAGEREF_KEEP; --=20 2.23.0 From nobody Sun May 10 19:52:34 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 E2897C433EF for ; Mon, 25 Apr 2022 11:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239233AbiDYLP6 (ORCPT ); Mon, 25 Apr 2022 07:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241706AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D532A700 for ; Mon, 25 Apr 2022 04:12:12 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Pz2JxQzfZSF; Mon, 25 Apr 2022 19:11:19 +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; Mon, 25 Apr 2022 19:12:10 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 4/6] mm/vmscan: take all base pages of THP into account when race with speculative reference Date: Mon, 25 Apr 2022 19:12:30 +0800 Message-ID: <20220425111232.23182-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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 the page has buffers, shrink_page_list will try to free the buffer mappings associated with the page and try to free the page as well. In the rare race with speculative reference, the page will be freed shortly by speculative reference. But nr_reclaimed is not incremented correctly when we come across the THP. We need to account all the base pages in this case. Signed-off-by: Miaohe Lin --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 82e6fa83c472..10ba16fdd748 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1887,7 +1887,7 @@ static unsigned int shrink_page_list(struct list_head= *page_list, * increment nr_reclaimed here (and * leave it off the LRU). */ - nr_reclaimed++; + nr_reclaimed +=3D nr_pages; continue; } } --=20 2.23.0 From nobody Sun May 10 19:52:34 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 C7240C433EF for ; Mon, 25 Apr 2022 11:13:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237632AbiDYLQX (ORCPT ); Mon, 25 Apr 2022 07:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241572AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30EDB2A737 for ; Mon, 25 Apr 2022 04:12:13 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Q01JDsz1JBfc; Mon, 25 Apr 2022 19:11:20 +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; Mon, 25 Apr 2022 19:12:11 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 5/6] mm/vmscan: remove obsolete comment in kswapd_run Date: Mon, 25 Apr 2022 19:12:31 +0800 Message-ID: <20220425111232.23182-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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" Since commit 6b700b5b3c59 ("mm/vmscan.c: remove cpu online notification for now"), cpu online notification is removed. So kswapd won't move to proper cpus if cpus are hot-added. Remove this obsolete comment. Signed-off-by: Miaohe Lin --- mm/vmscan.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 10ba16fdd748..db3500bd5c7d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4572,7 +4572,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_r= eclaim) =20 /* * This kswapd start function will be called by init and node-hot-add. - * On node-hot-add, kswapd will moved to proper cpus if cpus are hot-added. */ void kswapd_run(int nid) { --=20 2.23.0 From nobody Sun May 10 19:52:34 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 73658C433EF for ; Mon, 25 Apr 2022 11:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231582AbiDYLQS (ORCPT ); Mon, 25 Apr 2022 07:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241713AbiDYLPm (ORCPT ); Mon, 25 Apr 2022 07:15:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3171C2A73C for ; Mon, 25 Apr 2022 04:12:13 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kn2Qm48YmzhYkj; Mon, 25 Apr 2022 19:12:00 +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; Mon, 25 Apr 2022 19:12:11 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH v3 6/6] mm/vmscan: use helper folio_is_file_lru() Date: Mon, 25 Apr 2022 19:12:32 +0800 Message-ID: <20220425111232.23182-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220425111232.23182-1-linmiaohe@huawei.com> References: <20220425111232.23182-1-linmiaohe@huawei.com> 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" Use helper folio_is_file_lru() to check whether folio is file lru. Minor readability improvement. Signed-off-by: Miaohe Lin --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index db3500bd5c7d..a2752e8fc879 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1424,7 +1424,7 @@ static enum page_references folio_check_references(st= ruct folio *folio, } =20 /* Reclaim if clean, defer dirty folios to writeback */ - if (referenced_folio && !folio_test_swapbacked(folio)) + if (referenced_folio && folio_is_file_lru(folio)) return PAGEREF_RECLAIM_CLEAN; =20 return PAGEREF_RECLAIM; --=20 2.23.0