Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k8s mem stat #253

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

ShirleyFei
Copy link
Contributor

No description provided.

To collect k8s memory cgroup statistics, we should check the
cgroup version, and then read corresponding memcg path.

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
The kubelet will terminate end-user pods when the worker node has
'MemoryPressure' according to [1]. But confusingly, there exits two
reasons for pods being evicted:
- one is the whole machine's free memory is too low,
- the other is k8s itself calculation[2], e.i. memory.available[3]
  is too low.

To resolve such confusion for k8s users, collect and show k8s global
workingset memory to distinguish between these two causes.

Note:
1. Only collect k8s global memory stats is enough, this is because
   cgroupfs stats are propagated from child to parent. Thus the
   parent can always notice the change and then updates. And From
   v1.6 k8s[4], allocatable(/sys/fs/cgroup/memory/kubepods/) is more
   convincing than capacity(/sys/fs/cgroup/memory/).
2. There are two cgroup drivers or managers to control resources:
   cgroupfs and systemd[5]. We should take both into account.
   (The 'systemd' cgroup driver always ends with '.slice')
3. The difference between cgroupv1 and cgroupv2: different field names
   for memory.stat file, and memory.currentUsage storing in different
   files (cgv1's memory.usage_in_bytes v.s. cgv2's memory.current).

[1]https://kubernetes.io/docs/concepts/scheduling-eviction/node-pressure-eviction/#node-out-of-memory-behavior
[2]kubernetes/kubernetes#43916
[3]memory.available = memory.allocatable/capacity - memory.workingSet,
   memory.workingSet = memory.currentUsage - memory.inactivefile
[4]kubernetes/kubernetes#42204
   kubernetes/community#348
[5]https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/

Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
Reported-by: Teng Hu <huteng.ht@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant