Skip to content

Commit

Permalink
Fix oom-score-adj test due to no permission (#12887)
Browse files Browse the repository at this point in the history
Fix #12792

On ubuntu 23(lunar), non-root users will not be allowed to change the
oom_score_adj of a process to a value that is too low.
Since terminal's default oom_score_adj is 200, if we run the test on
terminal, we won't be able to set the oom_score_adj of the redis process
to 9 or 22, which is too low.

Reproduction on ubuntu 23(lunar) terminal:
```sh
$ cat /proc/`pgrep redis-server`/oom_score_adj
200
$ echo 100 > /proc/`pgrep redis-server`/oom_score_adj
# success without error
$ echo 99 > /proc/`pgrep redis-server`/oom_score_adj
echo: write error: Permission denied
```

As from the output above, we can only set the minimum oom score of redis
processes to 100.
By modifying the test, make oom_score_adj only increase upwards and not
decrease.

---------

Co-authored-by: debing.sun <[email protected]>
  • Loading branch information
2 people authored and madolson committed Apr 7, 2024
1 parent a66a239 commit 9706ca6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/unit/oom-score-adj.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,27 @@ if {$system_name eq {linux}} {

test {CONFIG SET oom score restored on disable} {
r config set oom-score-adj no
set_oom_score_adj 22
assert_equal [get_oom_score_adj] 22
set custom_oom [expr [get_oom_score_adj] + 1]
set_oom_score_adj $custom_oom
assert_equal [get_oom_score_adj] $custom_oom

r config set oom-score-adj-values "9 9 9" oom-score-adj yes
assert_equal [get_oom_score_adj] [expr 9+22]
assert_equal [get_oom_score_adj] [expr 9+$custom_oom]

r config set oom-score-adj no
assert_equal [get_oom_score_adj] 22
assert_equal [get_oom_score_adj] $custom_oom
}

test {CONFIG SET oom score relative and absolute} {
set custom_oom 9
r config set oom-score-adj no
set base_oom [get_oom_score_adj]

set custom_oom 9
r config set oom-score-adj-values "$custom_oom $custom_oom $custom_oom" oom-score-adj relative
assert_equal [get_oom_score_adj] [expr $base_oom+$custom_oom]

r config set oom-score-adj absolute
set custom_oom [expr [get_oom_score_adj] + 1]
r config set oom-score-adj-values "$custom_oom $custom_oom $custom_oom" oom-score-adj absolute
assert_equal [get_oom_score_adj] $custom_oom
}

Expand Down

0 comments on commit 9706ca6

Please sign in to comment.