Skip to contentSkip to conversation

syscalls/msgstress: fixes for small systems

PATCH Superseded Krzysztof Kozlowski 2 participants 14 messages Jun 29, 2021 – Aug 20, 2021 Library code

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover syscalls/msgstress: fixes for small systems

Hi,

Changes since v3:
1. Adjust subject of patch 2/4.
2. Don't use TEST() macro in 2/4.
3. Remove debug messages in 2/4.
4. Return unsigned int in get_session_uid() as it cannot fail in 2/4.

Changes since v2:
1. Resend due to messed up previous submission.

Changes since v1:
1. Move the code reading cgroups session limit to lib/tst_pid.c to existing tst_get_free_pids_().
2. Allow reading session limits from cgroups v2.
3. Add patch 1/4 - typo fix.
4. Add patch 4/4 with the buffer/reserve of pids.

Best regards,
Krzysztof

Krzysztof Kozlowski (4):
include/tst_pid.h: fix language typo (subtraction) tst_pid.c: fix fork failure on small memory systems syscalls/msgstress03: fix fork failure on small memory systems syscalls/msgstress: tune limit of processes for small machines

 include/tst_pid.h                             |  6 +-
 lib/tst_pid.c                                 | 72 ++++++++++++++++++-
 .../syscalls/ipc/msgstress/msgstress03.c      | 15 +++-
 3 files changed, 89 insertions(+), 4 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v4 1/4 include/tst_pid.h: fix language typo (subtraction)

---
 include/tst_pid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/tst_pid.h +1 -1
index 9ba1abb27b7c..6c42f73a57e7 100644
@@ -13,7 +13,7 @@
 pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
 
 /*
- * Returns number of free pids by substarction of the number of pids
+ * Returns number of free pids by subtraction of the number of pids
  * currently used ('ps -eT') from max_pids
  */
 int tst_get_free_pids_(void (*cleanup_fn)(void));
Signature · 1 line
2.27.0
#2 lore raw

PATCH v4 2/4 tst_pid.c: fix fork failure on small memory systems

In reply to Krzysztof Kozlowski

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.

---
 include/tst_pid.h |  4 ++-
 lib/tst_pid.c     | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 2 deletions(-)
include/tst_pid.h +3 -1
index 6c42f73a57e7..8d999a655f1a 100644
@@ -14,7 +14,9 @@ pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
 
 /*
  * Returns number of free pids by subtraction of the number of pids
- * currently used ('ps -eT') from max_pids
+ * currently used ('ps -eT') from maximum number of processes.
+ * The limit of processes come from kernel pid_max and cgroup session limits
+ * (e.g. configured by systemd user.slice).
  */
 int tst_get_free_pids_(void (*cleanup_fn)(void));
 
lib/tst_pid.c +69 -1

99 lines not on this page · raw message

Signature · 1 line
2.27.0
#3 lore raw

PATCH v4 3/4 syscalls/msgstress03: fix fork failure on small memory systems

In reply to Krzysztof Kozlowski

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

msgstress03 1 TFAIL : msgstress03.c:155: Fork failed (may be OK if under stress)

In dmesg:

LTP: starting msgstress03
cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-1.scope

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. For 2 GB RAM machine with systemd this will result in:

    msgstress03    0  TINFO  :  Found limit of processes 5056 (from /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max)
    msgstress03    0  TINFO  :  Requested number of processes higher than user session limit (10000 > 4556), setting to 4556
---
 .../kernel/syscalls/ipc/msgstress/msgstress03.c   | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/msgstress/msgstress03.c +14 -1
index 294b401b1b38..18e50e35ee07 100644
@@ -78,7 +78,7 @@ static void usage(void)
 
 int main(int argc, char **argv)
 {
-	int i, j, ok, pid;
+	int i, j, ok, pid, free_pids;
 	int count, status;
 	struct sigaction act;
 
@@ -109,6 +109,19 @@ int main(int argc, char **argv)
 		}
 	}
 
+	free_pids = tst_get_free_pids(cleanup);
+	if (free_pids < 0) {
+		tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
+	} else if (!free_pids) {
+		tst_brkm(TBROK, cleanup, "No free pids");
+	}
+	if (nprocs >= free_pids) {
+		tst_resm(TINFO,
+			 "Requested number of processes higher than limit (%d > %d), "
+			 "setting to %d", nprocs, free_pids, free_pids);
+		nprocs = free_pids;
+	}
+
 	srand(getpid());
 	tid = -1;
 
Signature · 1 line
2.27.0
#4 lore raw

PATCH v4 3/4 syscalls/msgstress03: fix fork failure on small memory systems

Hi!

testcases/kernel/syscalls/ipc/msgstress/msgstress03.c int main(int argc, char **argv) · line 117

Quoted 6 lines
testcases/kernel/syscalls/ipc/msgstress/msgstress03.c +6 -0
+	free_pids = tst_get_free_pids(cleanup);
+	if (free_pids < 0) {
+		tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
+	} else if (!free_pids) {
+		tst_brkm(TBROK, cleanup, "No free pids");
+	}

This looks like copy&paste from msgstress04.c, can we please move this snippet to the library function instead?

Quoted 16 lines
testcases/kernel/syscalls/ipc/msgstress/msgstress03.c +7 -0
+	if (nprocs >= free_pids) {
+		tst_resm(TINFO,
+			 "Requested number of processes higher than limit (%d > %d), "
+			 "setting to %d", nprocs, free_pids, free_pids);
+		nprocs = free_pids;
+	}
+
 	srand(getpid());
 	tid = -1;
Signature · 6 lines
-- 
2.27.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v4 3/4 syscalls/msgstress03: fix fork failure on small memory systems

Quoted 6 lines · Cyril Hrubis

Hi!
And we do have a patchset that converts msgstress* to new library as well which merges msgstress03 and msgstress01. I will try to have a look into that as well.

http://patchwork.ozlabs.org/project/ltp/list/?series=233661

The question then would be who should rebase on whose work :)

Best regards,
Krzysztof

#7 lore raw

PATCH v4 3/4 syscalls/msgstress03: fix fork failure on small memory systems

Hi!

Quoted 7 lines
Quoted 5 lines

And we do have a patchset that converts msgstress* to new library as well which merges msgstress03 and msgstress01. I will try to have a look into that as well.

http://patchwork.ozlabs.org/project/ltp/list/?series=233661

The question then would be who should rebase on whose work :)

Given that the patchset is not ready, I will push your fixes first.

Signature · 2 lines
Cyril Hrubis
[email protected]
#8 lore raw

PATCH v4 3/4 syscalls/msgstress03: fix fork failure on small memory systems

In reply to Cyril Hrubis
Quoted 11 lines · Cyril Hrubis

Hi!

testcases/kernel/syscalls/ipc/msgstress/msgstress03.c int main(int argc, char **argv) · line 117

Quoted 6 lines
testcases/kernel/syscalls/ipc/msgstress/msgstress03.c +6 -0
+	free_pids = tst_get_free_pids(cleanup);
+	if (free_pids < 0) {
+		tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
+	} else if (!free_pids) {
+		tst_brkm(TBROK, cleanup, "No free pids");
+	}

This looks like copy&paste from msgstress04.c, can we please move this snippet to the library function instead?

I can move it.

Best regards,
Krzysztof

#9 lore raw

PATCH v4 4/4 syscalls/msgstress: tune limit of processes for small machines

In reply to Krzysztof Kozlowski

Forking the exactly amount of processes as the limit (either from max_pids or from cgroups) is risky - OS might be doing some work and interfere with the test. Instead leave some reserve (hard-coded to
500) for the OS so the test won't fail on fork failure.

---
 lib/tst_pid.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/tst_pid.c +3 -1
index c408172675a7..338235f13a6a 100644
@@ -32,6 +32,8 @@
 #define PID_MAX_PATH "/proc/sys/kernel/pid_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 */
+#define PIDS_RESERVE 500
 
 pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
 {
@@ -97,7 +99,7 @@ static int get_session_pids_limit(void (*cleanup_fn) (void))
 	if (max_pids < 0)
 		return -1;
 
-	return max_pids;
+	return max_pids > PIDS_RESERVE ? max_pids - PIDS_RESERVE : 0;
 }
 
 int tst_get_free_pids_(void (*cleanup_fn) (void))
Signature · 1 line
2.27.0
#10 lore raw

PATCH v4 4/4 syscalls/msgstress: tune limit of processes for small machines

Hi!

Quoted 4 lines

Forking the exactly amount of processes as the limit (either from max_pids or from cgroups) is risky - OS might be doing some work and interfere with the test. Instead leave some reserve (hard-coded to
500) for the OS so the test won't fail on fork failure.

Isn't 500 far too many? I would expect that 50 would be more than enough.

Signature · 2 lines
Cyril Hrubis
[email protected]
#11 lore raw

PATCH v4 4/4 syscalls/msgstress: tune limit of processes for small machines

Quoted 8 lines · Cyril Hrubis

Hi!

Quoted 4 lines

Forking the exactly amount of processes as the limit (either from max_pids or from cgroups) is risky - OS might be doing some work and interfere with the test. Instead leave some reserve (hard-coded to
500) for the OS so the test won't fail on fork failure.

Isn't 500 far too many? I would expect that 50 would be more than enough.

I wanted to stay on the safe side to avoid false failures especially that even with 500 reserve there will be plenty of PIDs to stress the system.

I can change it to 50.

Best regards,
Krzysztof

#12 lore raw

v4 cover syscalls/msgstress: fixes for small systems

In reply to Krzysztof Kozlowski
Quoted 11 lines · Krzysztof Kozlowski

Hi,

Changes since v3:
1. Adjust subject of patch 2/4.
2. Don't use TEST() macro in 2/4.
3. Remove debug messages in 2/4.
4. Return unsigned int in get_session_uid() as it cannot fail in 2/4.

Changes since v2:
1. Resend due to messed up previous submission.

Quoted 6 lines

Changes since v1:
1. Move the code reading cgroups session limit to lib/tst_pid.c to existing tst_get_free_pids_().
2. Allow reading session limits from cgroups v2.
3. Add patch 1/4 - typo fix.
4. Add patch 4/4 with the buffer/reserve of pids.

Any comments on this set?

Quoted 7 lines

Krzysztof Kozlowski (4):
include/tst_pid.h: fix language typo (subtraction) tst_pid.c: fix fork failure on small memory systems syscalls/msgstress03: fix fork failure on small memory systems syscalls/msgstress: tune limit of processes for small machines

Quoted 5 lines
 include/tst_pid.h                             |  6 +-
 lib/tst_pid.c                                 | 72 ++++++++++++++++++-
 .../syscalls/ipc/msgstress/msgstress03.c      | 15 +++-
 3 files changed, 89 insertions(+), 4 deletions(-)

Best regards,
Krzysztof

#13 lore raw

v4 cover syscalls/msgstress: fixes for small systems

Hi!

Quoted 1 line

Any comments on this set?

Sorry for the delay. I've pushed the first two patches, I will comment the rest.

Signature · 2 lines
Cyril Hrubis
[email protected]