Re: 答复: [PATCH v3 2/2] ksm: Optimize rmap_walk_ksm by passing a suitable address range

From: David Hildenbrand (Arm)

Date: Thu Apr 09 2026 - 07:59:59 EST


On 4/9/26 12:56, xu.xin16@xxxxxxxxxx wrote:
>> On 4/9/26 11:41, David Hildenbrand (Arm) wrote:
>>>
>>> As we're using a dedicate kmem cache it might "only" add 8 bytes, not
>>> sure. Still an undesired increase given that we need that for each entry
>>> in the stable/unstable tree.
>>>
>>
>> Hmm, maybe we could do the following. I think the other members are only
>> relevant for the unstable tree.
>
> Well, I suspect that "SmartScan-Related" members might be also needed and used even when
>
> it's a stable rmap_item. In should_skip_rmap_item(), if its page is KSM, it can't be skip.

Yes, needs some more thought on details. We might have to ignore/skip
the fields for stable tree entries that have not a KSM page.

>
> What if the rmap_item is stable, but its page is not KSM?

I guess that would happen if we had a rmap_item at that address, and
then changed the page (e.g., COW).

ksm_do_scan() would call cmp_and_merge_page() after obtaining such an
rmap item from scan_get_next_rmap_item().

In cmp_and_merge_page() we'd call remove_rmap_item_from_tree() and
recalculate the checksum.

In remove_rmap_item_from_tree() we remove the item from the stable tree.

So we'd want to ignore the entries in STABLE_FLAG in
scan_get_next_rmap_item() to then reinitialize the fields in
cmp_and_merge_page() after remove_rmap_item_from_tree() I guess.

--
Cheers,

David