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