[RHEL8,COMMIT] oom: make berserker more aggressive

Submitted by Konstantin Khorenko on Dec. 21, 2020, 4:49 p.m.

Details

Message ID 202012211649.0BLGnXie227085@finist-co8.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Dec. 21, 2020, 4:49 p.m.
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.3
------>
commit 89c9c96179c7c59ca937010420c590e38fa1bf30
Author: Vladimir Davydov <vdavydov.dev@gmail.com>
Date:   Mon Dec 21 19:49:33 2020 +0300

    oom: make berserker more aggressive
    
    In the berserker mode we kill a bunch of tasks that are as bad as the
    selected victim. We assume two tasks to be equally bad if they consume
    the same permille of memory. With such a strict check, it might turn out
    that oom berserker won't kill any tasks in case a fork bomb is running
    inside a container while the effect of killing a task eating <=1/1000th
    of memory won't be enough to cope with memory shortage. Let's loosen
    this check and use percentage instead of permille. In this case, it
    might still happen that berserker won't kill anyone, but in this case
    the regular oom should free at least 1/100th of memory, which should be
    enough even for small containers.
    
    Also, check berserker mode even if the victim has already exited by the
    time we are about to send SIGKILL to it. Rationale: when the berserker
    is in rage, it might kill hundreds of tasks so that the next oom kill is
    likely to select an exiting task. Not triggering berserker in this case
    will result in oom stalls.
    
    Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
    
    [aryabinin: rh8 rebase]
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/oom_kill.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 353fb22da98c..366ec5be9107 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -1024,11 +1024,11 @@  static void oom_berserker(struct oom_control *oc)
 			continue;
 
 		/*
-		 * Consider tasks as equally bad if they have equal
-		 * normalized scores.
+		 * Consider tasks as equally bad if they occupy equal
+		 * percentage of available memory.
 		 */
-		if (tsk_points * 1000 / oc->totalpages <
-			oc->chosen_points * 1000 / oc->totalpages)
+		if (tsk_points * 100 / oc->totalpages <
+			oc->chosen_points * 100 / oc->totalpages)
 			continue;
 
 		if (__ratelimit(&berserker_rs)) {
@@ -1069,6 +1069,7 @@  static void oom_kill_process(struct oom_control *oc, const char *message)
 		wake_oom_reaper(victim);
 		task_unlock(victim);
 		put_task_struct(victim);
+		oom_berserker(oc);
 		return;
 	}
 	task_unlock(victim);