[rh7] mm, memcg, oom_gurantee: change memcg oom overdraft formula

Submitted by Andrey Ryabinin on April 25, 2019, 2:10 p.m.

Details

Message ID 20190425141038.2769-1-aryabinin@virtuozzo.com
State New
Series "mm, memcg, oom_gurantee: change memcg oom overdraft formula"
Headers show

Commit Message

Andrey Ryabinin April 25, 2019, 2:10 p.m.
Currently our oom killer kill tasks from cgroup with max overdraft.
Overdraft formula looks like this "usage/(gurantee + 1)". Which makes
all cgroups without gurantee (default) to be a first candidates for oom
kill since "usage_cgrp1"/"hundreds of megabytes" always < usage_cgrp2/1.

Change overdraft formula to simple "usage > guarantee ? usage - guarantee : 0".

Unrelated note: oom_guarantee is 0 by default and not inherited from parent
cgroup. Not going to change it since currently ther is no necessity for it.
Also this would require from userspace to make sure that oom_guarantee set
for all sub cgroups of cgroups like machine.slice wich has unreacheable high
oom_guarantee and we don't want this high guarantee on sub groups.

https://pmc.acronis.com/browse/VSTOR-22575
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index dc5940bbf026..e69273a5d314 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1995,7 +1995,7 @@  unsigned long mem_cgroup_overdraft(struct mem_cgroup *memcg)
 
 	guarantee = ACCESS_ONCE(memcg->oom_guarantee);
 	usage = page_counter_read(&memcg->memsw);
-	return div64_u64(1000 * usage, guarantee + 1);
+	return usage > guarantee ? (usage - guarantee) : 0;
 }
 
 unsigned long mem_cgroup_total_pages(struct mem_cgroup *memcg, bool swap)