wok-current rev 881

linux: minimize lzma memory footprint
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 06 23:15:25 2008 +0000 (2008-06-06)
parents 9c22e6598e9f
children 29d6ffb622ab
files linux/receipt linux/stuff/linux-lzma-loram-2.6.24.2.u
line diff
     1.1 --- a/linux/receipt	Sat Jun 07 00:48:02 2008 +0200
     1.2 +++ b/linux/receipt	Fri Jun 06 23:15:25 2008 +0000
     1.3 @@ -16,7 +16,7 @@
     1.4  	# lzma and boot patch from pascal
     1.5  	while read patch_file; do
     1.6  		echo "Apply $patch_file"
     1.7 -		patch -p1 < ../stuff/$patch_file
     1.8 +		patch -p1 < ../stuff/$patch_file || return 1
     1.9  	done <<EOT
    1.10  boot-kernel.u
    1.11  $PACKAGE-lzma-$VERSION.u
    1.12 @@ -26,7 +26,7 @@
    1.13  	cp ../stuff/$PACKAGE-$VERSION-slitaz.config .config
    1.14  	while read patch_file; do
    1.15  		echo "Apply $patch_file"
    1.16 -		patch -p1 < ../stuff/$patch_file
    1.17 +		patch -p1 < ../stuff/$patch_file || return 1
    1.18  	done <<EOT
    1.19  config-acpi-$VERSION.u
    1.20  linux-utf8-$VERSION.u
    1.21 @@ -35,6 +35,7 @@
    1.22  config-tun-$VERSION.u
    1.23  config-reiserfs-$VERSION.u
    1.24  config-wireless-$VERSION.u
    1.25 +$PACKAGE-lzma-loram-$VERSION.u
    1.26  EOT
    1.27  	make oldconfig
    1.28  	make bzImage
    1.29 @@ -48,6 +49,7 @@
    1.30      local path
    1.31      mkdir $fs/boot
    1.32      cp -a $src/arch/x86/boot/bzImage $fs/boot/vmlinuz-$VERSION-slitaz
    1.33 +    rdev $fs/boot/vmlinuz-$VERSION-slitaz /dev/ram0
    1.34      # Compress all modules.
    1.35      # Package module-init-tools is compiled with zlib support.
    1.36      #
    1.37 @@ -75,7 +77,7 @@
    1.38  post_install()
    1.39  {
    1.40      echo "Processing post-install commands..."
    1.41 -    depmod -a -b /$1
    1.42 +    depmod -a -b "$1/"
    1.43      echo "----"
    1.44      echo "If you have GRUB installed, you can add tree lines to boot SliTaz."
    1.45      echo "Example /boot/grub/menu.lst"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/linux/stuff/linux-lzma-loram-2.6.24.2.u	Fri Jun 06 23:15:25 2008 +0000
     2.3 @@ -0,0 +1,227 @@
     2.4 +--- linux-2.6.24.2/init/initramfs.c
     2.5 ++++ linux-2.6.24.2/init/initramfs.c
     2.6 +@@ -468,6 +468,29 @@
     2.7 + }
     2.8 + #endif
     2.9 + 
    2.10 ++#include <linux/initrd.h>
    2.11 ++#ifdef CONFIG_RD_LZMA
    2.12 ++#define INITRD_PAGE ((PAGE_SIZE > 1024*1024) ? PAGE_SIZE : 1024*1024)
    2.13 ++static int fill_offset, fill_total;
    2.14 ++static int fill_buffer(void *buffer, unsigned size)
    2.15 ++{
    2.16 ++	int max =  initrd_end - initrd_start - fill_offset;
    2.17 ++	if (size < max) max = size;
    2.18 ++	memcpy(buffer, (void *)(initrd_start + fill_offset), max);
    2.19 ++	fill_offset += max;
    2.20 ++	fill_total += max;
    2.21 ++	if (fill_offset >= INITRD_PAGE) {
    2.22 ++		unsigned rem = fill_offset % INITRD_PAGE;
    2.23 ++		unsigned end = initrd_start + fill_offset - rem;
    2.24 ++		free_initrd_mem(initrd_start, end);
    2.25 ++		printk(".");
    2.26 ++		initrd_start = end;
    2.27 ++		fill_offset = rem;
    2.28 ++	}
    2.29 ++	return max;
    2.30 ++}
    2.31 ++#endif
    2.32 ++
    2.33 + static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
    2.34 + {
    2.35 + 	int written;
    2.36 +@@ -484,6 +507,9 @@
    2.37 + 	this_header = 0;
    2.38 + 	message = NULL;
    2.39 + 	while (!message && len) {
    2.40 ++#ifdef CONFIG_RD_LZMA
    2.41 ++		int status;
    2.42 ++#endif
    2.43 + 		loff_t saved_offset = this_header;
    2.44 + 		if (*buf == '0' && !(this_header & 3)) {
    2.45 + 			state = Start;
    2.46 +@@ -523,8 +549,20 @@
    2.47 + #ifdef CONFIG_RD_LZMA
    2.48 + 		message = NULL; /* Zero out message, or else cpio will
    2.49 + 				   think an error has already occured */
    2.50 +-		if(!unlzma(buf, len, NULL, flush_buffer, &inptr) < 0 &&
    2.51 +-		   message == NULL) {
    2.52 ++		status = -1;
    2.53 ++		if(buf == (char *) initrd_start) {
    2.54 ++			char *work_buffer = malloc(LZMA_IOBUF_SIZE);
    2.55 ++			if (work_buffer) {
    2.56 ++				fill_total = fill_offset = 0;
    2.57 ++				fill_buffer(work_buffer, LZMA_IOBUF_SIZE);
    2.58 ++				status = unlzma(work_buffer, LZMA_IOBUF_SIZE,
    2.59 ++					fill_buffer, flush_buffer, NULL);
    2.60 ++				inptr = fill_total;
    2.61 ++				free(work_buffer);
    2.62 ++			}
    2.63 ++		}
    2.64 ++		else status = unlzma(buf,len, NULL, flush_buffer, &inptr);
    2.65 ++		if (status == 0 && message == NULL) {
    2.66 + 			goto ok;
    2.67 + 		}
    2.68 + #endif
    2.69 +
    2.70 +--- linux-2.6.24.2/arch/x86/mm/init_32.c
    2.71 ++++ linux-2.6.24.2/arch/x86/mm/init_32.c
    2.72 +@@ -834,7 +834,8 @@
    2.73 + 		free_page(addr);
    2.74 + 		totalram_pages++;
    2.75 + 	}
    2.76 +-	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
    2.77 ++	if (what)
    2.78 ++		printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
    2.79 + }
    2.80 + 
    2.81 + void free_initmem(void)
    2.82 +@@ -847,7 +848,7 @@
    2.83 + #ifdef CONFIG_BLK_DEV_INITRD
    2.84 + void free_initrd_mem(unsigned long start, unsigned long end)
    2.85 + {
    2.86 +-	free_init_pages("initrd memory", start, end);
    2.87 ++	free_init_pages(NULL, start, end);
    2.88 + }
    2.89 + #endif
    2.90 + 
    2.91 +
    2.92 +--- linux-2.6.24.2/lib/decompress_unlzma.c
    2.93 ++++ linux-2.6.24.2/lib/decompress_unlzma.c
    2.94 +@@ -366,7 +366,8 @@
    2.95 + 		header.dict_size = 1;
    2.96 + 
    2.97 + 	bufsize = MIN(header.dst_size, header.dict_size);
    2.98 +-	buffer = large_malloc(bufsize);
    2.99 ++	buffer = (uint8_t *) posp;
   2.100 ++	if (writebb) buffer = large_malloc(bufsize);
   2.101 + 	if(buffer == NULL)
   2.102 + 		return -1;
   2.103 + 
   2.104 +@@ -394,10 +395,12 @@
   2.105 + 				int match_byte;
   2.106 + 
   2.107 + 				pos = buffer_pos - rep0;
   2.108 +-				while (pos >= header.dict_size)
   2.109 +-					pos += header.dict_size;
   2.110 +-				if(pos >= bufsize) {
   2.111 +-					goto fail;
   2.112 ++				if (writebb) {
   2.113 ++					while (pos >= header.dict_size)
   2.114 ++						pos += header.dict_size;
   2.115 ++					if(pos >= bufsize) {
   2.116 ++						goto fail;
   2.117 ++					}
   2.118 + 				}
   2.119 + 				match_byte = buffer[pos];
   2.120 + 				do {
   2.121 +@@ -419,20 +422,14 @@
   2.122 + 				prob_lit = prob + mi;
   2.123 + 				rc_get_bit(&rc, prob_lit, &mi);
   2.124 + 			}
   2.125 ++			previous_byte = (uint8_t) mi;
   2.126 + 			if (state < 4)
   2.127 + 				state = 0;
   2.128 + 			else if (state < 10)
   2.129 + 				state -= 3;
   2.130 + 			else
   2.131 + 				state -= 6;
   2.132 +-			previous_byte = (uint8_t) mi;
   2.133 +-		one_byte:
   2.134 +-			buffer[buffer_pos++] = previous_byte;
   2.135 +-			if (buffer_pos == header.dict_size) {
   2.136 +-				buffer_pos = 0;
   2.137 +-				global_pos += header.dict_size;
   2.138 +-				writebb((char*)buffer, header.dict_size);
   2.139 +-			}
   2.140 ++			goto store_previous_byte;
   2.141 + 		} else {
   2.142 + 			int offset;
   2.143 + 			uint16_t *prob_len;
   2.144 +@@ -457,14 +454,23 @@
   2.145 + 						rc_update_bit_0(&rc, prob);
   2.146 + 
   2.147 + 						state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
   2.148 +-						pos = buffer_pos - rep0;
   2.149 +-						while (pos >= header.dict_size)
   2.150 +-							pos += header.dict_size;
   2.151 +-						if(pos >= bufsize) {
   2.152 +-							goto fail;
   2.153 ++						pos = buffer_pos - rep0;
   2.154 ++						if (writebb) {
   2.155 ++							while (pos >= header.dict_size)
   2.156 ++								pos += header.dict_size;
   2.157 ++							if(pos >= bufsize) {
   2.158 ++								goto fail;
   2.159 ++							}
   2.160 + 						}
   2.161 + 						previous_byte = buffer[pos];
   2.162 +-						goto one_byte;
   2.163 ++					store_previous_byte:
   2.164 ++						buffer[buffer_pos++] = previous_byte;
   2.165 ++						if (writebb && buffer_pos == header.dict_size) {
   2.166 ++							buffer_pos = 0;
   2.167 ++							global_pos += header.dict_size;
   2.168 ++							writebb((char*)buffer, header.dict_size);
   2.169 ++						}
   2.170 ++						continue;
   2.171 + 					} else {
   2.172 + 						rc_update_bit_1(&rc, prob);
   2.173 + 					}
   2.174 +@@ -566,14 +572,16 @@
   2.175 + 
   2.176 + 			do {
   2.177 + 				pos = buffer_pos - rep0;
   2.178 +-				while (pos >= header.dict_size)
   2.179 +-					pos += header.dict_size;
   2.180 +-				if(pos >= bufsize) {
   2.181 +-					goto fail;
   2.182 ++				if (writebb) {
   2.183 ++					while (pos >= header.dict_size)
   2.184 ++						pos += header.dict_size;
   2.185 ++					if(pos >= bufsize) {
   2.186 ++						goto fail;
   2.187 ++					}
   2.188 + 				}
   2.189 + 				previous_byte = buffer[pos];
   2.190 + 				buffer[buffer_pos++] = previous_byte;
   2.191 +-				if (buffer_pos == header.dict_size) {
   2.192 ++				if (writebb && buffer_pos == header.dict_size) {
   2.193 + 					buffer_pos = 0;
   2.194 + 					global_pos += header.dict_size;
   2.195 + 					writebb((char*)buffer, header.dict_size);
   2.196 +@@ -583,15 +591,17 @@
   2.197 + 		}
   2.198 + 	}
   2.199 + 
   2.200 +-	writebb((char*)buffer, buffer_pos);
   2.201 +-	if(posp) {
   2.202 +-		*posp = rc.ptr-rc.buffer;
   2.203 ++	if (writebb) {
   2.204 ++		writebb((char*)buffer, buffer_pos);
   2.205 ++		if(posp) {
   2.206 ++			*posp = rc.ptr-rc.buffer;
   2.207 ++		}
   2.208 ++		large_free(buffer);
   2.209 + 	}
   2.210 +-	large_free(buffer);
   2.211 + 	large_free(p);
   2.212 + 	return 0;
   2.213 +  fail:
   2.214 +-	large_free(buffer);
   2.215 ++	if (writebb) large_free(buffer);
   2.216 + 	large_free(p);
   2.217 + 	return -1;
   2.218 + }
   2.219 +
   2.220 +--- linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
   2.221 ++++ linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
   2.222 +@@ -444,7 +444,7 @@
   2.223 + 
   2.224 + #ifdef CONFIG_KERNEL_LZMA
   2.225 + 	putstr("Unlzmaing Linux... ");
   2.226 +-	unlzma(input_data, input_len-4, NULL, compr_flush, NULL);
   2.227 ++	unlzma(input_data, input_len-4, NULL, NULL, window);
   2.228 + #endif
   2.229 + 
   2.230 + #ifdef CONFIG_KERNEL_GZIP