Hi, T2 build script has a nice feature of using TMPFS ramdisk as temporary 
compilation storage to speed up things. However, if certain "big package" 
doesn't fit in TMPFS ramdisk then Build-Target batch job fails to continue. In 
practice most users probably have enough RAM to compile 90% of packages but 
those few huuuuge packages would require several gigas of extra memory (gcc, 
kernel, etc). It would be nice to have T2 automatically revert back to ordinary 
disk usage if TMPFS usage run out of space. This way we can speed up 90% of 
package compilations and use slow disk for those couple huge packages only. 
Well, here is my proposal for that optimization and diff patch to 
scripts/Build-Pkg file. The patch does following tricks (1) Checks whether 
TMPFS configuration option is set (this is normal T2 config stuff). If TMPFS 
option is not set then this code change doesn't do anything new.(2) If TMPFS 
option was set then script tries to compile the package as normally using the 
TMPFS ramdisk storage if builddir_pkgsize cache file indicatates that the pkg 
build dir space requirement is less than TMPFS size (calculated in mega bytes 
in the current diff patch). If pkg compilation size would be more than TMPFS 
size then script doesnt use TMPFS even when it was enabled.(3) If pkg 
compilation failed in TMPFS then script does extra trick and tries to 
re-compile the same package automatically using normal disk space (it does this 
by forcing Build-Pkg script to ignore TMPFS option on the second run)(4) If pkg 
compilation succeeded then script caches the actual use of disk space in 
config/$config/builddir_pkgsize file (build stage and pkg specific cache line) 
This change caches actual compilation disk space requirements in 
config/$config/builddir_pkgsize file and it is automatically created and 
maintained. One can add manually lines in there as long the line format is as 
follows: stageNumber pkgName compilationDiskRequirementInMegaBytes For example 
in my scenario GCC package would have following lines in builddir_pkgsize cache 
file after completing all stages0 gcc 752M1 gcc 882M2 gcc 1520M5 gcc 1520M As 
you can see different stages may have different disk requirements, so this is 
why cache file is "per stage per pkg". One can copy this builddir_pkg cache 
file from one configuration to another config folder to re-use cache 
information and to avoid unnecessary "huuuge pkg" TMPFS compilations which 
would fail anyway in out-of-tmpfs-space errors. This saves couple minutes of 
crucial compilation time when those huuuge packages are automatically compiled 
through ordinary disk space even when TMPFS would be enabled. The patch is a 
bit brutal when it comes to TMPFS option in t2 configurator (normal stuff, this 
diff doesnt change anything there). It must be configured using following 
syntax (as a sample). TMPFS size in T2 configurator must be told in mega bytes 
and as the first parameter in option line: size=800M, nr_inodes=100k.  Of 
course your "mileague may vary" but order of these options and syntax should be 
as shown here. I hope someone else may find this optimization useful. I have 
used it quite a lot already and it does seem to speed up things at least in my 
"resource contrained laptop". I run T2 compilation environment in vmware image 
on a normal Windows laptop, so my benchmarks probably don't apply to bigger and 
faster native compilation platforms. Best regards,Mika N                        
             
--- scripts/Build-Pkg   2011-04-27 10:54:25.813438845 +0300
+++ scripts/Build-Pkg   2011-04-29 10:24:22.852869158 +0300
@@ -39,6 +39,11 @@ id=''
 stagelevel=9
 this_is_the_2nd_run=0
 
+# 0=Try to use TMPFS if enabled, otherwise do default build (the first call to 
pkg always has this state)
+# 1=Allow TMPFS RAM file system buildir if TMPFS is enabled in configuration
+# 2=Do not allow TMPFS even when enabled (re-try compilation after TMPFS 
retrystep 1 run out of diskspace) 
+tmpfsretrystep=0
+
 #
 # ----  Functions
 #
@@ -80,6 +85,7 @@ while [ "$1" ] ; do
                -id)      options="$options $1 $2" ; id="$2"       ; shift ;;
                -noclearsrc) options="$options $1" ; clear_src=0   ;;
                -norebuild)  options="$options $1" ; norebuild=1   ;;
