From nobody Sat Jul 25 02:43:20 2026 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C8C93F44CF for ; Mon, 20 Jul 2026 11:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545938; cv=none; b=nQoNtyvdEoqo4Y+JyrGRHtfwynvciFGkPgtUVwFSa8ploKuTx2xHDQpt45zGaRpW8nZy456L6asoG4mZa7ToV0pvmPN6Xt6M0XtfhiOCG8YfumF2R2R2AS33i/rKvRKhkwY1hxwNQzs9jxqxGjQOOuoo445gL4j4rlx8gFNit+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545938; c=relaxed/simple; bh=G+86JdbunNLIBuFbiHv2px2sL8QMG+vLty8H84m9FmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PcgpKEHTV4EvnKrgZzC4QtZWEqr+7LWT0DMGohoasUa5nCKmUDRF2x+e7VWZ8z5PM7h8ITr/OveCw4dRQL3tZjvb32mkkZwEtCERl0ilo+j8f+vD7cDMJnijnaS03++RHlM/dd0TMAalzzQh/iOIu5btx21zq+fADPvwcpeCoQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=WXD0fKUZ; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="WXD0fKUZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784545932; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Kx0HHACCJBu4qLsNxTSVWqhiiV39FZzOaFUJs4a+Yho=; b=WXD0fKUZPUXOHDhsYCE060mGyKKXgClYBhE9DiiG0rHSFvcpnMYWL81j5gcQqUJGdqURNJk7D5/bL+UHiZsHwDQHNYKeDlv1b1xtfjLw54vix73+inMkzEK3mJJxo9NJyq84k5P6Nko8KYpVb/twUDV9O7oO7abf03BU9R+pIto= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0X7THEvM_1784545929; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X7THEvM_1784545929 cluster:ay36) by smtp.aliyun-inc.com; Mon, 20 Jul 2026 19:12:10 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, kasong@tencent.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, mhocko@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] mm: vmscan: convert folio_referenced() to use vma_flags_t Date: Mon, 20 Jul 2026 19:12:00 +0800 Message-ID: <2bd39e16ec19e3e3c4716aa9a1a25775c26cac57.1784509721.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace use of the legacy vm_flags_t flags with vma_flags_t values for folio_referenced() and related logic. This is also a preparation for the following changes. No functional changes. Signed-off-by: Baolin Wang Acked-by: David Hildenbrand (Arm) Acked-by: Johannes Weiner Reviewed-by: Barry Song Reviewed-by: Kairui Song Reviewed-by: Axel Rasmussen --- include/linux/rmap.h | 7 +++---- mm/rmap.c | 19 +++++++++++-------- mm/vmscan.c | 14 +++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 8dc0871e5f00..e090aa09825d 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -843,7 +843,7 @@ static inline int folio_try_share_anon_rmap_pmd(struct = folio *folio, * Called from mm/vmscan.c to handle paging out */ int folio_referenced(struct folio *, int is_locked, - struct mem_cgroup *memcg, vm_flags_t *vm_flags); + struct mem_cgroup *memcg, vma_flags_t *vma_flags); =20 void try_to_migrate(struct folio *folio, enum ttu_flags flags); void try_to_unmap(struct folio *, enum ttu_flags flags); @@ -975,10 +975,9 @@ struct anon_vma *folio_lock_anon_vma_read(const struct= folio *folio, #define anon_vma_prepare(vma) (0) =20 static inline int folio_referenced(struct folio *folio, int is_locked, - struct mem_cgroup *memcg, - vm_flags_t *vm_flags) + struct mem_cgroup *memcg, vma_flags_t *vma_flags) { - *vm_flags =3D 0; + vma_flags_clear_all(vma_flags); return 0; } =20 diff --git a/mm/rmap.c b/mm/rmap.c index ad820fe86f7d..73c2fe2d1946 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -907,7 +907,7 @@ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long = address) struct folio_referenced_arg { int mapcount; int referenced; - vm_flags_t vm_flags; + vma_flags_t vma_flags; struct mem_cgroup *memcg; }; =20 @@ -926,7 +926,7 @@ static bool folio_referenced_one(struct folio *folio, address =3D pvmw.address; nr =3D 1; =20 - if (vma->vm_flags & VM_LOCKED) { + if (vma_test(vma, VMA_LOCKED_BIT)) { ptes++; pra->mapcount--; =20 @@ -947,7 +947,7 @@ static bool folio_referenced_one(struct folio *folio, /* Restore the mlock which got missed */ mlock_vma_folio(folio, vma); page_vma_mapped_walk_done(&pvmw); - pra->vm_flags |=3D VM_LOCKED; + vma_flags_set(&pra->vma_flags, VMA_LOCKED_BIT); return false; /* To break the loop */ } =20 @@ -1015,8 +1015,11 @@ static bool folio_referenced_one(struct folio *folio, referenced++; =20 if (referenced) { + vma_flags_t vma_flags =3D vma->flags; + pra->referenced++; - pra->vm_flags |=3D vma->vm_flags & ~VM_LOCKED; + vma_flags_clear(&vma_flags, VMA_LOCKED_BIT); + vma_flags_set_mask(&pra->vma_flags, vma_flags); } =20 if (!pra->mapcount) @@ -1054,7 +1057,7 @@ static bool invalid_folio_referenced_vma(struct vm_ar= ea_struct *vma, void *arg) * @folio: The folio to test. * @is_locked: Caller holds lock on the folio. * @memcg: target memory cgroup - * @vm_flags: A combination of all the vma->vm_flags which referenced the = folio. + * @vma_flags: A combination of all the vma->flags which referenced the fo= lio. * * Quick test_and_clear_referenced for all mappings of a folio, * @@ -1062,7 +1065,7 @@ static bool invalid_folio_referenced_vma(struct vm_ar= ea_struct *vma, void *arg) * the function bailed out due to rmap lock contention. */ int folio_referenced(struct folio *folio, int is_locked, - struct mem_cgroup *memcg, vm_flags_t *vm_flags) + struct mem_cgroup *memcg, vma_flags_t *vma_flags) { bool we_locked =3D false; struct folio_referenced_arg pra =3D { @@ -1078,7 +1081,7 @@ int folio_referenced(struct folio *folio, int is_lock= ed, }; =20 VM_WARN_ON_ONCE_FOLIO(folio_is_zone_device(folio), folio); - *vm_flags =3D 0; + vma_flags_clear_all(vma_flags); if (!pra.mapcount) return 0; =20 @@ -1092,7 +1095,7 @@ int folio_referenced(struct folio *folio, int is_lock= ed, } =20 rmap_walk(folio, &rwc); - *vm_flags =3D pra.vm_flags; + vma_flags_set_mask(vma_flags, pra.vma_flags); =20 if (we_locked) folio_unlock(folio); diff --git a/mm/vmscan.c b/mm/vmscan.c index b7ef032e78a0..11357b86ba2c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -861,16 +861,16 @@ static enum folio_references folio_check_references(s= truct folio *folio, struct scan_control *sc) { int referenced_ptes, referenced_folio; - vm_flags_t vm_flags; + vma_flags_t vma_flags; =20 referenced_ptes =3D folio_referenced(folio, 1, sc->target_mem_cgroup, - &vm_flags); + &vma_flags); =20 /* * The supposedly reclaimable folio was found to be in a VM_LOCKED vma. * Let the folio, now marked Mlocked, be moved to the unevictable list. */ - if (vm_flags & VM_LOCKED) + if (vma_flags_test(&vma_flags, VMA_LOCKED_BIT)) return FOLIOREF_ACTIVATE; =20 /* @@ -914,7 +914,7 @@ static enum folio_references folio_check_references(str= uct folio *folio, /* * Activate file-backed executable folios after first usage. */ - if ((vm_flags & VM_EXEC) && folio_is_file_lru(folio)) + if (vma_flags_test(&vma_flags, VMA_EXEC_BIT) && folio_is_file_lru(folio)) return FOLIOREF_ACTIVATE; =20 return FOLIOREF_KEEP; @@ -2063,7 +2063,7 @@ static void shrink_active_list(unsigned long nr_to_sc= an, { unsigned long nr_taken; unsigned long nr_scanned; - vm_flags_t vm_flags; + vma_flags_t vma_flags; LIST_HEAD(l_hold); /* The folios which were snipped off */ LIST_HEAD(l_active); LIST_HEAD(l_inactive); @@ -2107,7 +2107,7 @@ static void shrink_active_list(unsigned long nr_to_sc= an, =20 /* Referenced or rmap lock contention: rotate */ if (folio_referenced(folio, 0, sc->target_mem_cgroup, - &vm_flags) !=3D 0) { + &vma_flags) !=3D 0) { /* * Identify referenced, file-backed active folios and * give them one more trip around the active list. So @@ -2117,7 +2117,7 @@ static void shrink_active_list(unsigned long nr_to_sc= an, * IO, plus JVM can create lots of anon VM_EXEC folios, * so we ignore them here. */ - if ((vm_flags & VM_EXEC) && folio_is_file_lru(folio)) { + if (vma_flags_test(&vma_flags, VMA_EXEC_BIT) && folio_is_file_lru(folio= )) { nr_rotated +=3D folio_nr_pages(folio); list_add(&folio->lru, &l_active); continue; --=20 2.47.3 From nobody Sat Jul 25 02:43:20 2026 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A84AF3F44D3 for ; Mon, 20 Jul 2026 11:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545939; cv=none; b=PoMjcIjxWVwnqWfTP5L3kBG0rDJJIpJG7o+lRAEY/BjUoybm7l7G0jjTUsTAALLmfxY7KAjpSaAC+uxVgJU4+OCsbaZ2di5fB9Dt1B42ocW39vRCh8Sp+gjIHuEHn79f8wzUOPxtZhwNEPbCepN3ke/JF3mDIRBbJZquzv2F/3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545939; c=relaxed/simple; bh=rCzJV0ETmhGhJnsf/SyTQn1Z9CHQ2Mn4YoKB8Any4mQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=taqTTwSkePK6mKFu0kGQj2MoCvNxhv844CIYW93C6EcfTeVN6dxHJOZB7L66ccZpcGWa1b/XLfaoeSlZaUThSS3PZ18k4N2dMHMXbeZICmSjjOOQykL/1FFylXsTA/EAk0knE4L6LV83ktbIQUAbuPq4WzvAIw0FlQOEjwsyzyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Eud/wBbB; arc=none smtp.client-ip=115.124.30.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Eud/wBbB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784545933; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=qKLNv9nPUB641uxGT2XoWRnvBcDasFEpS3y3304Rfn4=; b=Eud/wBbBA1nMIdBN/MfU/gB2G2nIJenm2H0l4E/wkctunTzbWJULXaP+bzTCqI+hMgbnKFQ2RA3DB10pO5QUGTglH+X8iqCAVFhf3JH/nOjKlEaqzVDwo/ws/PkLKjbC9SlMZ6V9Sftw4ZwCk55sfrZ/nzP8l2dBcrZxyUEwWa0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0X7THEvy_1784545930; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X7THEvy_1784545930 cluster:ay36) by smtp.aliyun-inc.com; Mon, 20 Jul 2026 19:12:11 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, kasong@tencent.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, mhocko@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] mm: vmscan: add a helper to identify file-backed executable folios Date: Mon, 20 Jul 2026 19:12:01 +0800 Message-ID: <2ee74f9f98ac45a2f0db0ceb018e086bdb671d17.1784509721.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper to identify file-backed executable folios to avoid duplicate code. No functional changes. Signed-off-by: Baolin Wang Acked-by: Johannes Weiner Reviewed-by: Axel Rasmussen Reviewed-by: Barry Song Reviewed-by: David Hildenbrand (Arm) Reviewed-by: Kairui Song --- mm/vmscan.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 11357b86ba2c..8f0c31a4848e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -268,6 +268,12 @@ static int sc_swappiness(struct scan_control *sc, stru= ct mem_cgroup *memcg) } #endif =20 +static inline bool is_exec_file_folio(const struct folio *folio, + const vma_flags_t *vma_flags) +{ + return vma_flags_test(vma_flags, VMA_EXEC_BIT) && folio_is_file_lru(folio= ); +} + static void set_task_reclaim_state(struct task_struct *task, struct reclaim_state *rs) { @@ -914,7 +920,7 @@ static enum folio_references folio_check_references(str= uct folio *folio, /* * Activate file-backed executable folios after first usage. */ - if (vma_flags_test(&vma_flags, VMA_EXEC_BIT) && folio_is_file_lru(folio)) + if (is_exec_file_folio(folio, &vma_flags)) return FOLIOREF_ACTIVATE; =20 return FOLIOREF_KEEP; @@ -2117,7 +2123,7 @@ static void shrink_active_list(unsigned long nr_to_sc= an, * IO, plus JVM can create lots of anon VM_EXEC folios, * so we ignore them here. */ - if (vma_flags_test(&vma_flags, VMA_EXEC_BIT) && folio_is_file_lru(folio= )) { + if (is_exec_file_folio(folio, &vma_flags)) { nr_rotated +=3D folio_nr_pages(folio); list_add(&folio->lru, &l_active); continue; --=20 2.47.3 From nobody Sat Jul 25 02:43:20 2026 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 928053F44D1 for ; Mon, 20 Jul 2026 11:12:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545937; cv=none; b=SnpbN+8fHXV7J9exI8IFRtZY0wUDMBMz+lKzLN00WHjjGX6VDukiAIczo8yMFowPgton/0wwA7T99ApZWyGO+Z35pfCOPTeuZ9/N4pRkWtB3bFkSPSNjqu238SLtYQLnUnPsyZMpsLRK9zvZZq5e4ZA7dehLhJuAMIMRkg9gzwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784545937; c=relaxed/simple; bh=934q2rxU/afAtWk4sd6NhiVJXeGAkubj2nXp19Rr2u4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BwCty6ra5fNneAUzXaS3bw5lJy3uH9X/fX6NYnRN0Cg6KSPmWQW2duqqFBrNJolSPkjylxkeq8p1Rw7K3A2E/ezafo4Z4VL5y6d5X9F7H9YVV9toZtHRQGGt59V9tFix6gKJRPuZUtmlbxfGybmgR1lieBRYLGQIG+2CsFWKBjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=TA0Lm8FR; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="TA0Lm8FR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784545933; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bszNFZM6om9ILDWnNHRZxsFQwjm6KW0clbRXih7h2aE=; b=TA0Lm8FREzu/7PX1Av0X+GYQJCyBiG5lUCgqLCBW4BAaq83b68POCUO71zlSLbbxtp3H1pfrOT2RVAF1J6KdAh7iIk0ag6+4DFyzZzSW/s+UNCWowwNbqbA0LefaV26TUeDEQSNktH/wefzqq3w+UG9Dt+Xomw89Z4EplreswGc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0X7TBAGP_1784545931; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X7TBAGP_1784545931 cluster:ay36) by smtp.aliyun-inc.com; Mon, 20 Jul 2026 19:12:12 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, hannes@cmpxchg.org Cc: riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, kasong@tencent.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, mhocko@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] mm: mglru: promote mapped executable folios after first usage Date: Mon, 20 Jul 2026 19:12:02 +0800 Message-ID: X-Mailer: git-send-email 2.43.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Classical LRU protects mapped executable file folios through commit 8cab4754d24a0 ("vmscan: make mapped executable pages the first class citizen") and commit c909e99364c8 ("vmscan: activate executable pages after first usage"), giving executable code a better chance to stay in memory, avoiding IO thrashing and improving workload performance. However, MGLRU's protection of mapped executable file folios is less reliable. Although shrink_folio_list() checks references, the access flag of mapped executable file folios may have already been checked and cleared by lru_gen_look_around() or walk_mm(). Additionally, folio_update_gen() or lru_gen_set_refs() only sets the 'PG_referenced' flag for mapped executable file folios, which causes shrink_folio_list() to ignore the first usage of these mapped executable file folios and reclaim them easily. Follow the classical LRU's logic, promoting mapped executable file folios after their first usage in folio_update_gen() and lru_gen_set_refs(), giving executable code a better chance to stay in memory. On my 32-core Arm machine, with the memcg limit set to 2G, running 'make -j32' to build kernel showed some improvement in sys time. base patched 9248.543s 7861.579s Signed-off-by: Baolin Wang Acked-by: Johannes Weiner Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 8f0c31a4848e..b1ec65fb8947 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -841,10 +841,16 @@ enum folio_references { * with PG_active set. In contrast, the aging (page table walk) path uses * folio_update_gen(). */ -static bool lru_gen_set_refs(struct folio *folio) +static bool lru_gen_set_refs(struct folio *folio, const vma_flags_t *vma_f= lags) { /* see the comment on LRU_REFS_FLAGS */ if (!folio_test_referenced(folio) && !folio_test_workingset(folio)) { + /* Activate file-backed executable folios after first usage. */ + if (is_exec_file_folio(folio, vma_flags)) { + set_mask_bits(&folio->flags.f, LRU_REFS_FLAGS, BIT(PG_workingset)); + return true; + } + set_mask_bits(&folio->flags.f, LRU_REFS_MASK, BIT(PG_referenced)); return false; } @@ -857,7 +863,7 @@ static bool lru_gen_set_refs(struct folio *folio) return true; } #else -static bool lru_gen_set_refs(struct folio *folio) +static bool lru_gen_set_refs(struct folio *folio, const vma_flags_t *vma_f= lags) { return false; } @@ -892,7 +898,7 @@ static enum folio_references folio_check_references(str= uct folio *folio, if (!referenced_ptes) return FOLIOREF_RECLAIM; =20 - return lru_gen_set_refs(folio) ? FOLIOREF_ACTIVATE : FOLIOREF_KEEP; + return lru_gen_set_refs(folio, &vma_flags) ? FOLIOREF_ACTIVATE : FOLIORE= F_KEEP; } =20 referenced_folio =3D folio_test_clear_referenced(folio); @@ -3192,14 +3198,19 @@ static bool positive_ctrl_err(struct ctrl_pos *sp, = struct ctrl_pos *pv) *************************************************************************= *****/ =20 /* promote pages accessed through page tables */ -static int folio_update_gen(struct folio *folio, int gen) +static int folio_update_gen(struct folio *folio, int gen, const vma_flags_= t *vma_flags) { unsigned long new_flags, old_flags =3D READ_ONCE(folio->flags.f); =20 VM_WARN_ON_ONCE(gen >=3D MAX_NR_GENS); =20 - /* see the comment on LRU_REFS_FLAGS */ - if (!folio_test_referenced(folio) && !folio_test_workingset(folio)) { + /* + * See the comment on LRU_REFS_FLAGS, and activate file-backed + * executable folios after first usage to avoid typical IO + * thrashing from reclaiming. + */ + if (!folio_test_referenced(folio) && !folio_test_workingset(folio) && + !is_exec_file_folio(folio, vma_flags)) { set_mask_bits(&folio->flags.f, LRU_REFS_MASK, BIT(PG_referenced)); return -1; } @@ -3432,8 +3443,8 @@ static bool suitable_to_scan(int total, int young) return young * n >=3D total; } =20 -static void walk_update_folio(struct lru_gen_mm_walk *walk, struct folio *= folio, - int new_gen, bool dirty) +static void walk_update_folio(struct lru_gen_mm_walk *walk, struct vm_area= _struct *vma, + struct folio *folio, int new_gen, bool dirty) { int old_gen; =20 @@ -3446,10 +3457,10 @@ static void walk_update_folio(struct lru_gen_mm_wal= k *walk, struct folio *folio, folio_mark_dirty(folio); =20 if (walk) { - old_gen =3D folio_update_gen(folio, new_gen); + old_gen =3D folio_update_gen(folio, new_gen, &vma->flags); if (old_gen >=3D 0 && old_gen !=3D new_gen) update_batch_size(walk, folio, old_gen, new_gen); - } else if (lru_gen_set_refs(folio)) { + } else if (lru_gen_set_refs(folio, &vma->flags)) { old_gen =3D folio_lru_gen(folio); if (old_gen >=3D 0 && old_gen !=3D new_gen) folio_activate(folio); @@ -3522,7 +3533,7 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long = start, unsigned long end, continue; =20 if (last !=3D folio) { - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, args->vma, last, gen, dirty); =20 last =3D folio; dirty =3D false; @@ -3535,7 +3546,7 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long = start, unsigned long end, walk->mm_stats[MM_LEAF_YOUNG] +=3D nr; } =20 - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, args->vma, last, gen, dirty); last =3D NULL; =20 if (i < PTRS_PER_PTE && get_next_vma(PMD_MASK, PAGE_SIZE, args, &start, &= end)) @@ -3613,7 +3624,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigne= d long addr, struct vm_area goto next; =20 if (last !=3D folio) { - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, vma, last, gen, dirty); =20 last =3D folio; dirty =3D false; @@ -3627,7 +3638,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigne= d long addr, struct vm_area i =3D i > MIN_LRU_BATCH ? 0 : find_next_bit(bitmap, MIN_LRU_BATCH, i) + = 1; } while (i <=3D MIN_LRU_BATCH); =20 - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, vma, last, gen, dirty); =20 lazy_mmu_mode_disable(); spin_unlock(ptl); @@ -4262,7 +4273,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk = *pvmw, unsigned int nr) continue; =20 if (last !=3D folio) { - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, vma, last, gen, dirty); =20 last =3D folio; dirty =3D false; @@ -4274,7 +4285,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk = *pvmw, unsigned int nr) young +=3D nr; } =20 - walk_update_folio(walk, last, gen, dirty); + walk_update_folio(walk, vma, last, gen, dirty); =20 lazy_mmu_mode_disable(); =20 --=20 2.47.3