-
Notifications
You must be signed in to change notification settings - Fork 15
[PROPOSAL] [RFC] KSM throttler #168
Description
Definition
Kernel Same-page Merging (KSM) throttling is the process of regulating the KSM daemon by dynamically modifying the KSM sysfs entries, in order to minimize memory duplication as fast as possible while keeping the KSM daemon load low.
KSM throttling currently uses container creation events as its single input.
Problem statement
Today's KSM throttling is part of the Clear Containers proxy code and is a passive component (i.e. it needs to be notified by other parts of the code). That is problematic for 2 main reasons:
-
KSM throttling depends on a system wide proxy daemon to be running. As Clear Containers is moving towards a one proxy per VM architecture, the proxy code will no longer have a system wide view and will thus no longer be able to trigger the KSM throttling routine based on the overall container creation activity.
-
The current KSM throttling code is very much Clear Containers proxy specific. It can not be extracted from the code base because it's passive, i.e. it relies on being actually called from other parts of the proxy implementation. It can also not be made a separate standalone component without callers modifying their code to call into a KSM throttling specific API.
Proposal
This proposal is about creating a generic, Clear Containers agnostic and active KSM throttling service: the KSM throttler.
Clear Containers agnostic
The KSM throttler will not be dependent on any Clear Containers piece of code, API or architecture design. As a matter of fact, we believe that a KSM throttler could not only benefit VM based containers but also generic/legacy VM based workloads where the goal would be to minimize memory duplication as quickly as possible.
Active component
The KSM throttler will by default be an active component, checking for different system wide values and settings in order to build informed KSM throttling decisions. In other words KSM throttler will by default not have to be explictly triggered by e.g. a VM based container runtime or proxy but will instead be actively watching for specific information about VM or VM based containers life cycles.
Passive Fallback
When a system can not provide a reliable source of information about VM life cycles, KSM throttler will provide a passive UNIX socket for components like container runtimes to notify it about VM or container specific events (creation, destruction, etc...)
Implementation
The KSM throttler implementation can be split into 2 parts: The throttling algorithm and the input sources handling.
Input sources
The KSM throttler will be able to handle several input sources and one should be able to add a new input source implementation to the source code fairly easily.
In practice, a KSM throttling input source will watch any specific system wide component and will notify the KSM throttler about any new VM or VM based containers life cycle event. The KSM throttler is a server and all input sources are potential clients.
We will use the gRPC protocol between the throttler and its clients, defined by the following proto file:
service KSMThrottler {
rpc Register(RegisterRequest) returns (Empty) {}
rpc Events(stream VMEvent) returns (stream VMEvent) {}
}
message RegisterRequest {
string name = 1;
}
enum EventType {
CREATING = 0;
CREATED = 1;
DESTROYING = 2;
DESTROYED = 3;
}
message VMEvent {
string vm_id = 1;
EventType type = 2;
}
Each KSM throttler input source would first register against KSM throttler and then send a stream of events.
KSM Throttling
The initial throttling algorithm will follow the current proxy one, where we throttle KSM up on each VM creation and then progressively throttle it down as long as there are no new VM creation.
Phases
The implementation will follow an incremental process going through a few phases:
Phase 1: virtcontainers compatibility
The virtcontainers KSM throttler input source will be watching the virtcontainers pod filesystem through inotify in order to understand whenever a new Pod is created or destroyed.