All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] syscalls/msgstress04: fix fork failure on small memory systems
Date: Tue, 22 Jun 2021 13:14:40 +0200	[thread overview]
Message-ID: <20210622111440.74722-2-krzysztof.kozlowski@canonical.com> (raw)
In-Reply-To: <20210622111440.74722-1-krzysztof.kozlowski@canonical.com>

Running syscalls/msgstress04 on a system with less than ~4 GB of RAM fails:

    Fork failure in the first child of child group 4396
    Fork failure in the second child of child group 4413
    msgstress04    1  TFAIL  :  msgstress04.c:222: Child exit status = 1

The reason is cgroups pid limit set by systemd user.slice.  The limit is
set for login session, also for root user.  For example on 2 GB RAM
machine it is set as:
    /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207

Read the maximum number of pids and adjust the test limit.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 testcases/kernel/syscalls/ipc/msgstress/msgstress04.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
index f1c124990cb1..37561b18c651 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
@@ -387,7 +387,7 @@ static void term(int sig LTP_ATTRIBUTE_UNUSED)
 
 void setup(void)
 {
-	int nr_msgqs, free_pids;
+	int nr_msgqs, free_pids, max_session_pids;
 
 	tst_tmpdir();
 	/* You will want to enable some signal handling so you can capture
@@ -423,6 +423,13 @@ void setup(void)
 	 * For each child we fork up to 2*maxnkids grandchildren. */
 	maxnprocs = (free_pids / 2) / (1 + 2 * maxnkids);
 
+	max_session_pids = get_pids_limit();
+	if ((max_session_pids > 0) && (max_session_pids < free_pids)) {
+		/* Clamp number of processes to session limit with some buffer for OS */
+		max_session_pids = (max_session_pids > 500 ? max_session_pids - 500 : 0);
+		maxnprocs = (max_session_pids / 2) / (1 + 2 * maxnkids);
+	}
+
 	if (!maxnprocs)
 		tst_brkm(TBROK, cleanup, "Not enough free pids");
 
-- 
2.27.0


  reply	other threads:[~2021-06-22 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 11:14 [LTP] [PATCH 1/2] syscalls/msgstress03: fix fork failure on small memory systems Krzysztof Kozlowski
2021-06-22 11:14 ` Krzysztof Kozlowski [this message]
2021-06-23  9:28 ` xuyang2018.jy
2021-06-23  9:39   ` Krzysztof Kozlowski
2021-06-23 10:36 ` Cyril Hrubis
2021-06-23 11:27   ` Krzysztof Kozlowski
2021-06-23 11:18     ` Cyril Hrubis

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=20210622111440.74722-2-krzysztof.kozlowski@canonical.com \
    --to=krzysztof.kozlowski@canonical.com \
    --cc=ltp@lists.linux.it \
    /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.