trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [2/2] git commit: TS-2736: detect max file limit in common code
Date Sat, 06 Sep 2014 20:35:19 GMT
TS-2736: detect max file limit in common code


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4a1d1781
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4a1d1781
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4a1d1781

Branch: refs/heads/master
Commit: 4a1d178189d0c86ac69d8e82580535416ae9a138
Parents: a4d903c
Author: James Peach <jpeach@apache.org>
Authored: Sat Sep 6 12:51:21 2014 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Sat Sep 6 12:51:21 2014 -0700

----------------------------------------------------------------------
 cmd/traffic_manager/traffic_manager.cc | 27 +++++++++----------
 lib/ts/ink_sys_control.cc              | 28 ++++++++++++++++++--
 lib/ts/ink_sys_control.h               | 10 +------
 proxy/Main.cc                          | 41 +++++++++++++++--------------
 4 files changed, 60 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a1d1781/cmd/traffic_manager/traffic_manager.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_manager/traffic_manager.cc b/cmd/traffic_manager/traffic_manager.cc
index 93bbbd2..087795a 100644
--- a/cmd/traffic_manager/traffic_manager.cc
+++ b/cmd/traffic_manager/traffic_manager.cc
@@ -295,6 +295,7 @@ static void
 set_process_limits(int fds_throttle)
 {
   struct rlimit lim;
+  rlim_t maxfiles;
 
   // Set needed rlimits (root)
   ink_max_out_rlimit(RLIMIT_NOFILE, true, false);
@@ -305,32 +306,28 @@ set_process_limits(int fds_throttle)
   ink_max_out_rlimit(RLIMIT_RSS, true, true);
 #endif
 
-#if defined(linux)
-  float file_max_pct = 0.9;
-  FILE *fd;
+  maxfiles = ink_get_max_files();
+  if (maxfiles != RLIM_INFINITY) {
+    float file_max_pct = 0.9;
 
-  if ((fd = fopen("/proc/sys/fs/file-max","r"))) {
-    ATS_UNUSED_RETURN(fscanf(fd, "%lu", &lim.rlim_max));
-    fclose(fd);
     REC_ReadConfigFloat(file_max_pct, "proxy.config.system.file_max_pct");
-    lim.rlim_cur = lim.rlim_max = static_cast<rlim_t>(lim.rlim_max * file_max_pct);
-    if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim))
{
+    if (file_max_pct > 1.0) {
+      file_max_pct = 1.0;
+    }
+
+    lim.rlim_cur = lim.rlim_max = static_cast<rlim_t>(maxfiles * file_max_pct);
+    if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim)
== 0) {
       fds_limit = (int) lim.rlim_cur;
       syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur,
(int)lim.rlim_max);
-    } else {
-      syslog(LOG_NOTICE, "NOTE: Unable to set RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE,
(int)lim.rlim_cur, (int)lim.rlim_max);
     }
-  } else {
-    syslog(LOG_NOTICE, "NOTE: Unable to open /proc/sys/fs/file-max");
   }
-#endif // linux
 
-  if (!getrlimit(RLIMIT_NOFILE, &lim)) {
+  if (getrlimit(RLIMIT_NOFILE, &lim) == 0) {
     if (fds_throttle > (int) (lim.rlim_cur + FD_THROTTLE_HEADROOM)) {
       lim.rlim_cur = (lim.rlim_max = (rlim_t) fds_throttle);
       if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim))
{
         fds_limit = (int) lim.rlim_cur;
-	syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur,
(int)lim.rlim_max);
+	      syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur,
(int)lim.rlim_max);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a1d1781/lib/ts/ink_sys_control.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_sys_control.cc b/lib/ts/ink_sys_control.cc
index d04d2f4..03a6bc9 100644
--- a/lib/ts/ink_sys_control.cc
+++ b/lib/ts/ink_sys_control.cc
@@ -21,9 +21,9 @@
   limitations under the License.
  */
 
-#include "ink_sys_control.h"
-#include "ink_platform.h"
+#include "ink_defs.h"
 #include "ink_assert.h"
+#include "ink_sys_control.h"
 
 rlim_t
 ink_max_out_rlimit(int which, bool max_it, bool unlim_it)
@@ -63,3 +63,27 @@ ink_max_out_rlimit(int which, bool max_it, bool unlim_it)
   ink_release_assert(getrlimit(MAGIC_CAST(which), &rl) >= 0);
   return rl.rlim_cur;
 }
