public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* /proc/config reducing kernel image size
@ 2004-09-14 16:33 Tom Fredrik Blenning Klaussen
  2004-09-14 17:26 ` DervishD
  2004-09-14 17:44 ` Norberto Bensa
  0 siblings, 2 replies; 8+ messages in thread
From: Tom Fredrik Blenning Klaussen @ 2004-09-14 16:33 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

I've written a small patch that reduces the size of /proc/config.

There is no point in storing all the comments and unused options in the
kernel image. This typically reduces the config size to about 1/5th
before compressing, and to about 1/4th after compressing.

I've also added the configuration option of how you want to compress it.

In order to do the comment stripping I was forced to add a small script
to the scripts, section, this has to be made executable. However if it
is possible, the script should be skipped altogether, but I can't figure
out how to do the proper escaping of the special characters in the
kernel/Makefile. So if anyone could help me with that, I would be
grateful.

I'm interessted in comments on the concept.

Sincerely
-- 
BFG

[-- Attachment #2: linux-2.6.8.1-config-compress-patch.diff --]
[-- Type: text/x-patch, Size: 6697 bytes --]

diff -ruN /usr/src/linux-2.6.8.1/init/Kconfig ./init/Kconfig
--- /usr/src/linux-2.6.8.1/init/Kconfig	2004-08-31 13:11:45.000000000 +0200
+++ ./init/Kconfig	2004-09-12 19:51:06.000000000 +0200
@@ -197,6 +197,8 @@
 	  agent" (/sbin/hotplug) to load modules and set up software needed
 	  to use devices as you hotplug them.
 
+menu "Kernel .config support"
+
 config IKCONFIG
 	bool "Kernel .config support"
 	---help---
@@ -209,13 +211,71 @@
 	  It can also be extracted from a running kernel by reading
 	  /proc/config.gz if enabled (below).
 
-config IKCONFIG_PROC
-	bool "Enable access to .config through /proc/config.gz"
-	depends on IKCONFIG && PROC_FS
+config IKCONFIG_STRIP
+	bool "Strip comments and unused options"
+	depends on IKCONFIG
+	---help---
+	  This option strips all comments and options that increases 
+          human readability, but are unnecessary for the parsing 
+          process.
+
+choice
+        prompt "Config compression method"
+	depends on IKCONFIG
+        default IKCONFIG_COMPRESS_NONE
+	---help---
+	  Choose which kind of compression that will be used for the 
+          kernel copy of the config file.
+
+config IKCONFIG_COMPRESS_NONE
+	bool "None"
+	---help---
+	  This option disables config file compression.
+
+
+config IKCONFIG_COMPRESS_GZIP
+	bool "Gzip"
+	---help---
+	  This option enables gzip config file compression.
+
+          Gzip is the standard compression utility that can be found on 
+          any UNIX machine.
+
+config IKCONFIG_COMPRESS_BZIP2
+	bool "Bzip2 (RECOMMENDED)"
 	---help---
-	  This option enables access to the kernel configuration file
-	  through /proc/config.gz.
+	  This option enables bzip2 config file compression.
+
+          Bzip2 is designed for text compression, and is slightly better 
+          than gzip for this purpose.
 
+endchoice
+
+config IKCONFIG_PROC
+        bool "Enable access to .config through /proc/config"
+        depends on IKCONFIG_COMPRESS_NONE && PROC_FS
+        ---help---
+          This option enables access to the kernel configuration file
+          through /proc/config.
+
+
+config IKCONFIG_PROC
+        bool "Enable access to .config through /proc/config.gz"
+        depends on IKCONFIG_COMPRESS_GZIP && PROC_FS
+        ---help---
+          This option enables access to the kernel configuration file
+          through /proc/config.gz.
+
+
+config IKCONFIG_PROC
+        bool "Enable access to .config through /proc/config.bz2"
+        depends on IKCONFIG_COMPRESS_BZIP2 && PROC_FS
+        ---help---
+          This option enables access to the kernel configuration file
+          through /proc/config.bz2.
+
+
+endmenu
 
 menuconfig EMBEDDED
 	bool "Configure standard kernel features (for small systems)"
diff -ruN /usr/src/linux-2.6.8.1/kernel/Makefile ./kernel/Makefile
--- /usr/src/linux-2.6.8.1/kernel/Makefile	2004-08-31 13:11:45.000000000 +0200
+++ ./kernel/Makefile	2004-09-12 20:08:02.000000000 +0200
@@ -19,6 +19,8 @@
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_COMPAT) += compat.o
 obj-$(CONFIG_IKCONFIG) += configs.o
+#Is this strictly needed? CONFIG_IKCONFIG_PROC should only be defined 
+# if CONFIG_IKCONFIG is defined.
 obj-$(CONFIG_IKCONFIG_PROC) += configs.o
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
 obj-$(CONFIG_AUDIT) += audit.o
@@ -35,14 +37,48 @@
 
 $(obj)/configs.o: $(obj)/config_data.h
 
