Re: [Regerssion] [KSM] KSM CPU overhead in 6.16+ kernel compared to <=6.15 versions ("folio_walk_start" kernel object overhead)

From: craftfever

Date: Mon Oct 13 2025 - 13:19:19 EST


> Looking again, no, that's not the case. We do a cond_resched() after every page we looked up.
>
> Also, b1d3e9bbccb4 was introduced in v6.12 already. Regarding folio_walk_start(), also nothing major changed ever since v6.12.
>
> Looking at scan_get_next_rmap_item(). I guess we might hold the mmap lock for quite a long time (if we're iterating large areas where there are no suitable pages mapped -- very large sparse areas).
>
> That would explain why we end up calling folio_walk_start() that frequently.
>
> But nothing really changed in that regard lately in KSM code.
>
> What we probably should be doing, is give up the mmap lock after scanning a certain size. Or better, switch to per-VMA locks if possible.
>
> Also, looking up each address is highly inefficient if we end up having
> large empty areas. A range-walk function would be much better suited for that, so we can just jump over holes completely.
>
> But anyhow, nothing seems to have changed ever since 6.15 AFAIKT, so I'm not really sure what's going on here. Likely it's unrelated to KSM changes.
>
> -- Cheers
>
> David / dhildenb
>

I have to make a correction, folio_start_walk is present in "perf top" statistics on 6.12-6.15, it just consumes 0.5-1% of kernel time compared to 11-14% on 6.16+, where it causes ksmd 100% cpu usage compared <=6.15 kernels. I understand, that something changed in linked function, that affecting KSM behavior. Maybe, you can reproduce it with same settings, especially it happens with Chromium apps, there is V8 sandbox with huge VM size. Maybe, you could reproduce the problem with the same MemoryKSM=yes in user@.service, that sets KSM processing for all user processes, especially, when Chromium is running. KSM CPU usage really differs between 6.12-6.15 and 6.16+. Maybe, it's related to your explanation. Thank you.