Package: archipel-agent-virtualmachine-oomkiller Severity: normal Tags: patch
Hi, I am not sure where the upstream code sits for this package so I am reporting it to distribution. Let me know if I should post the patch somewhere else. Anyway oom_adj is long deprecated and shouldn't be used. The attached patch uses oom_score_adj in preference to oom_adj. I hope I got everything right because I am not familiar with python. I also didn't know how to set up things to test it properly so it might be broken but it should at least give an idea how to do the fix. -- System Information: Debian Release: stretch/sid APT prefers testing APT policy: (500, 'testing'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 4.3.0-rc7 (SMP w/2 CPU cores; PREEMPT) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: sysvinit (via /sbin/init) -- Michal Hocko
From: Michal Hocko <[email protected]> Subject: use oom_score_adj instead of deprecated oom_adj We are trying to get rid of oom_adj in the kernel. It has been deprecated since 2.6.36. Let's use oom_score_adj preferably and fallback to oom_adj when the former is not present (if used on older systems). As the values stored in the DB expectes only oom_adj values we have to recalculate it to oom_score_adj scale (this is taken from fs/proc/base.c:oom_adj_write from the kernel source tree). Signed-off-by: Michal Hocko <[email protected]> Index: archipel-agent-virtualmachine-oomkiller-0.6.0/archipelagentvirtualmachineoomkiller/oomkiller.py =================================================================== --- archipel-agent-virtualmachine-oomkiller-0.6.0.orig/archipelagentvirtualmachineoomkiller/oomkiller.py +++ archipel-agent-virtualmachine-oomkiller-0.6.0/archipelagentvirtualmachineoomkiller/oomkiller.py @@ -149,6 +149,45 @@ class TNOOMKiller (TNArchipelPlugin): score_value = 0 return {"adjust": adj_value, "score": score_value} + def try_set_oom_score_adj(pid, adjust) + """ + Tries to scale and store given oom_adj value into /proc/<pid>/oom_score_adj + @type pid: int + @param pid: pid of the process to set + @type adjust: int + @param adjust: the value of adjust + """ + try: + f = open("/proc/%d/oom_score_adj" % pid, "w") + OOM_ADJUST_MAX = 15 + OOM_SCORE_ADJ_MAX = 1000 + OOM_DISABLE = -17 + if (adjust == OOM_ADJUST_MAX) + adjust = OOM_ADJUST_MAX + else + adjust = (adjust * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE + f.write(str(adjust)) + f.close() + except Exception as ex: + return 0 + return 1 + + def set_oom_adj(pid, adjust) + """ + Tries to store given oom_adj value into /proc/<pid>/oom_adj + @type pid: int + @param pid: pid of the process to set + @type adjust: int + @param adjust: the value of adjust + """ + try: + f = open("/proc/%d/oom_adj" % pid, "w") + f.write(str(adjust)) + f.close() + except Exception as ex: + return 0 + return 1 + def set_oom_info(self, adjust, score): """ Set the OOM info both on file if exists and on database. @@ -159,11 +198,9 @@ class TNOOMKiller (TNArchipelPlugin): """ try: pid = int(commands.getoutput("ps -ef | grep kvm | grep %s | grep -v grep" % self.entity.uuid).split()[1]) - f = open("/proc/%d/oom_adj" % pid, "w") - f.write(str(adjust)) - f.close() - except Exception as ex: - self.entity.log.warning("OOM: No valid PID. storing value only on database: " + str(ex)) + if (!try_set_oom_score_adj(pid, adjust)) + if (!set_oom_adj(pid, adjust)) + self.entity.log.warning("OOM: No valid PID. storing value only on database: " + str(ex)) try: self.database.execute("INSERT INTO oomkiller VALUES (?, ?)", (self.entity.uuid, int(adjust))) except: @@ -232,4 +269,4 @@ class TNOOMKiller (TNArchipelPlugin): self.entity.push_change("oom", "adjusted") except Exception as ex: reply = build_error_iq(self, ex, iq) - return reply \ No newline at end of file + return reply

