<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Xu, Petr,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 22, 2021 at 10:26 AM <a href="mailto:xuyang2018.jy@fujitsu.com">xuyang2018.jy@fujitsu.com</a> <<a href="mailto:xuyang2018.jy@fujitsu.com">xuyang2018.jy@fujitsu.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Petr<br>
> If needed to set value also for non-root, use set_oom_score_adj().<br>
If so, why not rename set_oom_score_adj to tst_set_oom_score_adj and add <br>
declartion to tst_memutils.h?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Yes, it makes sense to expose this function to users to cover</div><div class="gmail_default" style="font-size:small">more oom test scenarios. For instance, set a high (>0) or low (<0)</div><div class="gmail_default" style="font-size:small">score in child_alloc() to verify if OOM-Killer still works well.</div></div><div class="gmail_default" style="font-size:small">But so far, we don't have such tests.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
ps: also have a word typo in set_oom_score_adj, adjustement => adjustment.<br>
<br>
Best Regards<br>
Yang Xu<br>
><br>
> Fixes: 8a0827766d ("lib: add functions to adjust oom score")<br>
><br>
> Signed-off-by: Petr Vorel<<a href="mailto:pvorel@suse.cz" target="_blank">pvorel@suse.cz</a>><br>
> ---<br>
>   include/tst_memutils.h | 11 ++++++++++-<br>
>   lib/tst_memutils.c     |  6 ++++++<br>
>   2 files changed, 16 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/include/tst_memutils.h b/include/tst_memutils.h<br>
> index 68a6e37714..e6f946ac0c 100644<br>
> --- a/include/tst_memutils.h<br>
> +++ b/include/tst_memutils.h<br>
> @@ -30,11 +30,15 @@ long long tst_available_mem(void);<br>
>    *   echo -1000>/proc/$PID/oom_score_adj<br>
>    * If the pid is 0 which means it will set on current(self) process.<br>
>    *<br>
> + * WARNING:<br>
> + *  Do nothing for non-root, because setting value<  0 requires root.<br>
> +    If you want to set value also for non-root, use set_oom_score_adj().<br>
> + *<br>
>    * Note:<br>
>    *  This exported tst_enable_oom_protection function can be used at anywhere<br>
>    *  you want to protect, but please remember that if you do enable protection<br>
>    *  on a process($PID) that all the children will inherit its score and be<br>
> - *  ignored by OOM Killer as well. So that's why tst_disable_oom_protection<br>
> + *  ignored by OOM Killer as well. So that's why tst_disable_oom_protection()<br>
>    *  to be used in combination.<br>
>    */<br>
>   void tst_enable_oom_protection(pid_t pid);<br>
> @@ -42,6 +46,11 @@ void tst_enable_oom_protection(pid_t pid);<br>
>   /*<br>
>    * Disable the OOM protection for the process($PID).<br>
>    *   echo 0>/proc/$PID/oom_score_adj<br>
> + *<br>
> + * WARNING:<br>
> + *  Do nothing for non-root, because it's expected to be cleanup after<br>
> + *  tst_enable_oom_protection(). Use set_oom_score_adj(), if you want to set<br>
> + *  value also for non-root.<br>
>    */<br>
>   void tst_disable_oom_protection(pid_t pid);<br>
><br>
> diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c<br>
> index 4346508d9a..f0695e026a 100644<br>
> --- a/lib/tst_memutils.c<br>
> +++ b/lib/tst_memutils.c<br>
> @@ -126,10 +126,16 @@ static void set_oom_score_adj(pid_t pid, int value)<br>
><br>
>   void tst_enable_oom_protection(pid_t pid)<br>
>   {<br>
> +     if (geteuid() != 0)<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">This is not working as expected in Github CI. I'm still looking at the problem.</div><div class="gmail_default" style="font-size:small"><a href="https://github.com/wangli5665/ltp/runs/4602025797?check_suite_focus=true">https://github.com/wangli5665/ltp/runs/4602025797?check_suite_focus=true<br></a></div><br></div><div><div class="gmail_default" style="font-size:small">And the worth mentioning, maybe better to do this check</div><div class="gmail_default" style="font-size:small">in set_oom_score_adj() if we do not decide to expose</div><div class="gmail_default" style="font-size:small">that function to user.</div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>