wok annotate linux-libre/stuff/linux-libre-freeinitrd-2.6.37-libre.u @ rev 12504

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