On 2025-02-28 10:10, David Hildenbrand wrote:
[...]
For example, QEMU will mark all guest memory is mergeable using MADV, to
limit the deduplicaton to guest RAM only.
On a related note, I think the madvise(2) documentation is inaccurate.
It states:
MADV_MERGEABLE (since Linux 2.6.32)
Enable Kernel Samepage Merging (KSM) for the pages in the range
specified by addr and length. [...]
AFAIU, based on code review of ksm_madvise(), this is not strictly true.
The KSM implementation enables KSM for pages in the entire vma containing the range.
So if it so happens that two mmap areas with identical protection flags are merged,
both will be considered mergeable by KSM as soon as at least one page from any of
those areas is made mergeable.