-# config_data.h contains the same information as ikconfig.h but gzipped.
-# Info from config_data can be extracted from /proc/config*
-targets += config_data.gz
-$(obj)/config_data.gz: .config FORCE
-	$(call if_changed,gzip)
 
-quiet_cmd_ikconfiggz = IKCFG   $@
-      cmd_ikconfiggz = (echo "const char kernel_config_data[] = MAGIC_START"; cat $< | scripts/bin2c; echo "MAGIC_END;") > $@
+#define the stripping command, basically strip or copy
+ifdef CONFIG_IKCONFIG_STRIP
+quiet_cmd_ikconfig_strip = STRIP   $@
+	cmd_ikconfig_strip = scripts/stripCommBlank.sh < $< > $@
+else
+quiet_cmd_ikconfig_strip = COPY    $@
+	cmd_ikconfig_strip = cp $< $@
+endif
+
+# config_data_in contains the (stripped?) config file
+targets += config_data_in
+$(obj)/config_data_in: .config FORCE
+	$(call if_changed,ikconfig_strip)
+
+
+#define the compression command, none,gzip or bzip2
+ifdef CONFIG_IKCONFIG_COMPRESS_NONE
+quiet_cmd_ikconfig_compress = COPY    $@
+	cmd_ikconfig_compress = cp $< $@
+endif
+
+ifdef CONFIG_IKCONFIG_COMPRESS_GZIP
+quiet_cmd_ikconfig_compress = GZIP    $@
+	cmd_ikconfig_compress = gzip --best < $< > $@
+endif
+
+ifdef CONFIG_IKCONFIG_COMPRESS_BZIP2
+quiet_cmd_ikconfig_compress = BZIP2   $@
+	cmd_ikconfig_compress = bzip2 --best < $< > $@
+endif
+
+
+# config_data_compressed contains the (compressed?) config file
+targets += config_data_compressed
+$(obj)/config_data_compressed: $(obj)/config_data_in FORCE
+	$(call if_changed,ikconfig_compress)
+
+quiet_cmd_ikconfig = IKCFG   $@
+      cmd_ikconfig = (echo "const char kernel_config_data[] = MAGIC_START"; cat $< | scripts/bin2c; echo "MAGIC_END;") > $@
+
+# Info from config_data can be extracted from /proc/config*
 targets += config_data.h
-$(obj)/config_data.h: $(obj)/config_data.gz FORCE
-	$(call if_changed,ikconfiggz)
+$(obj)/config_data.h: $(obj)/config_data_compressed FORCE
+	$(call if_changed,ikconfig)
diff -ruN /usr/src/linux-2.6.8.1/kernel/configs.c ./kernel/configs.c
--- /usr/src/linux-2.6.8.1/kernel/configs.c	2004-08-31 13:11:45.000000000 +0200
+++ ./kernel/configs.c	2004-09-12 19:51:06.000000000 +0200
@@ -55,6 +55,16 @@
 
 #ifdef CONFIG_IKCONFIG_PROC
 
+#ifdef CONFIG_IKCONFIG_COMPRESS_NONE
+#define PROC_CONFIG_FILENAME "config"
+#elif CONFIG_IKCONFIG_COMPRESS_GZIP
+#define PROC_CONFIG_FILENAME "config.gz"
+#elif CONFIG_IKCONFIG_COMPRESS_BZIP2
+#define PROC_CONFIG_FILENAME "config.bz2"
+#else
+#error Proc config filename could not be defined
+#endif
+
 /**************************************************/
 /* globals and useful constants                   */
 
@@ -89,7 +99,7 @@
 	struct proc_dir_entry *entry;
 
 	/* create the current config file */
-	entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO,
+	entry = create_proc_entry(PROC_CONFIG_FILENAME, S_IFREG | S_IRUGO,
 				  &proc_root);
 	if (!entry)
 		return -ENOMEM;
diff -ruN /usr/src/linux-2.6.8.1/scripts/stripCommBlank.sh ./scripts/stripCommBlank.sh
--- /usr/src/linux-2.6.8.1/scripts/stripCommBlank.sh	1970-01-01 01:00:00.000000000 +0100
+++ ./scripts/stripCommBlank.sh	2004-09-12 19:51:06.000000000 +0200
@@ -0,0 +1,2 @@
+#!/bin/sh
+egrep -v '^#|^[:space:]*$'

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-09-15 10:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-14 16:33 /proc/config reducing kernel image size Tom Fredrik Blenning Klaussen
2004-09-14 17:26 ` DervishD
2004-09-14 17:36   ` Tom Fredrik Blenning Klaussen
2004-09-14 18:01     ` DervishD
2004-09-15 10:11       ` Herbert Poetzl
2004-09-14 17:44 ` Norberto Bensa
2004-09-14 17:57   ` Tom Fredrik Blenning Klaussen
2004-09-14 18:11     ` Norberto Bensa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox