[55279] trunk/base

jmr at macports.org jmr at macports.org
Fri Aug 7 19:43:22 PDT 2009


Revision: 55279
          http://trac.macports.org/changeset/55279
Author:   jmr at macports.org
Date:     2009-08-07 19:43:22 -0700 (Fri, 07 Aug 2009)
Log Message:
-----------
limit default build.jobs based on available memory

Modified Paths:
--------------
    trunk/base/doc/macports.conf.in
    trunk/base/src/macports1.0/sysctl.c
    trunk/base/src/port1.0/portbuild.tcl

Modified: trunk/base/doc/macports.conf.in
===================================================================
--- trunk/base/doc/macports.conf.in	2009-08-08 01:53:35 UTC (rev 55278)
+++ trunk/base/doc/macports.conf.in	2009-08-08 02:43:22 UTC (rev 55279)
@@ -72,7 +72,8 @@
 
 # Number of simultaneous make jobs (commands) to use when building ports. This
 # value may be set to 0 so the number of simultaneous make jobs will be set to
-# the number of CPU cores that are automatically detected.
+# the number of CPU cores that are automatically detected, or the number of GB
+# of physical memory plus one, whichever is less.
 #buildmakejobs		0
 
 # Set whether to automatically execute "clean" after "install" of ports

Modified: trunk/base/src/macports1.0/sysctl.c
===================================================================
--- trunk/base/src/macports1.0/sysctl.c	2009-08-08 01:53:35 UTC (rev 55278)
+++ trunk/base/src/macports1.0/sysctl.c	2009-08-08 02:43:22 UTC (rev 55279)
@@ -44,7 +44,7 @@
 #include "sysctl.h"
 
 /*
- * Read-only wrapper for sysctlbyname(3). Only works for values of type CTLTYPE_INT.
+ * Read-only wrapper for sysctlbyname(3). Only works for values of type CTLTYPE_INT and CTLTYPE_QUAD.
  */
 int SysctlCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
@@ -53,6 +53,7 @@
     int res;
     char *name;
     int value;
+    Tcl_WideInt long_value;
     size_t len = sizeof(value);
 
     if (objc != 2) {
@@ -62,14 +63,25 @@
 
     name = Tcl_GetString(objv[1]);
     res = sysctlbyname(name, &value, &len, NULL, 0);
-    if (res == -1) {
+    if (res == -1 && errno != ENOMEM && errno != ERANGE) {
         tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
         Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(strerror(errno), -1));
         Tcl_SetObjResult(interp, tcl_result);
         return TCL_ERROR;
+    } else if (res == -1) {
+        len = sizeof(long_value);
+        res = sysctlbyname(name, &long_value, &len, NULL, 0);
+        if (res == -1) {
+            tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
+            Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(strerror(errno), -1));
+            Tcl_SetObjResult(interp, tcl_result);
+            return TCL_ERROR;
+        }
+        tcl_result = Tcl_NewWideIntObj(long_value);
+    } else {
+        tcl_result = Tcl_NewIntObj(value);
     }
-
-    tcl_result = Tcl_NewIntObj(value);
+    
     Tcl_SetObjResult(interp, tcl_result);
     return TCL_OK;
 }

Modified: trunk/base/src/port1.0/portbuild.tcl
===================================================================
--- trunk/base/src/port1.0/portbuild.tcl	2009-08-08 01:53:35 UTC (rev 55278)
+++ trunk/base/src/port1.0/portbuild.tcl	2009-08-08 02:43:22 UTC (rev 55279)
@@ -119,11 +119,14 @@
     set jobs $buildmakejobs
     # if set to '0', use the number of cores for the number of jobs
     if {$jobs == 0} {
-        if {[catch {set jobs [sysctl hw.activecpu]}]} {
+        if {[catch {set jobs [sysctl hw.activecpu]}] || [catch {set memsize [sysctl hw.memsize]}]} {
             set jobs 2
             ui_warn "failed to determine the number of available CPUs (probably not supported on this platform)"
             ui_warn "defaulting to $jobs jobs, consider setting buildmakejobs to a nonzero value in macports.conf"
         }
+        if {$jobs > $memsize / 1000000000 + 1} {
+            set jobs [expr $memsize / 1000000000 + 1]
+        }
     }
     if {![string is integer -strict $jobs] || $jobs <= 1} {
         set jobs 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090807/80f5837b/attachment.html>


More information about the macports-changes mailing list