# Cgroup泄露2

## 现象描述

 1  mkdir /sys/fs/cgroup/memory/kubepods/burstable/pod79fe803c-072f-11e9-90ca-525400090c71/b98d4aea818bf9d1d1aa84079e1688cd9b4218e008c58a8ef6d6c3c106403e7b: no space left on devic 

## 如何查看泄漏程度

 1  cat /proc/cgroups 

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  # usage : stap -g get_memcg_count.stp %{ #include #include #include /* The embedded c function must have a return value. * If it doesn't has an argument, we must use a specified void here. */ int get_memcg_count(void) { struct cgroup_subsys_state *tmp; int count = 1; int i; rcu_read_lock(); for (i = 1; i < 65536; i++) { tmp = css_lookup(&mem_cgroup_subsys, i); if (tmp) count++; } rcu_read_unlock(); return count; } %} function do_calc:long() %{ int count = 0; count = get_memcg_count(); STAP_RETVALUE = count; %} probe begin { printf("probe begin\n"); printf("count %ld\n", do_calc()); exit(); } probe end { printf("probe end\n"); } 

## 如何引入 & 如何解决

https://github.com/moby/moby/issues/29638 https://tencentcloudcontainerteam.github.io/2018/12/29/cgroup-leaking/ http://www.linuxfly.org/kubernetes-19-conflict-with-centos7/?from=groupmessage

## cgroup迁移

cgroup 本身是支持cgroup迁移功能的

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  4.2 Task migration When a task migrates from one cgroup to another, its charge is not carried forward by default. The pages allocated from the original cgroup still remain charged to it, the charge is dropped when the page is freed or reclaimed. You can move charges of a task along with task migration. See 8. "Move charges at task migration" This feature is disabled by default. It can be enabledi (and disabled again) by writing to memory.move_charge_at_immigrate of the destination cgroup. If you want to enable it: # echo (some positive value) > memory.move_charge_at_immigrate Note: Each bits of move_charge_at_immigrate has its own meaning about what type of charges should be moved. See 8.2 for details. Note: Charges are moved only when you move mm->owner, in other words, a leader of a thread group. Note: If we cannot find enough space for the task in the destination cgroup, we try to make space by reclaiming memory. Task migration may fail if we cannot make enough space. Note: It can take several seconds if you move charges much.