wok diff linux/stuff/linux-freeinitrd-2.6.34.u @ rev 5684
Up busybox (1.16.1)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jun 04 17:00:07 2010 +0200 (2010-06-04) |
parents | |
children | 0c80e5eb512d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux/stuff/linux-freeinitrd-2.6.34.u Fri Jun 04 17:00:07 2010 +0200 1.3 @@ -0,0 +1,133 @@ 1.4 +--- linux-2.6.30.4/arch/x86/mm/init.c 1.5 ++++ linux-2.6.30.4/arch/x86/mm/init.c 1.6 +@@ -381,7 +381,7 @@ 1.7 + */ 1.8 + set_memory_rw(begin, (end - begin) >> PAGE_SHIFT); 1.9 + 1.10 +- printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); 1.11 ++ if (what) printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); 1.12 + 1.13 + for (; addr < end; addr += PAGE_SIZE) { 1.14 + ClearPageReserved(virt_to_page(addr)); 1.15 + 1.16 +--- linux-2.6.30.4/init/initramfs.c 1.17 ++++ linux-2.6.30.4/init/initramfs.c 1.18 +@@ -374,6 +374,52 @@ 1.19 + [Reset] = do_reset, 1.20 + }; 1.21 + 1.22 ++#include <linux/initrd.h> 1.23 ++#define INITRD_PAGE ((PAGE_SIZE > 64*1024) ? PAGE_SIZE : 64*1024) 1.24 ++#define INITRD_DOT (1024*1024) 1.25 ++ 1.26 ++static void free_rootfs_mem(unsigned long start, unsigned long end) 1.27 ++{ 1.28 ++ free_init_pages(NULL, start, end); 1.29 ++} 1.30 ++ 1.31 ++static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end, 1.32 ++ void (*free_initrd_mem)(unsigned long, unsigned long)); 1.33 ++ 1.34 ++static struct { 1.35 ++ int offset, last, inptr, freed; 1.36 ++ char *max; 1.37 ++} fill; 1.38 ++ 1.39 ++static void release_inbuf(unsigned n) 1.40 ++{ 1.41 ++ if (n >= INITRD_PAGE) { 1.42 ++ unsigned rem = n % INITRD_PAGE; 1.43 ++ unsigned end = initrd_start + n - rem; 1.44 ++ _free_initrd(initrd_start, end, free_rootfs_mem); 1.45 ++ fill.freed += n - rem; 1.46 ++ if (fill.freed >= INITRD_DOT) { 1.47 ++ fill.freed -= INITRD_DOT; 1.48 ++ printk("."); 1.49 ++ } 1.50 ++ initrd_start = end; 1.51 ++ fill.offset = rem; 1.52 ++ } 1.53 ++} 1.54 ++ 1.55 ++static int fill_buffer(void *buffer, unsigned size) 1.56 ++{ 1.57 ++ int max = fill.max - (char *) initrd_start - fill.offset; 1.58 ++ if (max > size) max = size; 1.59 ++ if (max > INITRD_PAGE) max = INITRD_PAGE; 1.60 ++ memcpy(buffer, (void *)(initrd_start + fill.offset), max); 1.61 ++ release_inbuf(fill.offset); 1.62 ++ fill.offset += max; 1.63 ++ fill.inptr += fill.last; 1.64 ++ fill.last = max; 1.65 ++ return max; 1.66 ++} 1.67 ++ 1.68 + static int __init write_buffer(char *buf, unsigned len) 1.69 + { 1.70 + count = len; 1.71 +@@ -418,6 +463,7 @@ 1.72 + decompress_fn decompress; 1.73 + const char *compress_name; 1.74 + static __initdata char msg_buf[64]; 1.75 ++ int early_free_initrd = (buf == (char *) initrd_start); 1.76 + 1.77 + header_buf = kmalloc(110, GFP_KERNEL); 1.78 + symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); 1.79 +@@ -431,11 +478,16 @@ 1.80 + message = NULL; 1.81 + while (!message && len) { 1.82 + loff_t saved_offset = this_header; 1.83 ++ fill.offset = buf - (char *) initrd_start; 1.84 ++ fill.max = buf + len; 1.85 ++ fill.inptr = fill.last = fill.freed = 0; 1.86 + if (*buf == '0' && !(this_header & 3)) { 1.87 + state = Start; 1.88 + written = write_buffer(buf, len); 1.89 + buf += written; 1.90 + len -= written; 1.91 ++ if (early_free_initrd) 1.92 ++ release_inbuf(buf - (char *) initrd_start); 1.93 + continue; 1.94 + } 1.95 + if (!*buf) { 1.96 +@@ -446,9 +497,15 @@ 1.97 + } 1.98 + this_header = 0; 1.99 + decompress = decompress_method(buf, len, &compress_name); 1.100 +- if (decompress) 1.101 +- decompress(buf, len, NULL, flush_buffer, NULL, 1.102 ++ if (decompress) { 1.103 ++ if (early_free_initrd) { 1.104 ++ decompress(NULL, 0, fill_buffer, flush_buffer, 1.105 ++ NULL, &my_inptr, error); 1.106 ++ my_inptr += fill.inptr; 1.107 ++ } 1.108 ++ else decompress(buf, len, NULL, flush_buffer, NULL, 1.109 + &my_inptr, error); 1.110 ++ } 1.111 + else if (compress_name) { 1.112 + if (!message) { 1.113 + snprintf(msg_buf, sizeof msg_buf, 1.114 +@@ -485,7 +543,8 @@ 1.115 + #include <linux/initrd.h> 1.116 + #include <linux/kexec.h> 1.117 + 1.118 +-static void __init free_initrd(void) 1.119 ++static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end, 1.120 ++ void (*free_initrd_mem)(unsigned long, unsigned long)) 1.121 + { 1.122 + #ifdef CONFIG_KEXEC 1.123 + unsigned long crashk_start = (unsigned long)__va(crashk_res.start); 1.124 +@@ -513,6 +571,12 @@ 1.125 + #endif 1.126 + free_initrd_mem(initrd_start, initrd_end); 1.127 + skip: 1.128 ++ ; 1.129 ++} 1.130 ++ 1.131 ++static void __init free_initrd(void) 1.132 ++{ 1.133 ++ _free_initrd(initrd_start, initrd_end, free_initrd_mem); 1.134 + initrd_start = 0; 1.135 + initrd_end = 0; 1.136 + }