[Devel] [PATCH RHEL8 COMMIT] mm, memcg, oom_gurantee: change memcg oom overdraft formula

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jun 11 20:22:47 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.41
------>
commit f79da6e8f0f06cf17a4bf10bd160feebbb526c74
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Fri Jun 11 20:22:47 2021 +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 at virtuozzo.com>
    Reviewed-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    
    https://jira.sw.ru/browse/PSBM-127846
    (cherry-picked from vz7 commit 0996bb7c7837 ("mm, memcg, oom_gurantee:
    change memcg oom overdraft formula"))
    Fixes: 02ccefe3c24f ("memcg: add oom_guarantee")
    
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 18f90e5467bb..74bad9ff98b9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1364,7 +1364,7 @@ unsigned long mem_cgroup_overdraft(struct mem_cgroup *memcg)
 
 	guarantee = READ_ONCE(memcg->oom_guarantee);
 	usage = page_counter_read(&memcg->memsw);
-	return div64_u64(1000 * usage, guarantee + 1);
+	return usage > guarantee ? (usage - guarantee) : 0;
 }
 
 bool mem_cgroup_dcache_is_low(struct mem_cgroup *memcg, int vfs_cache_min_ratio)


More information about the Devel mailing list