Re: [PATCH] mm: mglru: promote mapped executable folios after first usage

From: Baolin Wang

Date: Wed Jul 15 2026 - 02:58:34 EST




On 7/15/26 2:52 PM, Barry Song wrote:
On Wed, Jul 15, 2026 at 2:33 PM Baolin Wang
<baolin.wang@xxxxxxxxxxxxxxxxx> 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() 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.

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.

Hi Baolin,

Because ARM doesn't set the surrounding PTEs to young, while x86
may behave differently and mark the surrounding PTEs as young as
well. Could we also collect the data on x86?

void set_pte_range(struct vm_fault *vmf, struct folio *folio,
struct page *page, unsigned int nr, unsigned long addr)
{
...

if (prefault && arch_wants_old_prefaulted_pte())
entry = pte_mkold(entry);
else
entry = pte_sw_mkyoung(entry);

Sure. But I don't think it's very relevant to this point. MGLRU doesn't protect normally accessed mmaped exec file folios well enough. Anyway, I'll test it on x86.