Skip to content

Commit

Permalink
[build] enable pigz by default (sonic-net#16959)
Browse files Browse the repository at this point in the history
Why I did it
pigz, which stands for parallel implementation of gzip,
is a fully functional replacement for gzip that exploits multiple processors
and multiple cores to the hilt when compressing data.

We can use it for compression instead of gzip to speed up builds.
It reduces build time (especially at final stage where we compress whole file system).

But solution with special option GZ_COMPRESS_PROGRAM is not good,
because it's hard to maintain (developers need to pass this flag to every script).
I think it's better to remove this option at all and use pigz directly where it's possible.

How I did it
Remove config flag GZ_COMPRESS_PROGRAM
Use pigz directly instead of gzip where it's possible.

How to verify it
I have tested builds with pigz almost 1 year and no issues were detected.
So I think it's better to enable it by default for all builds.
If we found some issues we can always replace pigz with gzip.
  • Loading branch information
k-v1 authored and pull[bot] committed Jul 22, 2024
1 parent 65b2eb4 commit cdf0da7
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 27 deletions.
9 changes: 0 additions & 9 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
# * ENABLE_BOOTCHART: Enable SONiC bootchart
# * Default: n
# * Values: y,n
# * GZ_COMPRESS_PROGRAM: Select pigz to reduce build time
# * Default: gzip
# * Values: pigz,gzip
# * UNATTENDED: Don't wait for interactive input from terminal, setting this
# * value to anything will enable it
# * Default: unset
Expand Down Expand Up @@ -157,10 +154,6 @@ ifeq ($(LEGACY_SONIC_MGMT_DOCKER),)
override LEGACY_SONIC_MGMT_DOCKER = y
endif

ifneq ($(GZ_COMPRESS_PROGRAM), pigz)
override GZ_COMPRESS_PROGRAM = gzip
endif

ifeq ($(CONFIGURED_ARCH),amd64)
SLAVE_BASE_IMAGE = $(SLAVE_DIR)
MULTIARCH_QEMU_ENVIRON = n
Expand Down Expand Up @@ -229,7 +222,6 @@ $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) \
INCLUDE_FIPS=$(INCLUDE_FIPS) \
DOCKER_EXTRA_OPTS=$(DOCKER_EXTRA_OPTS) \
DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) \
GZ_COMPRESS_PROGRAM=$(GZ_COMPRESS_PROGRAM) \
j2 $(SLAVE_DIR)/Dockerfile.j2 > $(SLAVE_DIR)/Dockerfile)

$(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) \
Expand Down Expand Up @@ -587,7 +579,6 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
SONIC_SLAVE_DOCKER_DRIVER=$(SONIC_SLAVE_DOCKER_DRIVER) \
MIRROR_URLS=$(MIRROR_URLS) \
MIRROR_SECURITY_URLS=$(MIRROR_SECURITY_URLS) \
GZ_COMPRESS_PROGRAM=$(GZ_COMPRESS_PROGRAM) \
MIRROR_SNAPSHOT=$(MIRROR_SNAPSHOT) \
SONIC_VERSION_CONTROL_COMPONENTS=$(SONIC_VERSION_CONTROL_COMPONENTS) \
ONIE_IMAGE_PART_SIZE=$(ONIE_IMAGE_PART_SIZE) \
Expand Down
8 changes: 3 additions & 5 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ else
fi

## docker and mkinitramfs on target system will use pigz/unpigz automatically
if [[ $GZ_COMPRESS_PROGRAM == pigz ]]; then
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install pigz
fi
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install pigz

## Install initramfs-tools and linux kernel
## Note: initramfs-tools recommends depending on busybox, and we really want busybox for
Expand Down Expand Up @@ -879,8 +877,8 @@ if [[ $MULTIARCH_QEMU_ENVIRON == y || $CROSS_BUILD_ENVIRON == y ]]; then
fi

## Compress docker files
pushd $FILESYSTEM_ROOT && sudo tar -I $GZ_COMPRESS_PROGRAM -cf $OLDPWD/$FILESYSTEM_DOCKERFS -C ${DOCKERFS_PATH}var/lib/docker .; popd
pushd $FILESYSTEM_ROOT && sudo tar -I pigz -cf $OLDPWD/$FILESYSTEM_DOCKERFS -C ${DOCKERFS_PATH}var/lib/docker .; popd

