wok diff linux-libre/stuff/linux-libre-freeinitrd-3.18.129-gnu.u @ rev 25071
waterline-plugin-multiload: added build dependencies
author | Hans-G?nter Theisgen |
---|---|
date | Sat Jun 11 09:07:17 2022 +0100 (2022-06-11) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux-libre/stuff/linux-libre-freeinitrd-3.18.129-gnu.u Sat Jun 11 09:07:17 2022 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +--- linux-libre-3.18.129-gnu/init/initramfs.c 1.5 ++++ linux-libre-3.18.129-gnu/init/initramfs.c 1.6 +@@ -409,6 +409,52 @@ 1.7 + [Reset] = do_reset, 1.8 + }; 1.9 + 1.10 ++#include <linux/initrd.h> 1.11 ++#define INITRD_PAGE ((PAGE_SIZE > 64*1024) ? PAGE_SIZE : 64*1024) 1.12 ++#define INITRD_DOT (1024*1024) 1.13 ++ 1.14 ++static void free_rootfs_mem(unsigned long start, unsigned long end) 1.15 ++{ 1.16 ++ free_init_pages(NULL, start, end); 1.17 ++} 1.18 ++ 1.19 ++static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end, 1.20 ++ void (*free_initrd_mem)(unsigned long, unsigned long)); 1.21 ++ 1.22 ++static struct { 1.23 ++ int offset, last, inptr, freed; 1.24 ++ char *max; 1.25 ++} fill; 1.26 ++ 1.27 ++static void release_inbuf(unsigned n) 1.28 ++{ 1.29 ++ if (n >= INITRD_PAGE) { 1.30 ++ unsigned rem = n % INITRD_PAGE; 1.31 ++ unsigned end = initrd_start + n - rem; 1.32 ++ _free_initrd(initrd_start, end, free_rootfs_mem); 1.33 ++ fill.freed += n - rem; 1.34 ++ if (fill.freed >= INITRD_DOT) { 1.35 ++ fill.freed -= INITRD_DOT; 1.36 ++ printk("."); 1.37 ++ } 1.38 ++ initrd_start = end; 1.39 ++ fill.offset = rem; 1.40 ++ } 1.41 ++} 1.42 ++ 1.43 ++static int fill_buffer(void *buffer, unsigned size) 1.44 ++{ 1.45 ++ int max = fill.max - (char *) initrd_start - fill.offset; 1.46 ++ if (max > size) max = size; 1.47 ++ if (max > INITRD_PAGE) max = INITRD_PAGE; 1.48 ++ memcpy(buffer, (void *)(initrd_start + fill.offset), max); 1.49 ++ release_inbuf(fill.offset); 1.50 ++ fill.offset += max; 1.51 ++ fill.inptr += fill.last; 1.52 ++ fill.last = max; 1.53 ++ return max; 1.54 ++} 1.55 ++ 1.56 + static long __init write_buffer(char *buf, unsigned long len) 1.57 + { 1.58 + byte_count = len; 1.59 +@@ -452,6 +498,7 @@ 1.60 + decompress_fn decompress; 1.61 + const char *compress_name; 1.62 + static __initdata char msg_buf[64]; 1.63 ++ int early_free_initrd = (buf == (char *) initrd_start); 1.64 + 1.65 + header_buf = kmalloc(110, GFP_KERNEL); 1.66 + symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); 1.67 +@@ -465,11 +512,16 @@ 1.68 + message = NULL; 1.69 + while (!message && len) { 1.70 + loff_t saved_offset = this_header; 1.71 ++ fill.offset = buf - (char *) initrd_start; 1.72 ++ fill.max = buf + len; 1.73 ++ fill.inptr = fill.last = fill.freed = 0; 1.74 + if (*buf == '0' && !(this_header & 3)) { 1.75 + state = Start; 1.76 + written = write_buffer(buf, len); 1.77 + buf += written; 1.78 + len -= written; 1.79 ++ if (early_free_initrd) 1.80 ++ release_inbuf(buf - (char *) initrd_start); 1.81 + continue; 1.82 + } 1.83 + if (!*buf) { 1.84 +@@ -482,7 +534,13 @@ 1.85 + decompress = decompress_method(buf, len, &compress_name); 1.86 + pr_debug("Detected %s compressed data\n", compress_name); 1.87 + if (decompress) { 1.88 +- int res = decompress(buf, len, NULL, flush_buffer, NULL, 1.89 ++ int res; 1.90 ++ if (early_free_initrd) { 1.91 ++ res = decompress(NULL, 0, fill_buffer, 1.92 ++ flush_buffer, NULL, &my_inptr, error); 1.93 ++ my_inptr += fill.inptr; 1.94 ++ } 1.95 ++ else res = decompress(buf, len, NULL, flush_buffer, NULL, 1.96 + &my_inptr, error); 1.97 + if (res) 1.98 + error("decompressor failed"); 1.99 +@@ -524,7 +582,8 @@ 1.100 + #include <linux/initrd.h> 1.101 + #include <linux/kexec.h> 1.102 + 1.103 +-static void __init free_initrd(void) 1.104 ++static void _free_initrd(unsigned long initrd_start, unsigned long initrd_end, 1.105 ++ void (*free_initrd_mem)(unsigned long, unsigned long)) 1.106 + { 1.107 + #ifdef CONFIG_KEXEC 1.108 + unsigned long crashk_start = (unsigned long)__va(crashk_res.start); 1.109 +@@ -552,6 +611,12 @@ 1.110 + #endif 1.111 + free_initrd_mem(initrd_start, initrd_end); 1.112 + skip: 1.113 ++ ; 1.114 ++} 1.115 ++ 1.116 ++static void __init free_initrd(void) 1.117 ++{ 1.118 ++ _free_initrd(initrd_start, initrd_end, free_initrd_mem); 1.119 + initrd_start = 0; 1.120 + initrd_end = 0; 1.121 + }