wok-current annotate linux/stuff/linux-freeinitrd.u @ rev 13420

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