Skip to content

Commit

Permalink
Remove -i flag
Browse files Browse the repository at this point in the history
Kernel 5.9 changed how oom_score_adj works, and
I don't think this feature is worth having kernel
version detection to make it work on older & newer
kernels. Just drop it.

Fixes #234
  • Loading branch information
rfjakob committed May 7, 2021
1 parent 280dade commit 7ebc455
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 63 deletions.
2 changes: 1 addition & 1 deletion MANPAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Send SIGKILL if at or below KILL_SIZE (default SIZE/2), otherwise SIGTERM.
removed in earlyoom v1.2, ignored for compatibility

#### -i
user-space oom killer should ignore positive oom_score_adj values
removed in earlyoom v1.7, ignored for compatibility

#### -d
enable debugging messages
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ Changelog
---------
* vNEXT
* Add `-g` flag to kill whole process group ([#247](https://github.com/rfjakob/earlyoom/pull/247))
* Remove `-i` flag (ignored for compatibility), it does
not work properly on Linux kernels 5.9+ ([#234](https://github.com/rfjakob/earlyoom/issues/234))

* v1.6.2, 2020-10-14
* Double-check memory situation before killing victim ([commit](https://github.com/rfjakob/earlyoom/commit/e34e0fcec5d9f60eb19a48a3ec2bab175818fdd8))
Expand Down
11 changes: 0 additions & 11 deletions kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,6 @@ procinfo_t find_largest_process(const poll_loop_args_t* args)
}
cur.badness = res;
}
if (args->ignore_oom_score_adj) {
int oom_score_adj = 0;
int res = get_oom_score_adj(cur.pid, &oom_score_adj);
if (res < 0) {
debug(" error reading oom_score_adj: %s\n", strerror(-res));
continue;
}
if (oom_score_adj > 0) {
cur.badness -= oom_score_adj;
}
}

if ((args->prefer_regex || args->avoid_regex)) {
int res = get_comm(cur.pid, cur.name, sizeof(cur.name));
Expand Down
2 changes: 0 additions & 2 deletions kill.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ typedef struct {
double mem_kill_percent;
double swap_term_percent;
double swap_kill_percent;
/* ignore /proc/PID/oom_score_adj? */
bool ignore_oom_score_adj;
/* send d-bus notifications? */
bool notify;
/* kill all processes within a process group */
Expand Down
3 changes: 1 addition & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "Option -k is ignored since earlyoom v1.2\n");
break;
case 'i':
args.ignore_oom_score_adj = 1;
fprintf(stderr, "Ignoring positive oom_score_adj values (-i)\n");
fprintf(stderr, "Option -i is ignored since earlyoom v1.7\n");
break;
case 'n':
args.notify = true;
Expand Down
48 changes: 1 addition & 47 deletions testsuite_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"io/ioutil"
"math"
"os/exec"
"regexp"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -105,7 +103,7 @@ func TestCli(t *testing.T) {
// Test --avoid and --prefer
{args: []string{"--avoid", "MyProcess1"}, code: -1, stderrContains: "Will avoid killing", stdoutContains: memReport},
{args: []string{"--prefer", "MyProcess2"}, code: -1, stderrContains: "Preferring to kill", stdoutContains: memReport},
{args: []string{"-i"}, code: -1, stderrContains: "Ignoring positive oom_score_adj values"},
{args: []string{"-i"}, code: -1, stderrContains: "Option -i is ignored"},
// Extra arguments should error out
{args: []string{"xyz"}, code: 13, stderrContains: "extra argument not understood", stdoutEmpty: true},
{args: []string{"-i", "1"}, code: 13, stderrContains: "extra argument not understood", stdoutEmpty: true},
Expand Down Expand Up @@ -216,47 +214,3 @@ func TestRss(t *testing.T) {
}
t.Logf("earlyoom RSS: %d kiB", res.rss)
}

// TestI tests that `earlyoom -i` works as expected
func TestI(t *testing.T) {
cmd := exec.Command("sleep", "60")
err := cmd.Start()
if err != nil {
t.Fatal(err)
}
defer cmd.Process.Kill()
path := fmt.Sprintf("/proc/%d/oom_score_adj", cmd.Process.Pid)
err = ioutil.WriteFile(path, []byte("1000"), 0600)
if err != nil {
t.Fatal(err)
}
res := runEarlyoom(t, "-d")
// We should see a line like this:
// pid 2308155: badness 1000 vm_rss 708 uid 1026 "sleep" <--- new victim
// Or, for some reason, this:
// pid 6950: badness 999 vm_rss 772 uid 1026 "sleep" <--- new victim
matched := false
for _, b := range []int{1000, 999} {
pattern := fmt.Sprintf(`pid\s+%d: badness %d`, cmd.Process.Pid, b)
matched, err = regexp.MatchString(pattern, res.stdout)
if err != nil {
t.Fatal(err)
}
if matched {
break
}
}
if !matched {
t.Error("did not see badness 1000 or 999 in output")
t.Log(res.stdout)
}
res = runEarlyoom(t, "-d", "-i")
pattern := fmt.Sprintf(`pid\s+%d: badness %d`, cmd.Process.Pid, 1000)
matched, err = regexp.MatchString(pattern, res.stdout)
if err != nil {
t.Fatal(err)
}
if matched {
t.Error("saw badness 1000, but should not have")
}
}

0 comments on commit 7ebc455

Please sign in to comment.