All of lore.kernel.org
 help / color / mirror / Atom feed
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Richard Palethorpe <rpalethorpe@suse.com>,
	"ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH 1/1] lib: Skip tst_{disable, enable}_oom_protection() for non-root
Date: Wed, 22 Dec 2021 02:25:46 +0000	[thread overview]
Message-ID: <61C28CB8.3050209@fujitsu.com> (raw)
In-Reply-To: <20211221193500.31950-1-pvorel@suse.cz>

Hi Petr
> If needed to set value also for non-root, use set_oom_score_adj().
If so, why not rename set_oom_score_adj to tst_set_oom_score_adj and add 
declartion to tst_memutils.h?

ps: also have a word typo in set_oom_score_adj, adjustement => adjustment.

Best Regards
Yang Xu
>
> Fixes: 8a0827766d ("lib: add functions to adjust oom score")
>
> Signed-off-by: Petr Vorel<pvorel@suse.cz>
> ---
>   include/tst_memutils.h | 11 ++++++++++-
>   lib/tst_memutils.c     |  6 ++++++
>   2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/tst_memutils.h b/include/tst_memutils.h
> index 68a6e37714..e6f946ac0c 100644
> --- a/include/tst_memutils.h
> +++ b/include/tst_memutils.h
> @@ -30,11 +30,15 @@ long long tst_available_mem(void);
>    *   echo -1000>/proc/$PID/oom_score_adj
>    * If the pid is 0 which means it will set on current(self) process.
>    *
> + * WARNING:
> + *  Do nothing for non-root, because setting value<  0 requires root.
> +    If you want to set value also for non-root, use set_oom_score_adj().
> + *
>    * 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);
> @@ -42,6 +46,11 @@ void tst_enable_oom_protection(pid_t pid);
>   /*
>    * Disable the OOM protection for the process($PID).
>    *   echo 0>/proc/$PID/oom_score_adj
> + *
> + * WARNING:
> + *  Do nothing for non-root, because it's expected to be cleanup after
> + *  tst_enable_oom_protection(). Use set_oom_score_adj(), if you want to set
> + *  value also for non-root.
>    */
>   void tst_disable_oom_protection(pid_t pid);
>
> diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
> index 4346508d9a..f0695e026a 100644
> --- a/lib/tst_memutils.c
> +++ b/lib/tst_memutils.c
> @@ -126,10 +126,16 @@ static void set_oom_score_adj(pid_t pid, int value)
>
>   void tst_enable_oom_protection(pid_t pid)
>   {
> +	if (geteuid() != 0)
> +		return;
> +
>   	set_oom_score_adj(pid, -1000);
>   }
>
>   void tst_disable_oom_protection(pid_t pid)
>   {
> +	if (geteuid() != 0)
> +		return;
> +
>   	set_oom_score_adj(pid, 0);
>   }

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

  reply	other threads:[~2021-12-22  2:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 19:35 [LTP] [PATCH 1/1] lib: Skip tst_{disable, enable}_oom_protection() for non-root Petr Vorel
2021-12-22  2:25 ` xuyang2018.jy [this message]
2021-12-22  3:32   ` Li Wang
2021-12-22  6:05     ` xuyang2018.jy
2021-12-22  8:14       ` Petr Vorel
2021-12-22  8:37         ` xuyang2018.jy
2021-12-22  9:48           ` Li Wang
2021-12-22 10:09             ` Cyril Hrubis
2021-12-22 10:24               ` Petr Vorel
2021-12-22 10:40                 ` Cyril Hrubis
2021-12-22 10:48                   ` Petr Vorel
2021-12-22 11:29                     ` Li Wang
2021-12-22 11:32                       ` Li Wang
2021-12-22 11:25                   ` Li Wang
2021-12-22 10:38           ` Petr Vorel
2021-12-22  8:06     ` 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=61C28CB8.3050209@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    --cc=rpalethorpe@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.