mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Barry Song <baohua@kernel.org>
Cc: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org,
	hannes@cmpxchg.org, 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, axelrasmussen@google.com,
	yuanchu@google.com, weixugc@google.com, mhocko@kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/3] mm: mglru: promote mapped executable folios after first usage
Date: Thu, 23 Jul 2026 10:26:38 +0800	[thread overview]
Message-ID: <a786425e-be9b-4a06-9f9b-535419fd0c87@linux.alibaba.com> (raw)
In-Reply-To: <CAGsJ_4zBpd2o0chB84P=hNYAeM34E6xiFYMb89nrq5epr2GbVA@mail.gmail.com>



On 7/21/26 4:31 PM, Barry Song wrote:
> On Mon, Jul 20, 2026 at 7:12 PM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
>>
>> 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 <baolin.wang@linux.alibaba.com>
>> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
>> Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
>> ---
>>   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_flags)
>>   {
>>          /* 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;
>> +               }
>> +
> 
> Hi Baolin,
> 
> Do you see any performance difference if you change the code to
> something like the following?
> 
> -static bool lru_gen_set_refs(struct folio *folio)
> +static bool lru_gen_set_refs(struct folio *folio, const vma_flags_t *vma_flags)
>   {
> +       /* 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;
> +       }

I tried that, and there was no obvious difference. I think the original 
logic also promotes the exec folio when it is accessed again, so I 
prefer to keep the same logic as folio_update_gen().

As I mentioned earlier[1], lru_gen_set_refs() needs some rework, and 
I'll think about how to optimize this function later.

[1] 
https://lore.kernel.org/all/eb395442-0aad-428a-a5ac-9072d2d89060@linux.alibaba.com/

  reply	other threads:[~2026-07-23  2:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 11:11 [PATCH v4 0/3] promote mapped executable folios after first usage for MGLRU Baolin Wang
2026-07-20 11:12 ` [PATCH v4 1/3] mm: vmscan: convert folio_referenced() to use vma_flags_t Baolin Wang
2026-07-20 11:12 ` [PATCH v4 2/3] mm: vmscan: add a helper to identify file-backed executable folios Baolin Wang
2026-07-20 13:27   ` David Hildenbrand (Arm)
2026-07-20 14:26   ` Kairui Song
2026-07-21  7:47   ` Barry Song
2026-07-20 11:12 ` [PATCH v4 3/3] mm: mglru: promote mapped executable folios after first usage Baolin Wang
2026-07-21  8:31   ` Barry Song
2026-07-23  2:26     ` Baolin Wang [this message]
2026-07-24  8:00 ` [PATCH v4 0/3] promote mapped executable folios after first usage for MGLRU Zicheng Wang
2026-07-27  8:08   ` Baolin Wang
2026-07-28  4:11     ` Zicheng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a786425e-be9b-4a06-9f9b-535419fd0c87@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry@kernel.org \
    --cc=jannh@google.com \
    --cc=kasong@tencent.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=riel@surriel.com \
    --cc=shakeel.butt@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®