Using Dynamic MPAM Isolation
You can use the dynamic MPAM isolation function to adjust the resource usage of some offline services.
(Optional) Configuring Dynamic MPAM Isolation Parameters
The plugin provides default configurations. Dynamic MPAM isolation can be used without configuring configMaps. Dynamic MPAM isolation parameters are configured in a JSON file. For details about the parameters, see Table 1. To manually change the configurations, refer to the following content.
{
"mpamConfig":{
"adjustInterval": 5000,
"perfDuration": 3000,
"l3Percent": {
"low": 20,
"high": 50
},
"memBandPercent": {
"low": 10,
"high": 50
},
"cacheMiss": {
"minMiss": 10,
"maxMiss": 50
}
}
}
|
Parameter |
Description |
|---|---|
|
adjustInterval |
Interval between dynamic adjustments. For example, if this parameter is set to 1000, dynamic adjustment is performed every second. |
|
perfDuration |
Perf collection duration. For example, if this parameter is set to 1000, perf will collect data within one second each time. |
|
l3Percent |
Maximum and minimum L3 cache percentages that can be used by offline services during dynamic adjustment. For example, if low is set to 20 and high is set to 50, offline services can use at least 20% and at most 50% of L3 CacheWay during dynamic adjustment. |
|
memBandPercent |
Maximum and minimum memory bandwidth percentages that can be used by offline services during dynamic adjustment. For example, if low is set to 10 and high is set to 50, offline services can use at least 10% and at most 50% of the memory bandwidth during dynamic adjustment. |
|
cacheMiss |
Basis for determining whether to perform dynamic adjustment. For example, if minMiss is set to 10 and maxMiss is set to 50, the available resources of offline services are reduced when the cache miss rate of online services is greater than 50%, and are increased when the cache miss rate of online services is less than 10%. |
A JSON file is configured in the form of configMap in the k8s-mpam-controller.yaml file. The complete YAML file is as follows:
apiVersion: v1
kind: ServiceAccount
metadata:
name: mpam-controller-agent
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: mpam-controller-agent
rules:
- apiGroups:
- ""
resources:
- configmaps
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: mpam-controller-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: mpam-controller-agent
subjects:
- kind: ServiceAccount
name: mpam-controller-agent
namespace: default
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mpam-config
data:
config.json: |
{
"mpamConfig":{
"adjustInterval": 10000,
"perfDuration": 3000,
"l3Percent": {
"low": 20,
"high": 50
},
"memBandPercent": {
"low": 10,
"high": 50
},
"cacheMiss": {
"minMiss": 10,
"maxMiss": 30
}
}
}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: mpam-controller-daemonset-agent
spec:
selector:
matchLabels:
app: k8s-mpam-controller-agent
template:
metadata:
labels:
app: k8s-mpam-controller-agent
spec:
serviceAccountName: mpam-controller-agent
hostPID: true
hostIPC: true
containers:
- name: k8s-mpam-controller-agent
image: k8s-mpam-controller:0.1
securityContext:
privileged: true
command: ["/usr/bin/agent"]
args: ["-direct"]
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
env:
- name: NODE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
volumeMounts:
- name: resctrl
mountPath: /sys/fs/resctrl/
- name: hostname
mountPath: /etc/hostname
- name: sysfs
mountPath: /sys/fs/cgroup/
- name: config-volume
mountPath: /var/lib/mpam-config
volumes:
- name: resctrl
hostPath:
path: /sys/fs/resctrl/
- name: hostname
hostPath:
path: /etc/hostname
- name: sysfs
hostPath:
path: /sys/fs/cgroup/
- name: config-volume
configMap:
name: mpam-config
items:
- key: config.json
path: config.json
After the dynamic MPAM isolation function is enabled, the plugin creates the mpam-controller_dynamic directory in the directory, as shown in the following figure.

Deploying Offline Services
- Add the annotation kunpeng.com/offline: "true" to the YAML file of the Pod to label the Pod as an offline service so that the plugin can restrict the Pod. The following is a bw-mem.yaml file example.
apiVersion: v1 kind: Pod metadata: name: bw-mem annotations: kunpeng.com/offline: "true" spec: containers: - name: bw-mem image: bw-mem:latest imagePullPolicy: IfNotPresent command: [ "/bin/sh", "-c", "--" ] args: [ "while true; do sleep 300000; done;" ] securityContext: capabilities: add: ["ALL"] resources: requests: cpu: "9.6" limits: cpu: "9.6" - Deploy the offline service to be restricted.
kubectl apply -f bw-mem.yaml
After the deployment is successful, the PID of the offline service is added to tasks in the mpam-controller_dynamic control group.
- Run the following commands to check PIDs of restricted offline services:
cd /sys/fs/resctrl/mpam-controller_dynamic cat tasks