Re: KVM architecture docs

Avi Kivity
2008-03-05T06:10:23Z

Zhao Forrest wrote:
>>> Normally swapping mechanism choose the Least Recently Used(LRU) pages
>>> of a process to be swapped out. When KVM uses MMU notifier in linux
>>> kernel to implement swapping for VM, could KVM choose LRU pages of a
>>> VM to swap out? If so, could you give a brief description about how
>>> this is implemented?
>>>
>>>
>> The Linux memory manager approximates LRU by scanning pages for the
>> accessed bit, which is set in the pte by the processor when a page is
>> accessed through that pte. mmu notifiers provide a callback for the
>> check, so that kvm can check the accessed bit on the shadow ptes.
>>
>
> If I understand correctly, when NPT is used by KVM in the future, this mmu
> notifier can't help much for swapping out pages used by VM, right?
>

No, NPT does not change things materially. Shadow page tables are still
used, though instead of mapping guest virtual addresses to host physical
addresses, they now translate guest physical addresses to host physical
addresses. Swapping and all the other goodies still work.

> That is, when NPT is used, a balloon para-virt driver running on gust
> OS might be more efficient for swapping, am I right?
>

Ballooning is more efficient than swapping both with and without NPT.
The problem with ballooning is that it requires guest cooperation. The
guest may not be able to balloon, or it may take a long time to balloon,
while the host may need the memory immediately. A rebooting guest also
implicitly deflates its balloon, creating a large and unpredictable
memory demand on the host.

A good solution needs to use ballooning with swapping as a fallback for
guaranteeing that the system does not run out of memory.

A nice feature in 2.6.25 is the ability to select which guests will
swap, via the memory controller feature (mlock() also works, but is
relatively crude).

--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.