wok-6.x annotate linux-libre/stuff/linux-libre-freeinitrd-2.6.37-gnu.u @ rev 15872

Up: lz4 (112) add lz4c, lib and dev packages
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 02 21:26:43 2014 +0100 (2014-02-02)
parents
children
rev   line source
pascal@14201 1 --- linux-2.6.30.4/arch/x86/mm/init.c
pascal@14201 2 +++ linux-2.6.30.4/arch/x86/mm/init.c
pascal@14201 3 @@ -366,7 +366,7 @@
pascal@14201 4 */
pascal@14201 5 set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
pascal@14201 6
pascal@14201 7 - printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
pascal@14201 8 + if (what) printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
pascal@14201 9
pascal@14201 10 for (; addr < end; addr += PAGE_SIZE) {
pascal@14201 11 ClearPageReserved(virt_to_page(addr));
pascal@14201 12
pascal@14201 13 --- linux-2.6.30.4/init/initramfs.c
pascal@14201 14 +++ linux-2.6.30.4/init/initramfs.c
pascal@14201 15 @@ -374,6 +374,52 @@
pascal@14201 16 [Reset] = do_reset,
pascal@14201 17 };
pascal@14201 18
pascal@14201 19 +#include <linux/initrd.h>
pascal@14201 20 +#define INITRD_PAGE ((PAGE_SIZE > 64*1024) ? PAGE_SIZE : 64*1024)
pascal@14201 21 +#define INITRD_DOT (1024*1024)
pascal@14201 22 +
pascal@14201 23 +static void free_rootfs_mem(unsigned long start, unsigned long end)
pascal@14201 24 +{
pascal@14201 25 + free_init_pages(NULL, start, end);
pascal@14201 26 +}
pascal@14201 27 +
pascal@14201 28 +static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end,
pascal@14201 29 + void (*free_initrd_mem)(unsigned long, unsigned long));
pascal@14201 30 +
pascal@14201 31 +static struct {
pascal@14201 32 + int offset, last, inptr, freed;
pascal@14201 33 + char *max;
pascal@14201 34 +} fill;
pascal@14201 35 +
pascal@14201 36 +static void release_inbuf(unsigned n)
pascal@14201 37 +{
pascal@14201 38 + if (n >= INITRD_PAGE) {
pascal@14201 39 + unsigned rem = n % INITRD_PAGE;
pascal@14201 40 + unsigned end = initrd_start + n - rem;
pascal@14201 41 + _free_initrd(initrd_start, end, free_rootfs_mem);
pascal@14201 42 + fill.freed += n - rem;
pascal@14201 43 + if (fill.freed >= INITRD_DOT) {
pascal@14201 44 + fill.freed -= INITRD_DOT;
pascal@14201 45 + printk(".");
pascal@14201 46 + }
pascal@14201 47 + initrd_start = end;
pascal@14201 48 + fill.offset = rem;
pascal@14201 49 + }
pascal@14201 50 +}
pascal@14201 51 +
pascal@14201 52 +static int fill_buffer(void *buffer, unsigned size)
pascal@14201 53 +{
pascal@14201 54 + int max = fill.max - (char *) initrd_start - fill.offset;
pascal@14201 55 + if (max > size) max = size;
pascal@14201 56 + if (max > INITRD_PAGE) max = INITRD_PAGE;
pascal@14201 57 + memcpy(buffer, (void *)(initrd_start + fill.offset), max);
pascal@14201 58 + release_inbuf(fill.offset);
pascal@14201 59 + fill.offset += max;
pascal@14201 60 + fill.inptr += fill.last;
pascal@14201 61 + fill.last = max;
pascal@14201 62 + return max;
pascal@14201 63 +}
pascal@14201 64 +
pascal@14201 65 static int __init write_buffer(char *buf, unsigned len)
pascal@14201 66 {
pascal@14201 67 count = len;
pascal@14201 68 @@ -418,6 +463,7 @@
pascal@14201 69 decompress_fn decompress;
pascal@14201 70 const char *compress_name;
pascal@14201 71 static __initdata char msg_buf[64];
pascal@14201 72 + int early_free_initrd = (buf == (char *) initrd_start);
pascal@14201 73
pascal@14201 74 header_buf = kmalloc(110, GFP_KERNEL);
pascal@14201 75 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
pascal@14201 76 @@ -431,11 +478,16 @@
pascal@14201 77 message = NULL;
pascal@14201 78 while (!message && len) {
pascal@14201 79 loff_t saved_offset = this_header;
pascal@14201 80 + fill.offset = buf - (char *) initrd_start;
pascal@14201 81 + fill.max = buf + len;
pascal@14201 82 + fill.inptr = fill.last = fill.freed = 0;
pascal@14201 83 if (*buf == '0' && !(this_header & 3)) {
pascal@14201 84 state = Start;
pascal@14201 85 written = write_buffer(buf, len);
pascal@14201 86 buf += written;
pascal@14201 87 len -= written;
pascal@14201 88 + if (early_free_initrd)
pascal@14201 89 + release_inbuf(buf - (char *) initrd_start);
pascal@14201 90 continue;
pascal@14201 91 }
pascal@14201 92 if (!*buf) {
pascal@14201 93 @@ -447,7 +497,12 @@
pascal@14201 94 this_header = 0;
pascal@14201 95 decompress = decompress_method(buf, len, &compress_name);
pascal@14201 96 if (decompress) {
pascal@14201 97 - res = decompress(buf, len, NULL, flush_buffer, NULL,
pascal@14201 98 + if (early_free_initrd) {
pascal@14201 99 + res = decompress(NULL, 0, fill_buffer,
pascal@14201 100 + flush_buffer, NULL, &my_inptr, error);
pascal@14201 101 + my_inptr += fill.inptr;
pascal@14201 102 + }
pascal@14201 103 + else res = decompress(buf, len, NULL, flush_buffer, NULL,
pascal@14201 104 &my_inptr, error);
pascal@14201 105 if (res)
pascal@14201 106 error("decompressor failed");
pascal@14201 107 @@ -488,7 +546,8 @@
pascal@14201 108 #include <linux/initrd.h>
pascal@14201 109 #include <linux/kexec.h>
pascal@14201 110
pascal@14201 111 -static void __init free_initrd(void)
pascal@14201 112 +static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end,
pascal@14201 113 + void (*free_initrd_mem)(unsigned long, unsigned long))
pascal@14201 114 {
pascal@14201 115 #ifdef CONFIG_KEXEC
pascal@14201 116 unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
pascal@14201 117 @@ -516,6 +574,12 @@
pascal@14201 118 #endif
pascal@14201 119 free_initrd_mem(initrd_start, initrd_end);
pascal@14201 120 skip:
pascal@14201 121 + ;
pascal@14201 122 +}
pascal@14201 123 +
pascal@14201 124 +static void __init free_initrd(void)
pascal@14201 125 +{
pascal@14201 126 + _free_initrd(initrd_start, initrd_end, free_initrd_mem);
pascal@14201 127 initrd_start = 0;
pascal@14201 128 initrd_end = 0;
pascal@14201 129 }