## Compress together with /boot, /var/lib/docker and $PLATFORM_DIR as an installer payload zip file
pushd $FILESYSTEM_ROOT && sudo tar -I $GZ_COMPRESS_PROGRAM -cf platform.tar.gz -C $PLATFORM_DIR . && sudo zip -n .gz $OLDPWD/$INSTALLER_PAYLOAD -r boot/ platform.tar.gz; popd
pushd $FILESYSTEM_ROOT && sudo tar -I pigz -cf platform.tar.gz -C $PLATFORM_DIR . && sudo zip -n .gz $OLDPWD/$INSTALLER_PAYLOAD -r boot/ platform.tar.gz; popd
sudo zip -g -n .squashfs:.gz $INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS
4 changes: 2 additions & 2 deletions build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ generate_kvm_image()
exit 1
}

$GZ_COMPRESS_PROGRAM $KVM_IMAGE_DISK
pigz $KVM_IMAGE_DISK

[ -r $KVM_IMAGE_DISK.gz ] || {
echo "Error : $GZ_COMPRESS_PROGRAM $KVM_IMAGE_DISK failed!"
echo "Error : pigz $KVM_IMAGE_DISK failed!"
exit 1
}

Expand Down
4 changes: 0 additions & 4 deletions rules/config
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ ENABLE_FIPS ?= n
# SONIC_SLAVE_DOCKER_DRIVER - set the sonic slave docker storage driver
SONIC_SLAVE_DOCKER_DRIVER ?= vfs

# GZ_COMPRESS_PROGRAM - select pigz (a parallel implementation of gzip) to reduce a build time
# and speed up a decompression of docker images on target system
GZ_COMPRESS_PROGRAM ?= gzip

# SONIC_OS_VERSION - sonic os version
SONIC_OS_VERSION ?= 12

Expand Down
4 changes: 1 addition & 3 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export DOCKER_BASE_ARCH
export CROSS_BUILD_ENVIRON
export BLDENV
export BUILD_WORKDIR
export GZ_COMPRESS_PROGRAM
export MIRROR_SNAPSHOT
export SONIC_OS_VERSION
export FILES_PATH
Expand Down Expand Up @@ -461,7 +460,6 @@ ifeq ($(CONFIGURED_PLATFORM),vs)
$(info "BUILD_MULTIASIC_KVM" : "$(BUILD_MULTIASIC_KVM)")
endif
$(info "CROSS_BUILD_ENVIRON" : "$(CROSS_BUILD_ENVIRON)")
$(info "GZ_COMPRESS_PROGRAM" : "$(GZ_COMPRESS_PROGRAM)")
$(info "LEGACY_SONIC_MGMT_DOCKER" : "$(LEGACY_SONIC_MGMT_DOCKER)")
$(info "INCLUDE_EXTERNAL_PATCHES" : "$(INCLUDE_EXTERNAL_PATCHES)")
$(info "PTF_ENV_PY_VER" : "$(PTF_ENV_PY_VER)")
Expand Down Expand Up @@ -553,7 +551,7 @@ define docker-image-save
@echo "Tagging docker image $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) as $(1):$(call docker-get-tag,$(1))" $(LOG)
docker tag $(1)-$(DOCKER_USERNAME):$(DOCKER_USERTAG) $(1):$(call docker-get-tag,$(1)) $(LOG)
@echo "Saving docker image $(1):$(call docker-get-tag,$(1))" $(LOG)
docker save $(1):$(call docker-get-tag,$(1)) | $(GZ_COMPRESS_PROGRAM) -c > $(2)
docker save $(1):$(call docker-get-tag,$(1)) | pigz -c > $(2)
if [ x$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) == x"y" ]; then
@echo "Removing docker image $(1):$(call docker-get-tag,$(1))" $(LOG)
docker rmi -f $(1):$(call docker-get-tag,$(1)) $(LOG)
Expand Down
3 changes: 2 additions & 1 deletion sonic-slave-bookworm/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ RUN apt-get update && apt-get install -y \
curl \
wget \
unzip \
{{ GZ_COMPRESS_PROGRAM }} \
gzip \
pigz \
git \
build-essential \
remake \
Expand Down
3 changes: 2 additions & 1 deletion sonic-slave-bullseye/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install
curl \
wget \
unzip \
{{ GZ_COMPRESS_PROGRAM }} \
gzip \
pigz \
git \
build-essential \
remake \
Expand Down
3 changes: 2 additions & 1 deletion sonic-slave-buster/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ RUN apt-get update && apt-get install -y eatmydata && eatmydata apt-get install
curl \
wget \
unzip \
{{ GZ_COMPRESS_PROGRAM }} \
gzip \
pigz \
git \
build-essential \
remake \
Expand Down
3 changes: 2 additions & 1 deletion sonic-slave-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ RUN apt-get update && apt-get install -y \
curl \
wget \
unzip \
{{ GZ_COMPRESS_PROGRAM }} \
gzip \
pigz \
git \
build-essential \
libtool \
Expand Down

0 comments on commit cdf0da7

Please sign in to comment.