[LTP] [PATCH v3 1/3] lib: add functions to adjust oom score

Cyril Hrubis chrubis@suse.cz
Tue Dec 21 10:18:29 CET 2021


Hi!
> > >     v2 --> v3
> > >       * rename to tst_disable_oom_protection
> > >       * support set PID as 0 to protect current process
> >
> > > +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) {
> > We need to check here also /proc/PID/oom_score_adj, i.e. score_path.
> >
> 
> Good catch, I would add a 'W_OK' checking and skip the setting with
> a reminder message if run without root.
> 
> how about this?
> 
> if (access(score_path, W_OK) == -1) {
>         tst_res(TINFO, "Warning: %s cannot be accessed for writing,
>                 please check if test run with root user.",
>                 score_path);

Hmm, I guess that we should produce TINFO if the file does not exist and
TWARN if we cannot write to it. Something as:

if (access(score_path, F_OK)) {
	tst_res(TINFO,
		"'%s' does not exist, skipping OOM score adjustement",
		score_path);
	return;
}

if (access(score_path, W_OK)) {
	tst_res(TWARN, "'%s' not writeable, are you root?", score_path);
	return;
}

>         return
> }
> 
> 
> -- 
> Regards,
> Li Wang

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list