diff options
author | Bertrand Jacquin <beber@meleeweb.net> | 2014-08-27 07:01:56 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2014-08-27 08:24:12 -0400 |
commit | beb50df39e91745604ce3cb9dc6a503f39f4383d (patch) | |
tree | eaa6a996228eb532f56f46d1b5004a10062ac4fa | |
parent | 40e42f6a2596bbe757e561d4806fadd924f8c9fd (diff) |
kbuild: handle module compression while running 'make modules_install'.
Since module-init-tools (gzip) and kmod (gzip and xz) support compressed
modules, it could be useful to include a support for compressing modules
right after having them installed. Doing this in kbuild instead of per
distro can permit to make this kind of usage more generic.
This patch add a Kconfig entry to "Enable loadable module support" menu
and let you choose to compress using gzip (default) or xz.
Both gzip and xz does not used any extra -[1-9] option since Andi Kleen
and Rusty Russell prove no gain is made using them. gzip is called with -n
argument to avoid storing original filename inside compressed file, that
way we can save some more bytes.
On a v3.16 kernel, 'make allmodconfig' generated 4680 modules for a
total of 378MB (no strip, no sign, no compress), the following table
shows observed disk space gain based on the allmodconfig .config :
| time |
+-------------+-----------------+
| manual .ko | make | size | percent
| compression | modules_install | | gain
+-------------+-----------------+------+--------
- | | 18.61s | 378M |
GZIP | 3m16s | 3m37s | 102M | 73.41%
XZ | 5m22s | 5m39s | 77M | 79.83%
The gain for restricted environnement seems to be interesting while
uncompress can be time consuming but happens only while loading a module,
that is generally done only once.
This is fully compatible with signed modules while the signed module is
compressed. module-init-tools or kmod handles decompression
and provide to other layer the uncompressed but signed payload.
Reviewed-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Bertrand Jacquin <beber@meleeweb.net>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | init/Kconfig | 43 | ||||
-rw-r--r-- | scripts/Makefile.modinst | 3 |
3 files changed, 60 insertions, 1 deletions
@@ -842,6 +842,21 @@ mod_strip_cmd = true | |||
842 | endif # INSTALL_MOD_STRIP | 842 | endif # INSTALL_MOD_STRIP |
843 | export mod_strip_cmd | 843 | export mod_strip_cmd |
844 | 844 | ||
845 | # CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed | ||
846 | # after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP | ||
847 | # or CONFIG_MODULE_COMPRESS_XZ. | ||
848 | |||
849 | mod_compress_cmd = true | ||
850 | ifdef CONFIG_MODULE_COMPRESS | ||
851 | ifdef CONFIG_MODULE_COMPRESS_GZIP | ||
852 | mod_compress_cmd = gzip -n | ||
853 | endif # CONFIG_MODULE_COMPRESS_GZIP | ||
854 | ifdef CONFIG_MODULE_COMPRESS_XZ | ||
855 | mod_compress_cmd = xz | ||
856 | endif # CONFIG_MODULE_COMPRESS_XZ | ||
857 | endif # CONFIG_MODULE_COMPRESS | ||
858 | export mod_compress_cmd | ||
859 | |||
845 | # Select initial ramdisk compression format, default is gzip(1). | 860 | # Select initial ramdisk compression format, default is gzip(1). |
846 | # This shall be used by the dracut(8) tool while creating an initramfs image. | 861 | # This shall be used by the dracut(8) tool while creating an initramfs image. |
847 | # | 862 | # |
diff --git a/init/Kconfig b/init/Kconfig index e84c6423a2e5..4980925bf348 100644 --- a/init/Kconfig +++ b/init/Kconfig | |||
@@ -1906,6 +1906,49 @@ config MODULE_SIG_HASH | |||
1906 | default "sha384" if MODULE_SIG_SHA384 | 1906 | default "sha384" if MODULE_SIG_SHA384 |
1907 | default "sha512" if MODULE_SIG_SHA512 | 1907 | default "sha512" if MODULE_SIG_SHA512 |
1908 | 1908 | ||
1909 | config MODULE_COMPRESS | ||
1910 | bool "Compress modules on installation" | ||
1911 | depends on MODULES | ||
1912 | help | ||
1913 | This option compresses the kernel modules when 'make | ||
1914 | modules_install' is run. | ||
1915 | |||
1916 | The modules will be compressed either using gzip or xz depend on the | ||
1917 | choice made in "Compression algorithm". | ||
1918 | |||
1919 | module-init-tools has support for gzip format while kmod handle gzip | ||
1920 | and xz compressed modules. | ||
1921 | |||
1922 | When a kernel module is installed from outside of the main kernel | ||
1923 | source and uses the Kbuild system for installing modules then that | ||
1924 | kernel module will also be compressed when it is installed. | ||
1925 | |||
1926 | This option provides little benefit when the modules are to be used inside | ||
1927 | an initrd or initramfs, it generally is more efficient to compress the whole | ||
1928 | initrd or initramfs instead. | ||
1929 | |||
1930 | This is fully compatible with signed modules while the signed module is | ||
1931 | compressed. module-init-tools or kmod handles decompression and provide to | ||
1932 | other layer the uncompressed but signed payload. | ||
1933 | |||
1934 | choice | ||
1935 | prompt "Compression algorithm" | ||
1936 | depends on MODULE_COMPRESS | ||
1937 | default MODULE_COMPRESS_GZIP | ||
1938 | help | ||
1939 | This determines which sort of compression will be used during | ||
1940 | 'make modules_install'. | ||
1941 | |||
1942 | GZIP (default) and XZ are supported. | ||
1943 | |||
1944 | config MODULE_COMPRESS_GZIP | ||
1945 | bool "GZIP" | ||
1946 | |||
1947 | config MODULE_COMPRESS_XZ | ||
1948 | bool "XZ" | ||
1949 | |||
1950 | endchoice | ||
1951 | |||
1909 | endif # MODULES | 1952 | endif # MODULES |
1910 | 1953 | ||
1911 | config INIT_ALL_POSSIBLE | 1954 | config INIT_ALL_POSSIBLE |
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index aa911b557bde..e48a4e9d8868 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst | |||
@@ -22,7 +22,8 @@ quiet_cmd_modules_install = INSTALL $@ | |||
22 | mkdir -p $(2) ; \ | 22 | mkdir -p $(2) ; \ |
23 | cp $@ $(2) ; \ | 23 | cp $@ $(2) ; \ |
24 | $(mod_strip_cmd) $(2)/$(notdir $@) ; \ | 24 | $(mod_strip_cmd) $(2)/$(notdir $@) ; \ |
25 | $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) | 25 | $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ |
26 | $(mod_compress_cmd) $(2)/$(notdir $@) | ||
26 | 27 | ||
27 | # Modules built outside the kernel source tree go into extra by default | 28 | # Modules built outside the kernel source tree go into extra by default |
28 | INSTALL_MOD_DIR ?= extra | 29 | INSTALL_MOD_DIR ?= extra |