* [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
@ 2023-02-07 12:40 Leo Yu-Chi Liang
2023-02-07 13:42 ` Petr Vorel
2023-02-09 13:05 ` Cyril Hrubis
0 siblings, 2 replies; 7+ messages in thread
From: Leo Yu-Chi Liang @ 2023-02-07 12:40 UTC (permalink / raw)
To: ycliang, ltp
Running syscalls/msgstress03 on a system with less than ~1 GB of RAM fails:
msgstress03 1 TFAIL : msgstress03.c:163: Fork failed (may be OK if under stress)
The reason is that besides /proc/sys/kernel/pid_max, /proc/sys/kernel/threads-max
is another factor determining how many processes a system could create.
Use the smaller number between pid_max and threads-max as the nprocs.
Signed-off-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
lib/tst_pid.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/tst_pid.c b/lib/tst_pid.c
index 21cadef2a..3fb3f39ad 100644
--- a/lib/tst_pid.c
+++ b/lib/tst_pid.c
@@ -31,6 +31,7 @@
#include "tst_safe_macros.h"
#define PID_MAX_PATH "/proc/sys/kernel/pid_max"
+#define THREADS_MAX_PATH "/proc/sys/kernel/threads-max"
#define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
#define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
/* Leave some available processes for the OS */
@@ -113,7 +114,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void))
int tst_get_free_pids_(void (*cleanup_fn) (void))
{
FILE *f;
- int rc, used_pids, max_pids, max_session_pids;
+ int rc, used_pids, max_pids, max_session_pids, max_threads;
f = popen("ps -eT | wc -l", "r");
if (!f) {
@@ -129,6 +130,8 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
}
SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
+ SAFE_FILE_SCANF(cleanup_fn, THREADS_MAX_PATH, "%d", &max_threads);
+ max_pids = (max_pids < max_threads) ? max_pids : max_threads;
max_session_pids = get_session_pids_limit(cleanup_fn);
if ((max_session_pids > 0) && (max_session_pids < max_pids))
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-07 12:40 [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems Leo Yu-Chi Liang
@ 2023-02-07 13:42 ` Petr Vorel
2023-02-07 16:33 ` Jan Stancek
2023-02-09 13:35 ` Leo Liang
2023-02-09 13:05 ` Cyril Hrubis
1 sibling, 2 replies; 7+ messages in thread
From: Petr Vorel @ 2023-02-07 13:42 UTC (permalink / raw)
To: Leo Yu-Chi Liang; +Cc: ltp
Hi Leo,
> Running syscalls/msgstress03 on a system with less than ~1 GB of RAM fails:
> msgstress03 1 TFAIL : msgstress03.c:163: Fork failed (may be OK if under stress)
> The reason is that besides /proc/sys/kernel/pid_max, /proc/sys/kernel/threads-max
> is another factor determining how many processes a system could create.
> Use the smaller number between pid_max and threads-max as the nprocs.
Makes sense.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
BTW IMHO it'd be better to rewrite
f = popen("ps -eT | wc -l", "r");
to list count of /proc/[0-9]*/ in plain C (TODO for us).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-07 13:42 ` Petr Vorel
@ 2023-02-07 16:33 ` Jan Stancek
2023-02-09 13:35 ` Leo Liang
1 sibling, 0 replies; 7+ messages in thread
From: Jan Stancek @ 2023-02-07 16:33 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Tue, Feb 7, 2023 at 2:42 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Leo,
>
> > Running syscalls/msgstress03 on a system with less than ~1 GB of RAM fails:
>
> > msgstress03 1 TFAIL : msgstress03.c:163: Fork failed (may be OK if under stress)
>
> > The reason is that besides /proc/sys/kernel/pid_max, /proc/sys/kernel/threads-max
> > is another factor determining how many processes a system could create.
>
> > Use the smaller number between pid_max and threads-max as the nprocs.
>
> Makes sense.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
Acked-by: Jan Stancek <jstancek@redhat.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-07 12:40 [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems Leo Yu-Chi Liang
2023-02-07 13:42 ` Petr Vorel
@ 2023-02-09 13:05 ` Cyril Hrubis
2023-02-09 13:36 ` Leo Liang
1 sibling, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2023-02-09 13:05 UTC (permalink / raw)
To: Leo Yu-Chi Liang; +Cc: ltp
Hi!
> lib/tst_pid.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/tst_pid.c b/lib/tst_pid.c
> index 21cadef2a..3fb3f39ad 100644
> --- a/lib/tst_pid.c
> +++ b/lib/tst_pid.c
> @@ -31,6 +31,7 @@
> #include "tst_safe_macros.h"
>
> #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
> +#define THREADS_MAX_PATH "/proc/sys/kernel/threads-max"
> #define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
> #define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
> /* Leave some available processes for the OS */
> @@ -113,7 +114,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void))
> int tst_get_free_pids_(void (*cleanup_fn) (void))
> {
> FILE *f;
> - int rc, used_pids, max_pids, max_session_pids;
> + int rc, used_pids, max_pids, max_session_pids, max_threads;
>
> f = popen("ps -eT | wc -l", "r");
> if (!f) {
> @@ -129,6 +130,8 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
> }
>
> SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
> + SAFE_FILE_SCANF(cleanup_fn, THREADS_MAX_PATH, "%d", &max_threads);
> + max_pids = (max_pids < max_threads) ? max_pids : max_threads;
BTW: We do have a MIN() macro definition in tst_minmax.h header so we
can just do max_pids = MIN(max_pids, max_threads);
> max_session_pids = get_session_pids_limit(cleanup_fn);
> if ((max_session_pids > 0) && (max_session_pids < max_pids))
Otherwise:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-07 13:42 ` Petr Vorel
2023-02-07 16:33 ` Jan Stancek
@ 2023-02-09 13:35 ` Leo Liang
2023-02-09 13:49 ` Petr Vorel
1 sibling, 1 reply; 7+ messages in thread
From: Leo Liang @ 2023-02-09 13:35 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi Petr,
On Tue, Feb 07, 2023 at 02:42:22PM +0100, Petr Vorel wrote:
> Hi Leo,
>
> > Running syscalls/msgstress03 on a system with less than ~1 GB of RAM fails:
>
> > msgstress03 1 TFAIL : msgstress03.c:163: Fork failed (may be OK if under stress)
>
> > The reason is that besides /proc/sys/kernel/pid_max, /proc/sys/kernel/threads-max
> > is another factor determining how many processes a system could create.
>
> > Use the smaller number between pid_max and threads-max as the nprocs.
>
> Makes sense.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> BTW IMHO it'd be better to rewrite
> f = popen("ps -eT | wc -l", "r");
> to list count of /proc/[0-9]*/ in plain C (TODO for us).
>
Thanks for the review!
I could send a v2 to add this as well.
Best regards,
Leo
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-09 13:05 ` Cyril Hrubis
@ 2023-02-09 13:36 ` Leo Liang
0 siblings, 0 replies; 7+ messages in thread
From: Leo Liang @ 2023-02-09 13:36 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
On Thu, Feb 09, 2023 at 02:05:46PM +0100, Cyril Hrubis wrote:
> Hi!
> > lib/tst_pid.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/tst_pid.c b/lib/tst_pid.c
> > index 21cadef2a..3fb3f39ad 100644
> > --- a/lib/tst_pid.c
> > +++ b/lib/tst_pid.c
> > @@ -31,6 +31,7 @@
> > #include "tst_safe_macros.h"
> >
> > #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
> > +#define THREADS_MAX_PATH "/proc/sys/kernel/threads-max"
> > #define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
> > #define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
> > /* Leave some available processes for the OS */
> > @@ -113,7 +114,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void))
> > int tst_get_free_pids_(void (*cleanup_fn) (void))
> > {
> > FILE *f;
> > - int rc, used_pids, max_pids, max_session_pids;
> > + int rc, used_pids, max_pids, max_session_pids, max_threads;
> >
> > f = popen("ps -eT | wc -l", "r");
> > if (!f) {
> > @@ -129,6 +130,8 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
> > }
> >
> > SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
> > + SAFE_FILE_SCANF(cleanup_fn, THREADS_MAX_PATH, "%d", &max_threads);
> > + max_pids = (max_pids < max_threads) ? max_pids : max_threads;
>
> BTW: We do have a MIN() macro definition in tst_minmax.h header so we
> can just do max_pids = MIN(max_pids, max_threads);
>
Thanks for the review!
Will send a v2 to fix this!
Best regards,
Leo
> > max_session_pids = get_session_pids_limit(cleanup_fn);
> > if ((max_session_pids > 0) && (max_session_pids < max_pids))
>
> Otherwise:
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
> --
> Cyril Hrubis
> chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems
2023-02-09 13:35 ` Leo Liang
@ 2023-02-09 13:49 ` Petr Vorel
0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2023-02-09 13:49 UTC (permalink / raw)
To: Leo Liang; +Cc: ltp
Hi all,
Thanks Leo, I merged it with MIN(max_pids, max_threads), thanks Cyril for
catching it.
> > BTW IMHO it'd be better to rewrite
> > f = popen("ps -eT | wc -l", "r");
> > to list count of /proc/[0-9]*/ in plain C (TODO for us).
> Thanks for the review!
> I could send a v2 to add this as well.
Thank you, if you have time to send another patch to fix.
Kind regards,
Petr
> Best regards,
> Leo
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-02-09 13:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-07 12:40 [LTP] [PATCH 1/1] tst_pids.c: fix fork failure on small memory systems Leo Yu-Chi Liang
2023-02-07 13:42 ` Petr Vorel
2023-02-07 16:33 ` Jan Stancek
2023-02-09 13:35 ` Leo Liang
2023-02-09 13:49 ` Petr Vorel
2023-02-09 13:05 ` Cyril Hrubis
2023-02-09 13:36 ` Leo Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox