lib: Do not fail a test if oom score cannot be adjusted.
PATCH v2 1/1 lib: Do not fail a test if oom score cannot be adjusted.
From: Petr Vorel <[email protected]>
Setting value < 0 in /proc/*/oom_score_adj requires CAP_SYS_RESOURCE or CAP_SYS_ADMIN. However setting the library process score is a best effort operation, so let's skip it silently when the user is not privileged to do so.
--- include/tst_memutils.h | 6 ++++- lib/tst_memutils.c | 55 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 9 deletions(-)
include/tst_memutils.h +5 -1
@@ -28,13 +28,17 @@ long long tst_available_mem(void);/* * Enable OOM protection to prevent process($PID) being killed by OOM Killer. * echo -1000 >/proc/$PID/oom_score_adj +* * If the pid is 0 which means it will set on current(self) process. * +* Unless the process has CAP_SYS_RESOURCE or CAP_SYS_ADMIN this call will be +* no-op because setting adj value < 0 requires it. +* * Note: * This exported tst_enable_oom_protection function can be used at anywhere * you want to protect, but please remember that if you do enable protection * on a process($PID) that all the children will inherit its score and be -* ignored by OOM Killer as well. So that's why tst_disable_oom_protection +* ignored by OOM Killer as well. So that's why tst_disable_oom_protection() * to be used in combination. */ void tst_enable_oom_protection (pid_t pid);
lib/tst_memutils.c +47 -8
76 lines not on this page · raw message
Signature · 5 lines
2.32.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril, all,
Quoted 6 lines
From: Petr Vorel <[email protected]>
Setting value < 0 in
/proc/*/oom_score_adjrequiresCAP_SYS_RESOURCEorCAP_SYS_ADMIN. However setting the library process score is a best effort operation, so let's skip it silently when the user is not privileged to do so.
+1
LGTM, thanks for this version, I'm for merging it.
Also tested locally and on CI, working as expected.
https://github.com/pevik/ltp/runs/4607602484?check_suite_focus=true
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr, All
Quoted 6 lines
Hi Cyril, all,
Quoted 4 lines
From: Petr Vorel<[email protected]>
Setting value< 0 in
/proc/*/oom_score_adjrequiresCAP_SYS_RESOURCEorCAP_SYS_ADMIN.
Here will mislead user.
Since the default oom_score_adj value is 0, so we can not set a value < 0.
The value of /proc/<pid>/oom_score_adj may be reduced no lower than the last value set by a CAP_SYS_RESOURCE process. To reduce the value any lower requires CAP_SYS_RESOURCE.
Also looks man 7 capabilities, CAP_SYS_ADMIN doesn't have this cap and I have do a test to verify this
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include "tst_test.h"
#include "tst_capability.h"
static void run(void)
{
FILE *f;
f = fopen("/proc/self/oom_score_adj", "w");
if (!f)
tst_res(TFAIL, "non-exist");
if (fprintf(f, "%d", -200) <= 0)
tst_res(TFAIL, "write failed");
if (fclose(f))
tst_res(TFAIL, "close %d",errno);
tst_res(TPASS, "write pass");
}static struct tst_test test = {
.test_all = run,
.caps = (struct tst_cap []) {
TST_CAP(TST_CAP_REQ, CAP_SYS_ADMIN),
TST_CAP(TST_CAP_DROP, CAP_SYS_RESOURCE),
{}
},
};It still fails if we only have CAP_SYS_ADMIN.
Best Regards
Yang Xu
However setting the library process score is a best
Quoted 11 lines
Quoted 2 lines
effort operation, so let's skip it silently when the user is not privileged to do so.
+1
LGTM, thanks for this version, I'm for merging it.
Also tested locally and on CI, working as expected.
https://github.com/pevik/ltp/runs/4607602484?check_suite_focus=trueKind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi All,
Quoted 8 lines · On Thu, Dec 23, 2021 at 9:17 AM [email protected]…
Quoted 2 lines
Quoted 2 lines
Setting value< 0 in
/proc/*/oom_score_adjrequiresCAP_SYS_RESOURCEorCAP_SYS_ADMIN.Here will mislead user.
Since the defaultoom_score_adjvalue is 0, so we can not set a value < 0.The value of /proc/<pid>/oom_score_adj may be reduced no lower than the last value set by a
CAP_SYS_RESOURCEprocess. To reduce the value any lower requiresCAP_SYS_RESOURCE.
Good to know this, thank you Xu!
From the man page, CAP_SYS_RESOURCE gives:
"
CAP_SYS_RESOURCE
...
* set /proc/[pid]/oom_score_adj to a value lower than
the value last set by a process with CAP_SYS_RESOURCE.
"
I will send a V3 base on Petr and Cyril's work to speed up merging this fix.
Signature · 6 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 lib: Do not fail a test if oom score cannot be adjusted.
From: Petr Vorel <[email protected]>
Setting value < 0 in /proc/<pid>/oom_score_adj requires CAP_SYS_RESOURCE. However setting the library process score is a best effort operation, so let's skip it silently when the user is not privileged to do so.
---
Notes:
v2 --> v3
* drop the useless CAP_SYS_ADMIN
* add some new commments
CI job: https://github.com/wangli5665/ltp/actions/runs/1613852940
include/tst_memutils.h | 10 +++++++- lib/tst_memutils.c | 54 +++++++++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 9 deletions(-)
include/tst_memutils.h +9 -1
@@ -28,13 +28,21 @@ long long tst_available_mem(void);/* * Enable OOM protection to prevent process($PID) being killed by OOM Killer. * echo -1000 >/proc/$PID/oom_score_adj +* * If the pid is 0 which means it will set on current(self) process. * +* Unless the process has CAP_SYS_RESOURCE this call will be no-op because +* setting adj value < 0 requires it. +* +* CAP_SYS_RESOURCE: +* set /proc/[pid]/oom_score_adj to a value lower than the value last set +* by a process with CAP_SYS_RESOURCE. +* * Note: * This exported tst_enable_oom_protection function can be used at anywhere * you want to protect, but please remember that if you do enable protection * on a process($PID) that all the children will inherit its score and be -* ignored by OOM Killer as well. So that's why tst_disable_oom_protection +* ignored by OOM Killer as well. So that's why tst_disable_oom_protection() * to be used in combination. */ void tst_enable_oom_protection (pid_t pid);
lib/tst_memutils.c +46 -8
75 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Li
Quoted 10 lines
From: Petr Vorel<[email protected]>
Setting value< 0 in/proc/<pid>/oom_score_adj requires
CAP_SYS_RESOURCE. However setting the library process score is a best effort operation, so let's skip it silently when the user is not privileged to do so.Fixes 8a0827766d ("lib: add functions to adjust oom score")Signed-off-by Petr Vorel<[email protected]>Signed-off-by Cyril Hrubis<[email protected]>Signed-off-by Li Wang<[email protected]>
Now, LGTM,
ps: ubuntun:groxy fails because of other thing..., it is another problem.
Best Regards
Yang Xu
Quoted 8 lines
---
Notes:
v2 --> v3
* drop the uselessCAP_SYS_ADMIN
* add some new commments
CI job:https://github.com/wangli5665/ltp/actions/runs/1613852940
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 4 lines
Notes:
v2 --> v3
* drop the uselessCAP_SYS_ADMIN
* add some new commments
Yes, CAP_SYS_ADMIN was redundant, thus I merged it. Thanks a lot all.
Quoted 1 line
CI job: https://github.com/wangli5665/ltp/actions/runs/1613852940
Yes, ubuntu cannot reach repos:
Ign:1 http://security.ubuntu.com/ubuntu groovy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu groovy InRelease
Err:3 http://security.ubuntu.com/ubuntu groovy-security Release
404 Not Found [IP: 91.189.91.39 80]
Ign:4 http://archive.ubuntu.com/ubuntu groovy-updates InRelease
Ign:5 http://archive.ubuntu.com/ubuntu groovy-backports InRelease
Err:6 http://archive.ubuntu.com/ubuntu groovy Release
404 Not Found [IP: 91.189.88.142 80]
Err:7 http://archive.ubuntu.com/ubuntu groovy-updates Release
404 Not Found [IP: 91.189.88.142 80]
Err:8 http://archive.ubuntu.com/ubuntu groovy-backports Release
404 Not Found [IP: 91.189.88.142 80]
Reading package lists...
E: The repository 'http://security.ubuntu.com/ubuntu groovy-security Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu groovy Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu groovy-updates Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu groovy-backports Release' does not have a Release file.
I'm testing upgrade to impish:
https://github.com/pevik/ltp/actions/runs/1614667613
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 3 lines
I'm testing upgrade to impish:
Hm, impish is also broken. Hope it's just temporary issue.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp