public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] unshare03: using soft limit of NOFILE
@ 2025-03-14  4:42 lufei
  2025-03-27 10:33 ` Petr Vorel
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: lufei @ 2025-03-14  4:42 UTC (permalink / raw)
  To: ltp; +Cc: lufei

I think it's safer to set NOFILE increasing from soft limit than from
hard limit.

Hard limit may lead to dup2 ENOMEM error which bring the result to
TBROK on little memory machine. (e.g. 2GB memory in my situation, hard
limit in /proc/sys/fs/nr_open come out to be 1073741816)

Signed-off-by: lufei <lufei@uniontech.com>
---
 testcases/kernel/syscalls/unshare/unshare03.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/unshare/unshare03.c b/testcases/kernel/syscalls/unshare/unshare03.c
index 7c5e71c4e..bb568264c 100644
--- a/testcases/kernel/syscalls/unshare/unshare03.c
+++ b/testcases/kernel/syscalls/unshare/unshare03.c
@@ -24,7 +24,7 @@
 
 static void run(void)
 {
-	int nr_open;
+	int rlim_max;
 	int nr_limit;
 	struct rlimit rlimit;
 	struct tst_clone_args args = {
@@ -32,14 +32,12 @@ static void run(void)
 		.exit_signal = SIGCHLD,
 	};
 
-	SAFE_FILE_SCANF(FS_NR_OPEN, "%d", &nr_open);
-	tst_res(TDEBUG, "Maximum number of file descriptors: %d", nr_open);
+	SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlimit);
+	rlim_max = rlimit.rlim_max;
 
-	nr_limit = nr_open + NR_OPEN_LIMIT;
+	nr_limit = rlim_max + NR_OPEN_LIMIT;
 	SAFE_FILE_PRINTF(FS_NR_OPEN, "%d", nr_limit);
 
-	SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlimit);
-
 	rlimit.rlim_cur = nr_limit;
 	rlimit.rlim_max = nr_limit;
 
@@ -47,10 +45,10 @@ static void run(void)
 	tst_res(TDEBUG, "Set new maximum number of file descriptors to : %d",
 		nr_limit);
 
-	SAFE_DUP2(2, nr_open + NR_OPEN_DUP);
+	SAFE_DUP2(2, rlim_max + NR_OPEN_DUP);
 
 	if (!SAFE_CLONE(&args)) {
-		SAFE_FILE_PRINTF(FS_NR_OPEN, "%d", nr_open);
+		SAFE_FILE_PRINTF(FS_NR_OPEN, "%d", rlim_max);
 		TST_EXP_FAIL(unshare(CLONE_FILES), EMFILE);
 		exit(0);
 	}
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-04-16  1:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-14  4:42 [LTP] [PATCH] unshare03: using soft limit of NOFILE lufei
2025-03-27 10:33 ` Petr Vorel
     [not found]   ` <0A99FFBB46DDB0B4+Z+YKSlAwn1vx3Dz4@rocky>
2025-03-28  8:50     ` Petr Vorel
2025-04-01 10:11 ` Cyril Hrubis
2025-04-01 12:54   ` Petr Vorel
2025-04-01 13:55     ` Cyril Hrubis
2025-04-09  6:41   ` Lu Fei
2025-04-09  7:49 ` [LTP] [PATCH v2] unshare03: set nr_open with sizeof(long)*8 lufei
2025-04-10 15:35   ` Jan Stancek via ltp
2025-04-11  3:09   ` Li Wang via ltp
2025-04-11  3:21     ` Li Wang via ltp
2025-04-11  6:01       ` Lu Fei
2025-04-11  9:03         ` Cyril Hrubis
2025-04-11  9:30   ` [LTP] [PATCH v3] " lufei
2025-04-16  1:55     ` Li Wang via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox