[RHEL7,COMMIT] mm, memcg, oom_gurantee: change memcg oom overdraft formula

Submitted by Konstantin Khorenko on April 30, 2019, 10:54 a.m.

Details

Message ID 201904301054.x3UAs1aW020597@finist-ce7.sw.ru
State New
Series "mm, memcg, oom_gurantee: change memcg oom overdraft formula"
Headers show

Commit Message

Konstantin Khorenko April 30, 2019, 10:54 a.m.
The commit is pushed to "branch-rh7-3.10.0-957.12.1.vz7.95.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.1.vz7.95.2
------>
commit a0d70492a4e287879ed4456e7c76c8a298d52287
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Tue Apr 30 13:54:00 2019 +0300

    mm, memcg, oom_gurantee: change memcg oom overdraft formula
    
    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>
    Reviewed-by: Konstantin Khorenko <khorenko@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 4d520b570687..5a0641a38835 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)