mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: akpm@linux-foundation.org, qi.zheng@linux.dev,
	shakeel.butt@linux.dev, baohua@kernel.org,
	axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
	david@kernel.org, mhocko@kernel.org, ljs@kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: mglru: promote mapped executable folios after first usage
Date: Thu, 16 Jul 2026 10:30:27 +0800	[thread overview]
Message-ID: <4067606d-2b39-4b17-a3c6-be8f09c6bf96@linux.alibaba.com> (raw)
In-Reply-To: <CAMgjq7C47i-n-e=EGWoBvydp8mT3n-ZFeiLFpY=iTVDayucTRQ@mail.gmail.com>



On 7/16/26 12:50 AM, Kairui Song wrote:
> On Wed, Jul 15, 2026 at 2:33 PM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
> 
> Hi Baolin,
>>
>> 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.
> 
> That's really a long history for those two commits :)
>>
>> 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() 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.
>>
>> Follow the classical LRU's logic, promoting mapped executable file folios
>> after their first usage in folio_update_gen(), giving executable code a
>> better chance to stay in memory.
> 
> Yeah I think that's mostly an ideology issue, recently upstream tends
> to treat all folios fairly if there is no particular reason.
> Personally I also agree that some folios are more special compared to
> other though.

OK.

>> 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>
>> ---
>>   mm/vmscan.c | 25 +++++++++++++++----------
>>   1 file changed, 15 insertions(+), 10 deletions(-)
> 
> MGLRU used to favor and put all map faulted memory at head, so could
> this be related to a recent change in any way?
> https://lore.kernel.org/linux-mm/20260526130938.66253-1-baohua@kernel.org/

I haven't tested Barry's patch yet. Personally, I don't think this is 
closely related to Barry's patch. Though we put the faulted folios into 
the secound youngest gen before, after aging, the mapped exec folios are 
still not protected like in Classical LRU, and can be easily reclaimed.

>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 986dde8e7429..429857852bdb 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -3188,7 +3188,7 @@ static bool positive_ctrl_err(struct ctrl_pos *sp, struct ctrl_pos *pv)
>>    ******************************************************************************/
>>
>>   /* promote pages accessed through page tables */
>> -static int folio_update_gen(struct folio *folio, int gen)
>> +static int folio_update_gen(struct vm_area_struct *vma, struct folio *folio, int gen)
>>   {
>>          unsigned long new_flags, old_flags = READ_ONCE(folio->flags.f);
>>
>> @@ -3196,10 +3196,15 @@ static int folio_update_gen(struct folio *folio, int gen)
>>
>>          /* 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 (vma_test(vma, VMA_EXEC_BIT) && folio_is_file_lru(folio))
>> +                       goto promote;
>> +
> 
> Do you think it's a good idea to extract this into a helper e.g.
> folio_is_executable_file?

Good point. Will do. Thanks.

      reply	other threads:[~2026-07-16  2:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  6:33 Baolin Wang
2026-07-15  6:52 ` Barry Song
2026-07-15  6:58   ` Baolin Wang
2026-07-15  7:54     ` Barry Song
2026-07-15  7:57       ` Barry Song
2026-07-15  9:00         ` Baolin Wang
2026-07-15 19:44           ` Andrew Morton
2026-07-16  4:06             ` Baolin Wang
2026-07-15 16:50 ` Kairui Song
2026-07-16  2:30   ` Baolin Wang [this message]

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=4067606d-2b39-4b17-a3c6-be8f09c6bf96@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=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=ryncsn@gmail.com \
    --cc=shakeel.butt@linux.dev \
    --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