[LTP] [PATCH v3 1/3] lib: add functions to adjust oom score
Cyril Hrubis
chrubis@suse.cz
Tue Dec 21 11:36:16 CET 2021
Hi!
> So, I will push (the improved) code like below, after getting
> Petr and you ack again:
>
> +static void set_oom_score_adj(pid_t pid, int value)
> +{
> + int val;
> + char score_path[64];
> +
> + if (access("/proc/self/oom_score_adj", F_OK) == -1) {
> + tst_res(TINFO, "Warning: oom_score_adj does not exist,
> + skipping the adjustement");
I'm not sure about the "Warning:" in this message, I would just dully
informed the user that the interface is not available.
> + return;`
> + }
> +
> + if (pid == 0) {
> + sprintf(score_path, "/proc/self/oom_score_adj");
> + } else {
> + sprintf(score_path, "/proc/%d/oom_score_adj", pid);
> + if (access(score_path, F_OK) == -1)
> + tst_brk(TBROK, "%s does not exist, please
> check if PID is valid", score_path);
> + }
> +
> + FILE_PRINTF(score_path, "%d", value);
> + FILE_SCANF(score_path, "%d", &val);
> +
> + if (val != value) {
> + if (value < 0) {
> + tst_res(TWARN, "'%s' cannot be set to %i, are
> you root?",
> + score_path, value);
> + return
> + }
> + tst_brk(TBROK, "oom_score_adj = %d, but expect %d.",
> val, value);
> + }
> +}
Anyways this version looks good to me:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list