+               -tmpfsretrystep) options="$options $1 $2" ; tmpfsretrystep=$2  
; shift ;;
                -*) help_msg ; exit 1 ;;
                *)  break ;;
        esac
@@ -133,6 +139,39 @@ if [ $# -gt 1 ] ; then
     done
     exit 0
 fi
+
+# If TMPFS builddir is enabled and this is the first compilation attempt then 
allow TMPFS usage. 
+# Otherwise re-try compilation using disk storage because TMPFS ram disk run 
out of space
+pkg="${1%=*}"
+if [ "$SDECFG_SRC_TMPFS" = 1 -a $tmpfsretrystep = 0 ]; then
+       # Parse TMPFS ramdisk size from the TMPFS_OPT (size=800M converted to 
800).
+       # TMPFS_OPT is expected to use M mega bytes and size as the first option
+       #    size=800M,nr_inodes=100k
+       # TODO: Better way would be format independent parsing, but this 
version excepts TMPFS size to be in M mega bytes
+       tmpfs_size=$(echo $SDECFG_SRC_TMPFS_OPT | cut -d ',' -f 1 | cut -d '=' 
-f 2 | sed 's/M//g')
+
+       # Find stagelevel-pkg size value from the pkgsize cache file (3rd field 
is size and remove M mega tag)
+       pkg_size=$(grep "^$stagelevel $pkg" ./config/$config/builddir_pkgsize | 
cut -d ' ' -f 3 | sed 's/M//g')
+       [ "$pkg_size" = "" ] && pkg_size=0
+
+       # If builddir pkg size is smaller than tmpfs RAM disk size then try to 
use TMPFS.
+       # Otherwise use disk space even when TMPFS is enabled (TMPFS is too 
small to compile the pkg)
+       if [ $pkg_size -lt $tmpfs_size ]; then
+               if ! ./scripts/Build-Pkg $options -tmpfsretrystep 1 $pkg; then
+                       echo "Failed to compile $pkg. Trying to build without 
TMPFS RAM filesystem"
+                       if ! ./scripts/Build-Pkg $options -tmpfsretrystep 2 
$pkg; then
+                               exit 1
+                       fi
+               fi
+
+               # Successfully compiled pkg
+               exit 0
+       fi
+
+       # Fall through and disable TMPFS usage even when it is enabled (pkg too 
big to fit in)
+       tmpfsretrystep=2
+fi
+
 pkg="${1%=*}" ; xpkg="${1#*=}"
 builddir="$base/src.$pkg.$config.$id"
 
@@ -476,7 +515,8 @@ echo_status "Preparing build in src.$pkg
 
 if [ $clear_src = 1 ] ; then
        mkdir -p $builddir; chmod 700 $builddir
-       if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
+       if [ "$SDECFG_SRC_TMPFS" = 1 -a $tmpfsretrystep -le 1 ]; then
+               echo "Mounting TMPFS filesystem $SDECFG_SRC_TMPFS_OPT"
                mount -n -t tmpfs -o $SDECFG_SRC_TMPFS_OPT none $builddir
        fi
 else
@@ -948,6 +988,15 @@ if [ "$SDECFG_SRC_TMPFS_LOG" = 1 -a -n "
        expand -t20 >> $root/var/adm/t2-debug/tmpfslog.txt
 fi
 
+if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
+       # Successfully compiled pkg. Cache builddir disk usage statistics in 
mega bytes.
+       # Remove existing pkg size line and add up to date size stat line.
+       sed "/^$stagelevel $pkg /d" ./config/$config/builddir_pkgsize 2> 
/dev/null > ./config/$config/builddir_pkgsize.tmp
+       rm -f ./config/$config/builddir_pkgsize
+       mv ./config/$config/builddir_pkgsize.tmp 
./config/$config/builddir_pkgsize
+       echo -e "$stagelevel $pkg $(du 2> /dev/null -s -BM $builddir/ | cut 
-f1)" >> ./config/$config/builddir_pkgsize
+fi
+
 umount -r -d -f    $builddir   2> /dev/null
 umount -r -d -f -l $builddir   2> /dev/null
 
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[email protected] with a subject of: unsubscribe t2

Reply via email to