diff mbox series

[2/2] fs/squashfs: Add option to compress with extreme options

Message ID 20220517032459.3400-2-linus@cosmos-ink.net
State Accepted
Headers show
Series [1/2] fs/squashfs: Add block size option | expand

Commit Message

Linus May 17, 2022, 3:24 a.m. UTC
mksquashfs allows to tweak many compressions parameters. Currently they
can't be changed from kmenu. Leaving out potential space savings.

This adds the option to enable a set of predetermined compression
options. This option is enabled by default for lz4 since lz4 currently
implicitly added the extreme to it in the makefile. So this aids in
keeping backward compatibility.

Signed-off-by: Linus Kaschulla <linus@cosmos-ink.net>
---
 fs/squashfs/Config.in   | 26 ++++++++++++++++++++++++++
 fs/squashfs/squashfs.mk |  6 +++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

Comments

Yann E. MORIN May 17, 2022, 6:09 a.m. UTC | #1
Linus, All,

On 2022-05-17 03:24 +0000, Linus Kaschulla via buildroot spake thusly:
> mksquashfs allows to tweak many compressions parameters. Currently they
> can't be changed from kmenu. Leaving out potential space savings.
> 
> This adds the option to enable a set of predetermined compression
> options. This option is enabled by default for lz4 since lz4 currently
> implicitly added the extreme to it in the makefile. So this aids in
> keeping backward compatibility.
> 
> Signed-off-by: Linus Kaschulla <linus@cosmos-ink.net>
> ---
>  fs/squashfs/Config.in   | 26 ++++++++++++++++++++++++++
>  fs/squashfs/squashfs.mk |  6 +++++-
>  2 files changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/squashfs/Config.in b/fs/squashfs/Config.in
> index 341e50a08c..41c782105d 100644
> --- a/fs/squashfs/Config.in
> +++ b/fs/squashfs/Config.in
> @@ -89,4 +89,30 @@ config BR2_TARGET_ROOTFS_SQUASHFS4_ZSTD
>  
>  endchoice
>  
> +config BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP
> +	bool "extreme compression if possible"
> +	default BR2_TARGET_ROOTFS_SQUASHFS4_LZ4

This is technically correct, but we are not using that code style
anywhere else (that I am aware of), so I tweaked it to the more
tracitional form we use everywhere else. I also added a comment to
explain why it is:
    default y if BR2_TARGET_ROOTFS_SQUASHFS4_LZ4  # legacy

> +	help
> +	  Use options to increase compression ration as much as
> +	  possible, like using architecture-specific options, at
> +	  the cost of time when assembling the filesystem image.
> +
> +	  For example:
> +	   - with gzip and lzo, use -Xcompression-level 9
> +	   - with xz use a architecture specific bjc (branch-call-jump) filter
> +	   - with zstd use -Xcompression-level 22
> +	   - and more

    $ make check-package
    WARNING: fs/squashfs/Config.in:102: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)

> +config BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS
> +	string
> +	depends on BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP
> +	default "-Xcompression-level 9" if BR2_TARGET_ROOTFS_SQUASHFS4_GZIP
> +	default "-Xcompression-level 9" if BR2_TARGET_ROOTFS_SQUASHFS4_LZO
> +	default "-Xhc" if BR2_TARGET_ROOTFS_SQUASHFS4_LZ4
> +	default "-Xbcj arm,armthumb" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_arm || BR_aarch64)
> +	default "-Xbcj powerpc" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_powerpc || BR2_powerpc64)
> +	default "-Xbcj sparc" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_sparc || BR2_sparc64)
> +	default "-Xbcj x86" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_i386 || BR2_x86_64)
> +	default "-Xcompression-level 22" if BR2_TARGET_ROOTFS_SQUASHFS4_ZSTD

    $ make check-package
    WARNING: fs/squashfs/Config.in:109: attributes order: type, default, depends on, select, help (http://nightly.buildroot.org/#_config_files)

So I fixed that too.

>  endif
> diff --git a/fs/squashfs/squashfs.mk b/fs/squashfs/squashfs.mk
> index 1790773f7e..51f8d0d7c9 100644
> --- a/fs/squashfs/squashfs.mk
> +++ b/fs/squashfs/squashfs.mk
> @@ -25,7 +25,7 @@ ROOTFS_SQUASHFS_ARGS += -nopad
>  endif
>  
>  ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZ4),y)
> -ROOTFS_SQUASHFS_ARGS += -comp lz4 -Xhc
> +ROOTFS_SQUASHFS_ARGS += -comp lz4
>  else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZO),y)
>  ROOTFS_SQUASHFS_ARGS += -comp lzo
>  else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZMA),y)
> @@ -38,6 +38,10 @@ else
>  ROOTFS_SQUASHFS_ARGS += -comp gzip
>  endif
>  
> +ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP),y)
> +ROOTFS_SQUASHFS_ARGS += $(call qstrip,$(BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS))
> +endif

If BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP is not set, or if no
condition match, then BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS will be an
empty string, so we can just always expand it unconditionally.

Applied to master with the abov e fixed;
  - fix check-package
  - change the default code-style, add the legacy comment
  - always add the qstriped string, as it's empty when not used

Thanks!

Ditto, a test-case would be awesome!

Regards,
Yann E. MORIN.

>  define ROOTFS_SQUASHFS_CMD
>  	$(HOST_DIR)/bin/mksquashfs $(TARGET_DIR) $@ $(ROOTFS_SQUASHFS_ARGS)
>  endef
> -- 
> 2.35.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/fs/squashfs/Config.in b/fs/squashfs/Config.in
index 341e50a08c..41c782105d 100644
--- a/fs/squashfs/Config.in
+++ b/fs/squashfs/Config.in
@@ -89,4 +89,30 @@  config BR2_TARGET_ROOTFS_SQUASHFS4_ZSTD
 
 endchoice
 
+config BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP
+	bool "extreme compression if possible"
+	default BR2_TARGET_ROOTFS_SQUASHFS4_LZ4
+	help
+	  Use options to increase compression ration as much as
+	  possible, like using architecture-specific options, at
+	  the cost of time when assembling the filesystem image.
+
+	  For example:
+	   - with gzip and lzo, use -Xcompression-level 9
+	   - with xz use a architecture specific bjc (branch-call-jump) filter
+	   - with zstd use -Xcompression-level 22
+	   - and more
+
+config BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS
+	string
+	depends on BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP
+	default "-Xcompression-level 9" if BR2_TARGET_ROOTFS_SQUASHFS4_GZIP
+	default "-Xcompression-level 9" if BR2_TARGET_ROOTFS_SQUASHFS4_LZO
+	default "-Xhc" if BR2_TARGET_ROOTFS_SQUASHFS4_LZ4
+	default "-Xbcj arm,armthumb" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_arm || BR_aarch64)
+	default "-Xbcj powerpc" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_powerpc || BR2_powerpc64)
+	default "-Xbcj sparc" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_sparc || BR2_sparc64)
+	default "-Xbcj x86" if BR2_TARGET_ROOTFS_SQUASHFS4_XZ && (BR2_i386 || BR2_x86_64)
+	default "-Xcompression-level 22" if BR2_TARGET_ROOTFS_SQUASHFS4_ZSTD
+
 endif
diff --git a/fs/squashfs/squashfs.mk b/fs/squashfs/squashfs.mk
index 1790773f7e..51f8d0d7c9 100644
--- a/fs/squashfs/squashfs.mk
+++ b/fs/squashfs/squashfs.mk
@@ -25,7 +25,7 @@  ROOTFS_SQUASHFS_ARGS += -nopad
 endif
 
 ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZ4),y)
-ROOTFS_SQUASHFS_ARGS += -comp lz4 -Xhc
+ROOTFS_SQUASHFS_ARGS += -comp lz4
 else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZO),y)
 ROOTFS_SQUASHFS_ARGS += -comp lzo
 else ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS4_LZMA),y)
@@ -38,6 +38,10 @@  else
 ROOTFS_SQUASHFS_ARGS += -comp gzip
 endif
 
+ifeq ($(BR2_TARGET_ROOTFS_SQUASHFS_EXTREME_COMP),y)
+ROOTFS_SQUASHFS_ARGS += $(call qstrip,$(BR2_TARGET_ROOTFS_SQUASHFS_COMP_OPTS))
+endif
+
 define ROOTFS_SQUASHFS_CMD
 	$(HOST_DIR)/bin/mksquashfs $(TARGET_DIR) $@ $(ROOTFS_SQUASHFS_ARGS)
 endef