[PATCH i-g-t 2/2] igt/gem_fd_exhaustion: Modify fs.nr_open for duration of the test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We also need to adjust fs.nr_open to allow setting rlimit equal to
fs.file-max. Otherwise we're getting EPREM on setrlimit().

Signed-off-by: Karol Krol <karol.krol@xxxxxxxxx>
---
 tests/gem_fd_exhaustion.c | 49 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 42 insertions(+), 7 deletions(-)

diff --git a/tests/gem_fd_exhaustion.c b/tests/gem_fd_exhaustion.c
index 6750444e..aa3fe8b3 100644
--- a/tests/gem_fd_exhaustion.c
+++ b/tests/gem_fd_exhaustion.c
@@ -33,17 +33,44 @@
 #include <fcntl.h>
 #include <limits.h>
 
+unsigned int original_nr_open;
+
+static int read_sysctl(const char *path)
+{
+	unsigned int val;
+	FILE *f = fopen(path, "r");
+
+	if (f) {
+		igt_assert(fscanf(f, "%u", &val) == 1);
+		fclose(f);
+		return val;
+	}
+	return -errno;
+}
+
+static int write_sysctl(const char *path, unsigned int val)
+{
+	FILE *f = fopen(path, "w");
+
+	if (f) {
+		igt_assert(fprintf(f, "%u", val));
+		fclose(f);
+		return 0;
+	}
+	return -errno;
+}
+
 static bool allow_unlimited_files(void)
 {
+	unsigned int nofile_rlim = 1024*1024;
 	struct rlimit rlim;
-	unsigned nofile_rlim = 1024*1024;
+	unsigned int buf;
 
-	FILE *file = fopen("/proc/sys/fs/file-max", "r");
-	if (file) {
-		igt_assert(fscanf(file, "%u", &nofile_rlim) == 1);
-		igt_info("System limit for open files is %u\n", nofile_rlim);
-		fclose(file);
-	}
+	buf = read_sysctl("/proc/sys/fs/file-max");
+	if (buf > 0)
+		nofile_rlim = buf;
+	original_nr_open = read_sysctl("/proc/sys/fs/nr_open");
+	igt_assert(write_sysctl("/proc/sys/fs/nr_open", nofile_rlim) == 0);
 
 	if (getrlimit(RLIMIT_NOFILE, &rlim))
 		return false;
@@ -53,6 +80,12 @@ static bool allow_unlimited_files(void)
 	return setrlimit(RLIMIT_NOFILE, &rlim) == 0;
 }
 
+static void restore_original_sysctl(void)
+{
+	if (original_nr_open > 0)
+		write_sysctl("/proc/sys/fs/nr_open", original_nr_open);
+}
+
 igt_simple_main
 {
 	int fd;
@@ -61,6 +94,8 @@ igt_simple_main
 
 	fd = drm_open_driver(DRIVER_INTEL);
 
+	igt_install_exit_handler(restore_original_sysctl);
+
 	igt_fork(n, 1) {
 		igt_drop_root();
 
-- 
2.14.3

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek
przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by
others is strictly prohibited.

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux