public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2] lib: Do not fail a test if oom score cannot be adjusted.
Date: Thu, 23 Dec 2021 01:17:24 +0000	[thread overview]
Message-ID: <61C3CE33.5010105@fujitsu.com> (raw)
In-Reply-To: <YcMwRIZcQNH94xhe@pevik>

Hi Petr, All
> Hi Cyril, all,
>
>> From: Petr Vorel<pvorel@suse.cz>
>
>> Setting value<  0 in /proc/*/oom_score_adj requires CAP_SYS_RESOURCE or
>> CAP_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
>> 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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2021-12-23  1:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22 13:52 [LTP] [PATCH v2] lib: Do not fail a test if oom score cannot be adjusted Cyril Hrubis
2021-12-22 14:03 ` Petr Vorel
2021-12-23  1:17   ` xuyang2018.jy [this message]
2021-12-23  2:13     ` Li Wang
2021-12-23  2:48       ` [LTP] [PATCH v3] " Li Wang
2021-12-23  3:03         ` xuyang2018.jy
2021-12-23  7:57         ` Petr Vorel
2021-12-23  8:29           ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61C3CE33.5010105@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox