aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaroslav Skarvada <jskarvad@redhat.com>2013-10-09 12:51:01 +0300
committerSergey Senozhatsky <sergey.senozhatsky@gmail.com>2013-10-09 12:56:39 +0300
commitb1668c39bb77fa5d0b9f0effc7646ee94948a3af (patch)
tree98001169b7c01932f048515690292dc42d12703a
parente6d483c8f570f7490fd93b1f920f0450c051f9d4 (diff)
set open files rlimit to /proc/sys/fs/nr_open
From: Jaroslav Skarvada <jskarvad@redhat.com> we have noticed that it can only overcome soft limits, but not hard limits. E.g. on Fedora (and probably others) there is a soft limit of 1024 and a hard limit of 4096, so if powertop opens at least 15 file descriptors per CPU, then this will fail on a system with >273 CPUs. On my system NR_OPEN is 1024, but /proc/sys/fs/nr_open gives me 1048576. It seems the linux kernel hardcodes 1024 * 1024 as the default kernel limit. This default limit can be raised to: sysctl_nr_open_max = min((size_t)INT_MAX, ~(size_t)0/sizeof(void *)) & -BITS_PER_LONG; which is 2 Gi - 63 on my 64 bit system. I think we shouldn't touch/increase this. It seems there is no header definition for these limits. I am proposing new patch, which reads the current kernel limit from the /proc. I am not sure about the portability, but at least it shouldn't break anything. Finally I think, the first patch could be applied together with this patch (probably with the changed message) to notify user that he/she reached the FDs limit, because there is still some limit. This could also occur if some process would decrease the /proc/sys/fs/nr_open after it is read by powertop and before the ulimit is set patch merge modifications by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
-rw-r--r--src/main.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 501a364..4e34ee6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -28,6 +28,7 @@
* Arjan van de Ven <arjan@linux.intel.com>
*/
#include <iostream>
+#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@@ -61,6 +62,8 @@
#define DEBUGFS_MAGIC 0x64626720
+#define NR_OPEN_DEF 1024 * 1024
+
int debug_learning = 0;
unsigned time_out = 20;
int leave_powertop = 0;
@@ -281,6 +284,20 @@ static void checkroot() {
}
+static int get_nr_open(void) {
+ int nr_open = NR_OPEN_DEF;
+ ifstream file;
+
+ file.open("/proc/sys/fs/nr_open", ios::in);
+ if (file) {
+ file >> nr_open;
+ if (!file)
+ nr_open = NR_OPEN_DEF;
+ file.close();
+ }
+ return nr_open;
+}
+
static void powertop_init(void)
{
static char initialized = 0;
@@ -293,8 +310,7 @@ static void powertop_init(void)
checkroot();
- getrlimit (RLIMIT_NOFILE, &rlmt);
- rlmt.rlim_cur = rlmt.rlim_max;
+ rlmt.rlim_cur = rlmt.rlim_max = get_nr_open();
setrlimit (RLIMIT_NOFILE, &rlmt);
ret = system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");