From 5e03ebc49870ca600fa4378a064100e9e13702e4 Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 28 Aug 2015 00:09:05 -0400 Subject: [PATCH 1/4] use pigz to improve the performance of genimage/packimage --- xCAT-server/lib/xcat/plugins/packimage.pm | 16 +++- xCAT-server/share/xcat/netboot/rh/genimage | 10 +++ xCAT-server/share/xcat/netboot/sles/genimage | 10 +++ .../share/xcat/netboot/ubuntu/genimage | 75 +++++++++++-------- 4 files changed, 76 insertions(+), 35 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index 02af3abc3..f93823588 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -366,17 +366,27 @@ sub process_request { $callback->({data=>["$verb contents of $rootimg_dir"]}); unlink("$destdir/rootimg.gz"); unlink("$destdir/rootimg.sfs"); + + my $compress="gzip"; + #use "pigz" as the compress tool instead of gzip if "pigz" exist + my $ispigz=system("bash -c 'type -p pigz'"); + if($ispigz == 0){ + $compress="pigz"; + } + + $callback->({info=>["compress method:$compress"]}); + if ($method =~ /cpio/) { if ( ! $exlistloc ) { - $excludestr = "find . -xdev |cpio -H newc -o | gzip -c - > ../rootimg.gz"; + $excludestr = "find . -xdev |cpio -H newc -o | $compress -c - > ../rootimg.gz"; }else { chdir("$rootimg_dir"); system("$excludestr >> $xcat_packimg_tmpfile"); if ($includestr) { system("$includestr >> $xcat_packimg_tmpfile"); } - #$excludestr =~ s!-a \z!|cpio -H newc -o | gzip -c - > ../rootimg.gz!; - $excludestr = "cat $xcat_packimg_tmpfile|cpio -H newc -o | gzip -c - > ../rootimg.gz"; + #$excludestr =~ s!-a \z!|cpio -H newc -o | $compress -c - > ../rootimg.gz!; + $excludestr = "cat $xcat_packimg_tmpfile|cpio -H newc -o | $compress -c - > ../rootimg.gz"; } $oldmask = umask 0077; } elsif ($method =~ /squashfs/) { diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 76b49dcb3..e7076f58c 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -955,6 +955,16 @@ sub mkinitrd_dracut { if ($dracutver > "033") { $additional_options .= " -N"; } + + + #if "pigz" is available in the rootimg, use "pigz" instead of "gzip" + my $compress=qx(chroot $rootimg_dir bash -c "type -p pigz"|tr -d "\n"); + if ($compress){ + #take the online cpu numerber as the pigz processes number + my $processnum=qx(lscpu -p=cpu --online|grep -v '#'|wc -l|tr -d "\n"); + $additional_options .= " --compress \"$compress -p $processnum \""; + } + print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; !system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver") or die("Error: failed to generate the initial ramdisk for $mode.\n"); print "the initial ramdisk for $mode is generated successfully.\n"; diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index a05fc8c99..1bb216ef4 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -1088,6 +1088,16 @@ sub mkinitrd_dracut { $additional_options .= " -N"; } + + #if "pigz" is available in the rootimg, use "pigz" instead of "gzip" + my $compress=qx(chroot $rootimg_dir bash -c "type -p pigz"|tr -d "\n"); + if ($compress){ + #take the online cpu numerber as the pigz processes number + my $processnum=qx(lscpu -p=cpu --online|grep -v '#'|wc -l|tr -d "\n"); + $additional_options .= " --compress \"$compress -p $processnum \""; + } + print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; + !system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver") or die("Error: failed to generate the initial ramdisk for $mode.\n"); print "the initial ramdisk for $mode is generated successfully.\n"; diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index 36fe9bcb3..7ab1679d0 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -1629,39 +1629,50 @@ EOMS # } system("chroot /tmp/xcatinitrd.$$/ depmod $kernelver"); - # Copy udev and network scripts into initrd for s390x, which also works for other platforms - # udev - system("mkdir -p /tmp/xcatinitrd.$$/etc/udev"); - system("cp -r $rootimg_dir/etc/udev/* /tmp/xcatinitrd.$$/etc/udev"); - system("mkdir -p /tmp/xcatinitrd.$$/lib/udev"); - system("cp -r $rootimg_dir/lib/udev/* /tmp/xcatinitrd.$$/lib/udev"); - system("mkdir -p /tmp/xcatinitrd.$$/proc/self"); - system("cp -r /proc/self/oom_adj /tmp/xcatinitrd.$$/proc/self"); - - # Network related scripts - #system("echo $kernelver\n"); - #system("mkdir -p /tmp/xcatinitrd.$$/sbin"); - #system("cp -r $rootimg_dir/sbin/* /tmp/xcatinitrd.$$/sbin"); - #system("mkdir -p /tmp/xcatinitrd.$$/lib/modules/$kernelver"); - #system("cp -r $rootimg_dir/lib/modules/$kernelver/modules.dep /tmp/xcatinitrd.$$/lib/modules/$kernelver/modules.dep"); - #system("mkdir -p /tmp/xcatinitrd.$$/etc/init.d"); - #system("cp -r $rootimg_dir/etc/init.d/* /tmp/xcatinitrd.$$/etc/init.d"); - #system("mkdir -p /tmp/xcatinitrd.$$/lib64"); - #system("cp -r $rootimg_dir/lib64/* /tmp/xcatinitrd.$$/lib64"); - #system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport"); - symlink("busybox","/tmp/xcatinitrd.$$/bin/pivot_root"); - symlink("busybox", "/tmp/xcatinitrd.$$/bin/udhcpc"); - symlink("busybox", "/tmp/xcatinitrd.$$/sbin/ifconfig"); - symlink("busybox", "/tmp/xcatinitrd.$$/bin/hostname"); - symlink("busybox", "/tmp/xcatinitrd.$$/bin/route"); - symlink("busybox", "/tmp/xcatinitrd.$$/bin/nc"); - symlink("bash", "/tmp/xcatinitrd.$$/bin/sh"); - symlink("bash", "/tmp/xcatinitrd.$$/sbin/sh"); + # Copy udev and network scripts into initrd for s390x, which also works for other platforms + # udev + system("mkdir -p /tmp/xcatinitrd.$$/etc/udev"); + system("cp -r $rootimg_dir/etc/udev/* /tmp/xcatinitrd.$$/etc/udev"); + system("mkdir -p /tmp/xcatinitrd.$$/lib/udev"); + system("cp -r $rootimg_dir/lib/udev/* /tmp/xcatinitrd.$$/lib/udev"); + system("mkdir -p /tmp/xcatinitrd.$$/proc/self"); + system("cp -r /proc/self/oom_adj /tmp/xcatinitrd.$$/proc/self"); + + # Network related scripts + #system("echo $kernelver\n"); + #system("mkdir -p /tmp/xcatinitrd.$$/sbin"); + #system("cp -r $rootimg_dir/sbin/* /tmp/xcatinitrd.$$/sbin"); + #system("mkdir -p /tmp/xcatinitrd.$$/lib/modules/$kernelver"); + #system("cp -r $rootimg_dir/lib/modules/$kernelver/modules.dep /tmp/xcatinitrd.$$/lib/modules/$kernelver/modules.dep"); + #system("mkdir -p /tmp/xcatinitrd.$$/etc/init.d"); + #system("cp -r $rootimg_dir/etc/init.d/* /tmp/xcatinitrd.$$/etc/init.d"); + #system("mkdir -p /tmp/xcatinitrd.$$/lib64"); + #system("cp -r $rootimg_dir/lib64/* /tmp/xcatinitrd.$$/lib64"); + #system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport"); + symlink("busybox","/tmp/xcatinitrd.$$/bin/pivot_root"); + symlink("busybox", "/tmp/xcatinitrd.$$/bin/udhcpc"); + symlink("busybox", "/tmp/xcatinitrd.$$/sbin/ifconfig"); + symlink("busybox", "/tmp/xcatinitrd.$$/bin/hostname"); + symlink("busybox", "/tmp/xcatinitrd.$$/bin/route"); + symlink("busybox", "/tmp/xcatinitrd.$$/bin/nc"); + symlink("bash", "/tmp/xcatinitrd.$$/bin/sh"); + symlink("bash", "/tmp/xcatinitrd.$$/sbin/sh"); - - #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); - system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd-$mode.gz"); - system("rm -rf /tmp/xcatinitrd.$$"); + + my $compress="gzip"; + #if pigz is available,use pigz instead of gzip + my $ispigz=system("bash -c 'type -p pigz' >/dev/null 2>&1"); + if($ispigz == 0){ + $compress="pigz"; + }else{ + $compress="gzip"; + } + + + #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); + print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz \n"; + system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz"); + system("rm -rf /tmp/xcatinitrd.$$"); } From 81409e1899b3440b4af89157a563b2eb11ba055a Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 28 Aug 2015 02:56:26 -0400 Subject: [PATCH 2/4] use pigz instead of gzip in liteimg --- xCAT-server/lib/xcat/plugins/statelite.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/statelite.pm b/xCAT-server/lib/xcat/plugins/statelite.pm index bac31cac3..7e5ffd58c 100644 --- a/xCAT-server/lib/xcat/plugins/statelite.pm +++ b/xCAT-server/lib/xcat/plugins/statelite.pm @@ -522,15 +522,26 @@ sub process_request { my $oldmask; $callback->({data=>["$verb contents of $rootimg_dir"]}); unlink("$destdir/rootimg-statelite.gz"); + + + my $compress="gzip"; + #use "pigz" as the compress tool instead of gzip if "pigz" exist + my $ispigz=system("bash -c 'type -p pigz'"); + if($ispigz == 0){ + $compress="pigz"; + } + + $callback->({info=>["compress method: $compress"]}); + if ($exlistloc) { chdir("$rootimg_dir"); system("$excludestr >> $xcat_packimg_tmpfile"); if ( $includestr) { system("$includestr >> $xcat_packimg_tmpfile"); } - $excludestr = "cat $xcat_packimg_tmpfile |cpio -H newc -o | gzip -c - > ../rootimg-statelite.gz"; + $excludestr = "cat $xcat_packimg_tmpfile |cpio -H newc -o | $compress -c - > ../rootimg-statelite.gz"; } else { - $excludestr = "find . |cpio -H newc -o | gzip -c - > ../rootimg-statelite.gz"; + $excludestr = "find . |cpio -H newc -o | $compress -c - > ../rootimg-statelite.gz"; } $oldmask = umask 0077; chdir("$rootimg_dir"); From 8dea21b6c1ac6ffc020d84057950548bbb95ea36 Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 28 Aug 2015 03:00:19 -0400 Subject: [PATCH 3/4] remove some code commented out --- xCAT-server/share/xcat/netboot/ubuntu/genimage | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index 7ab1679d0..dd880ad36 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -1624,9 +1624,6 @@ EOMS } -# if (-d "$rootimg_dir/lib/powerpc64le-linux-gnu/"){ -# system("cp -rf $rootimg_dir/lib/powerpc64le-linux-gnu/* /tmp/xcatinitrd.$$/lib/powerpc64le-linux-gnu/"); -# } system("chroot /tmp/xcatinitrd.$$/ depmod $kernelver"); # Copy udev and network scripts into initrd for s390x, which also works for other platforms @@ -1639,16 +1636,6 @@ EOMS system("cp -r /proc/self/oom_adj /tmp/xcatinitrd.$$/proc/self"); # Network related scripts - #system("echo $kernelver\n"); - #system("mkdir -p /tmp/xcatinitrd.$$/sbin"); - #system("cp -r $rootimg_dir/sbin/* /tmp/xcatinitrd.$$/sbin"); - #system("mkdir -p /tmp/xcatinitrd.$$/lib/modules/$kernelver"); - #system("cp -r $rootimg_dir/lib/modules/$kernelver/modules.dep /tmp/xcatinitrd.$$/lib/modules/$kernelver/modules.dep"); - #system("mkdir -p /tmp/xcatinitrd.$$/etc/init.d"); - #system("cp -r $rootimg_dir/etc/init.d/* /tmp/xcatinitrd.$$/etc/init.d"); - #system("mkdir -p /tmp/xcatinitrd.$$/lib64"); - #system("cp -r $rootimg_dir/lib64/* /tmp/xcatinitrd.$$/lib64"); - #system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport"); symlink("busybox","/tmp/xcatinitrd.$$/bin/pivot_root"); symlink("busybox", "/tmp/xcatinitrd.$$/bin/udhcpc"); symlink("busybox", "/tmp/xcatinitrd.$$/sbin/ifconfig"); From 4114a4f6a96bc8610139938eedd67a7b4cc2f293 Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 28 Aug 2015 03:29:09 -0400 Subject: [PATCH 4/4] fix some codeing style problems --- xCAT-server/lib/xcat/plugins/packimage.pm | 3 +-- xCAT-server/lib/xcat/plugins/statelite.pm | 3 +-- xCAT-server/share/xcat/netboot/rh/genimage | 6 ++---- xCAT-server/share/xcat/netboot/sles/genimage | 3 +-- xCAT-server/share/xcat/netboot/ubuntu/genimage | 4 ---- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index f93823588..c84e12cdd 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -369,7 +369,7 @@ sub process_request { my $compress="gzip"; #use "pigz" as the compress tool instead of gzip if "pigz" exist - my $ispigz=system("bash -c 'type -p pigz'"); + my $ispigz=system("bash -c 'type -p pigz' >/dev/null 2>&1"); if($ispigz == 0){ $compress="pigz"; } @@ -385,7 +385,6 @@ sub process_request { if ($includestr) { system("$includestr >> $xcat_packimg_tmpfile"); } - #$excludestr =~ s!-a \z!|cpio -H newc -o | $compress -c - > ../rootimg.gz!; $excludestr = "cat $xcat_packimg_tmpfile|cpio -H newc -o | $compress -c - > ../rootimg.gz"; } $oldmask = umask 0077; diff --git a/xCAT-server/lib/xcat/plugins/statelite.pm b/xCAT-server/lib/xcat/plugins/statelite.pm index 7e5ffd58c..d355d9bee 100644 --- a/xCAT-server/lib/xcat/plugins/statelite.pm +++ b/xCAT-server/lib/xcat/plugins/statelite.pm @@ -523,10 +523,9 @@ sub process_request { $callback->({data=>["$verb contents of $rootimg_dir"]}); unlink("$destdir/rootimg-statelite.gz"); - my $compress="gzip"; #use "pigz" as the compress tool instead of gzip if "pigz" exist - my $ispigz=system("bash -c 'type -p pigz'"); + my $ispigz=system("bash -c 'type -p pigz' >/dev/null 2>&1"); if($ispigz == 0){ $compress="pigz"; } diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index e7076f58c..4fc0f4a09 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -949,14 +949,11 @@ sub mkinitrd_dracut { $additional_options= qq{--include /tmp/cmdline /etc/cmdline}; } - - # force the dracut run in non-hostonly mode for dracut higher than version 033 if ($dracutver > "033") { $additional_options .= " -N"; } - #if "pigz" is available in the rootimg, use "pigz" instead of "gzip" my $compress=qx(chroot $rootimg_dir bash -c "type -p pigz"|tr -d "\n"); if ($compress){ @@ -964,7 +961,8 @@ sub mkinitrd_dracut { my $processnum=qx(lscpu -p=cpu --online|grep -v '#'|wc -l|tr -d "\n"); $additional_options .= " --compress \"$compress -p $processnum \""; } - print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; + + print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; !system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver") or die("Error: failed to generate the initial ramdisk for $mode.\n"); print "the initial ramdisk for $mode is generated successfully.\n"; diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index 1bb216ef4..24a780a4c 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -1088,7 +1088,6 @@ sub mkinitrd_dracut { $additional_options .= " -N"; } - #if "pigz" is available in the rootimg, use "pigz" instead of "gzip" my $compress=qx(chroot $rootimg_dir bash -c "type -p pigz"|tr -d "\n"); if ($compress){ @@ -1096,8 +1095,8 @@ sub mkinitrd_dracut { my $processnum=qx(lscpu -p=cpu --online|grep -v '#'|wc -l|tr -d "\n"); $additional_options .= " --compress \"$compress -p $processnum \""; } - print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; + print "\nchroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver\n"; !system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver") or die("Error: failed to generate the initial ramdisk for $mode.\n"); print "the initial ramdisk for $mode is generated successfully.\n"; diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index dd880ad36..f49573d3f 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -1645,17 +1645,13 @@ EOMS symlink("bash", "/tmp/xcatinitrd.$$/bin/sh"); symlink("bash", "/tmp/xcatinitrd.$$/sbin/sh"); - my $compress="gzip"; #if pigz is available,use pigz instead of gzip my $ispigz=system("bash -c 'type -p pigz' >/dev/null 2>&1"); if($ispigz == 0){ $compress="pigz"; - }else{ - $compress="gzip"; } - #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz \n"; system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz");