]> Sergey Matveev's repositories - nnn.git/commitdiff
Limit max open fds to 20K.
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 20 Aug 2017 19:25:45 +0000 (00:55 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 21 Aug 2017 03:46:11 +0000 (09:16 +0530)
nnn.c

diff --git a/nnn.c b/nnn.c
index 4605d19161724362e29a2d8887834440292b6fb1..4199feead63e66100981970aef7b5efd323aa1aa 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -246,10 +246,16 @@ max_openfds()
        rl.rlim_cur = rl.rlim_max;
 
        /* Return ~75% of max possible */
-       if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
-               return (rl.rlim_max - (rl.rlim_max >> 2));
+       if (setrlimit(RLIMIT_NOFILE, &rl) == 0) {
+               limit = rl.rlim_max - (rl.rlim_max >> 2);
+               /*
+                * 20K is arbitrary> If the limit is set to max possible
+                * value, the memory usage increases to more than double.
+                */
+               return limit > 20480 ?  20480 : limit;
+       }
 
-       return 32;
+       return limit;
 }
 
 /*