+
+rlim_t
+ink_get_max_files()
+{
+  FILE *fd;
+  struct rlimit lim;
+
+  // Linux-only ...
+  if ((fd = fopen("/proc/sys/fs/file-max","r"))) {
+    uint64_t fmax;
+    if (fscanf(fd, "%" PRIu64 "", &fmax) == 1) {
+      fclose(fd);
+      return static_cast<rlim_t>(fmax);
+    }
+
+    fclose(fd);
+  }
+
+  if (getrlimit(RLIMIT_NOFILE, &lim) == 0) {
+    return lim.rlim_max;
+  }
+
+  return RLIM_INFINITY;
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a1d1781/lib/ts/ink_sys_control.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_sys_control.h b/lib/ts/ink_sys_control.h
index ad562d7..15e2b2c 100644
--- a/lib/ts/ink_sys_control.h
+++ b/lib/ts/ink_sys_control.h
@@ -26,15 +26,7 @@
 
 #include <sys/resource.h>
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif                          /* __cplusplus */
-
 rlim_t ink_max_out_rlimit(int which, bool max_it=true, bool unlim_it=true);
-
-#ifdef __cplusplus
-}
-#endif                          /* __cplusplus */
+rlim_t ink_get_max_files();
 
 #endif /*_INK_SYS_CONTROL_H*/

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a1d1781/proxy/Main.cc
----------------------------------------------------------------------
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 02ad7de..1696151 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -796,53 +796,54 @@ init_core_size()
 static void
 adjust_sys_settings(void)
 {
-#if defined(linux)
   struct rlimit lim;
-  int mmap_max = -1;
   int fds_throttle = -1;
-  float file_max_pct = 0.9;
-  FILE *fd;
+  rlim_t maxfiles;
 
   // TODO: I think we might be able to get rid of this?
+#if defined(ATS_MMAP_MAX)
+  int mmap_max = -1;
+
   REC_ReadConfigInteger(mmap_max, "proxy.config.system.mmap_max");
   if (mmap_max >= 0)
     ats_mallopt(ATS_MMAP_MAX, mmap_max);
+#endif
+
+  maxfiles = ink_get_max_files();
+  if (maxfiles != RLIM_INFINITY) {
+    float file_max_pct = 0.9;
 
-  if ((fd = fopen("/proc/sys/fs/file-max","r"))) {
-    ATS_UNUSED_RETURN(fscanf(fd, "%" PRIu64 "", &lim.rlim_max));
-    fclose(fd);
     REC_ReadConfigFloat(file_max_pct, "proxy.config.system.file_max_pct");
-    lim.rlim_cur = lim.rlim_max = static_cast<rlim_t>(lim.rlim_max * file_max_pct);
-    if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim))
{
+    if (file_max_pct > 1.0) {
+      file_max_pct = 1.0;
+    }
+
+    lim.rlim_cur = lim.rlim_max = static_cast<rlim_t>(maxfiles * file_max_pct);
+    if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim)
== 0) {
       fds_limit = (int) lim.rlim_cur;
       syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur,
(int)lim.rlim_max);
-    } else {
-      syslog(LOG_NOTICE, "NOTE: Unable to set RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE,
(int)lim.rlim_cur, (int)lim.rlim_max);
     }
-  } else {
-    syslog(LOG_NOTICE, "NOTE: Unable to open /proc/sys/fs/file-max");
   }
 
   REC_ReadConfigInteger(fds_throttle, "proxy.config.net.connections_throttle");
 
-  if (!getrlimit(RLIMIT_NOFILE, &lim)) {
+  if (getrlimit(RLIMIT_NOFILE, &lim) == 0) {
     if (fds_throttle > (int) (lim.rlim_cur + THROTTLE_FD_HEADROOM)) {
       lim.rlim_cur = (lim.rlim_max = (rlim_t) fds_throttle);
-      if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim))
{
+      if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim)
== 0) {
         fds_limit = (int) lim.rlim_cur;
         syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur,
(int)lim.rlim_max);
       }
     }
   }
 
-  ink_max_out_rlimit(RLIMIT_STACK,true,true);
-  ink_max_out_rlimit(RLIMIT_DATA,true,true);
+  ink_max_out_rlimit(RLIMIT_STACK, true, true);
+  ink_max_out_rlimit(RLIMIT_DATA, true, true);
   ink_max_out_rlimit(RLIMIT_FSIZE, true, false);
+
 #ifdef RLIMIT_RSS
-  ink_max_out_rlimit(RLIMIT_RSS,true,true);
+  ink_max_out_rlimit(RLIMIT_RSS, true, true);
 #endif
-
-#endif  // linux check
 }
 
 struct ShowStats: public Continuation


Mime
View raw message