Skip to contentSkip to conversation

Fix running failure when > 69 CPUs for open file limitation

PATCH In review Youquan Song 2 participants 3 messages May 29, 2013

lore
Share & tools
lore

Youquan Song

author
#0 lore raw

PATCH 1/1 Fix running failure when > 69 CPUs for open file limitation

Powertop 2.3 fails to run on machine with > 69 CPUs because system open files limitation of one process is 1024 default, While powertop will open one file for every monitored perf_event (at least 15) each CPU.

Like on 80 CPUs Westmere-EX machine, powertop will fail to run with below:

PowerTOP v2.3 needs the kernel to support the 'perf' subsystem as well as support for trace points in the kernel:
CONFIG_PERF_EVENTS=y
CONFIG_PERF_COUNTERS=y
CONFIG_TRACEPOINTS=y
CONFIG_TRACING=y

This patch is to change RLIMIT_NOFILE from default (1024) to max limition.

Signed-off-by Youquan Song <youquan.song(a)intel.com>
---
 src/main.cpp |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
src/main.cpp +6 -0
index 0883424..8cd97a2 100644
@@ -36,6 +36,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sys/resource.h>
 
 #include "cpu/cpu.h"
 #include "process/process.h"
@@ -283,9 +284,14 @@ static void powertop_init(void)
 	static char initialized = 0;
 	int ret;
 	struct statfs st_fs;
+	struct rlimit rlmt;
 
 	if (initialized)
 		return;
+
+	getrlimit (RLIMIT_NOFILE, &rlmt);
+	rlmt.rlim_cur = rlmt.rlim_max;
+	setrlimit (RLIMIT_NOFILE, &rlmt);
 
 	checkroot();
 	ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
Signature · 1 line
1.7.7.4
#1 lore raw
Quoted 6 lines · Youquan Song

Powertop 2.3 fails to run on machine with > 69 CPUs because system open files limitation of one process is 1024 default, While powertop will open one file for every monitored perf_event (at least 15) each CPU.

Like on 80 CPUs Westmere-EX machine, powertop will fail to run with below:

Quoted 10 lines

PowerTOP v2.3 needs the kernel to support the 'perf' subsystem as well as support for trace points in the kernel:
CONFIG_PERF_EVENTS=y
CONFIG_PERF_COUNTERS=y
CONFIG_TRACEPOINTS=y
CONFIG_TRACING=y

This patch is to change RLIMIT_NOFILE from default (1024) to max limition.

Hello,
I'd like to ask you to try out the following patch. We leak fd in read_file().

------8<--------8<--------

- Do not leak file descriptor in perf_bundle read_file().
- Clear perf event (unmap memory and close fd) on event destruction.

Signed-off-by Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>

---

src/perf/perf.cpp +1 -0
index 35b4017..e919741 100644
@@ -167,6 +167,7 @@ perf_event::~perf_event(void)
 	if (perf_event::pevent->ref_count == 1) {
 		pevent_free(perf_event::pevent);
 		perf_event::pevent = NULL;
+		clear();
 	} else
 		pevent_unref(perf_event::pevent);
 }
src/perf/perf_bundle.cpp +1 -0
index 38e1e91..8d480e8 100644
@@ -123,6 +123,7 @@ static char * read_file(const char *file)
 		buffer[len] = '\0';
 	}
 out:
+	close(fd);
 	return buffer;
 }
 
#2 lore raw
In reply to Youquan Song
Quoted 4 lines · Youquan Song

Powertop 2.3 fails to run on machine with > 69 CPUs because system open files limitation of one process is 1024 default, While powertop will open one file for every monitored perf_event (at least 15) each CPU.

how about, say, 2048? unlimited resource steals possibility to detect error/bug/leak/etc.

and let's make rlimit change after checkroot() call.

	-ss
Quoted 45 lines

Like on 80 CPUs Westmere-EX machine, powertop will fail to run with below:

PowerTOP v2.3 needs the kernel to support the 'perf' subsystem as well as support for trace points in the kernel:
CONFIG_PERF_EVENTS=y
CONFIG_PERF_COUNTERS=y
CONFIG_TRACEPOINTS=y
CONFIG_TRACING=y

This patch is to change RLIMIT_NOFILE from default (1024) to max limition.

Signed-off-by Youquan Song <youquan.song(a)intel.com>
---
 src/main.cpp |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
src/main.cpp +6 -0
index 0883424..8cd97a2 100644
@@ -36,6 +36,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sys/resource.h>
 
 #include "cpu/cpu.h"
 #include "process/process.h"
@@ -283,9 +284,14 @@ static void powertop_init(void)
 	static char initialized = 0;
 	int ret;
 	struct statfs st_fs;
+	struct rlimit rlmt;
 
 	if (initialized)
 		return;
+
+	getrlimit (RLIMIT_NOFILE, &rlmt);
+	rlmt.rlim_cur = rlmt.rlim_max;
+	setrlimit (RLIMIT_NOFILE, &rlmt);
 
 	checkroot();
 	ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");