KSM Management¶
Kernel Samepage Merging (KSM) allows de-duplication of memory. KSM tries to find identical Memory Pages and merge those to free memory.
Further Information:
- KSM (Kernel Samepage Merging) feature
- Kernel Same-page Merging (KSM)
Enabling KSM through KubeVirt CR¶
KSM can be enabled on nodes by spec.configuration.ksmConfiguration
in the KubeVirt CR.
ksmConfiguration
instructs on which nodes KSM will be enabled, exposing a nodeLabelSelector
.
nodeLabelSelector
is a LabelSelector
and defines the filter, based on the node labels. If a node's labels match the label selector term,
then on that node, KSM will be enabled.
NOTE
IfnodeLabelSelector
is nil KSM will not be enabled on any nodes.
EmptynodeLabelSelector
will enable KSM on every node.
Examples:¶
-
Enabling KSM on nodes in which the hostname is
node01
ornode03
: -
Enabling KSM on nodes with labels
kubevirt.io/first-label: true
,kubevirt.io/second-label: true
: -
Enabling KSM on every node:
Annotation and restore mechanism¶
On those nodes where KubeVirt enables the KSM via configuration, an annotation will be
added (kubevirt.io/ksm-handler-managed
).
This annotation is an internal record to keep track of which nodes are currently
managed by virt-handler, so that it is possible to distinguish which nodes should be restored
in case of future ksmConfiguration changes.
Let's imagine this scenario:
- There are 3 nodes in the cluster and one of them(
node01
) has KSM externally enabled. - An admin patches the KubeVirt CR adding a ksmConfiguration which enables ksm for
node02
andnode03
. - After a while, an admin patches again the KubeVirt CR deleting the ksmConfiguration.
Thanks to the annotation, the virt-handler is able to disable ksm on only those nodes where it
itself had enabled it(node02
node03
), leaving the others unchanged (node01
).
Node labelling¶
KubeVirt can discover on which nodes KSM is enabled and will mark them
with a special label (kubevirt.io/ksm-enabled
) with value true
.
This label can be used to schedule the vms in nodes with KSM enabled or not.