kexec: allow to shrink reserved memory
Subsystems (2)
PATCH RESEND 1/1 kexec: allow to shrink reserved memory
This patch implements shrinking the reserved memory for crash kernel, if it is more than enough.
For example, if you have already reserved 128M, now you just want 100M, you can do:
# echo $((100*1024*1024)) > /sys/kernel/kexec_crash_size
Note, you can only do this before loading the crash kernel.
---
include/linux/kexec.h +2 -0
@@ -206,6 +206,8 @@ extern size_t vmcoreinfo_max_size;int __init parse_crashkernel (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); +int crash_shrink_memory (unsigned long new_size); +size_t crash_get_memory_size (void );#else /* !CONFIG_KEXEC */ struct pt_regs ;
kernel/kexec.c +59 -0
71 lines not on this page · raw message
kernel/ksysfs.c +21 -0
@@ -100,6 +100,26 @@ static ssize_t kexec_crash_loaded_show(struct kobject *kobj, }KERNEL_ATTR_RO (kexec_crash_loaded); +static ssize_t kexec_crash_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"%lu\n" ,crash_get_memory_size ()); +} +static ssize_t kexec_crash_size_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +unsigned long cnt; +int ret; + +if (strict_strtoul (buf,0 , &cnt)) +return -EINVAL ; + + ret =crash_shrink_memory (cnt); +return ret <0 ? ret : count; +} +KERNEL_ATTR_RW (kexec_crash_size); +static ssize_t vmcoreinfo_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {
@@ -147,6 +167,7 @@ static struct attribute * kernel_attrs[] = {#ifdef CONFIG_KEXEC &kexec_loaded_attr.attr, &kexec_crash_loaded_attr.attr, + &kexec_crash_size_attr.attr, &vmcoreinfo_attr.attr, #endifNULL
Quoted 9 lines · Amerigo Wang
This patch implements shrinking the reserved memory for crash kernel, if it is more than enough.
For example, if you have already reserved 128M, now you just want 100M, you can do:
# echo $((100*1024*1024)) > /sys/kernel/kexec_crash_sizeNote, you can only do this before loading the crash kernel.
Looks good to me.
Eric
On Mon, Nov 23, 2009 at 04:37:02AM -0500, Amerigo Wang wrote:
[snip]
Quoted 1 line
+size_t
crash_get_memory_size(void);
[snip]
kernel/ksysfs.c static ssize_t kexec_crash_loaded_show(struct kobject *kobj, · line 107
Quoted 5 lines
kernel/ksysfs.c +5
-0+static ssize_t kexec_crash_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"%lu\n" ,crash_get_memory_size ()); +}
CC kernel/ksysfs.okernel/ksysfs.c: In function ‘kexec_crash_size_show’:kernel/ksysfs.c:106: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
Could we get suppress this gcc warning?
regards,
dan carpenter
Quoted 14 lines · Dan Carpenter
On Mon, Nov 23, 2009 at 04:37:02AM -0500, Amerigo Wang wrote:
[snip]Quoted 1 line
+size_t
crash_get_memory_size(void);[snip]
kernel/ksysfs.c static ssize_t kexec_crash_loaded_show(struct kobject *kobj, · line 107
Quoted 5 lines
kernel/ksysfs.c +5
-0+static ssize_t kexec_crash_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"%lu\n" ,crash_get_memory_size ()); +}CC
kernel/ksysfs.okernel/ksysfs.c: In function ‘kexec_crash_size_show’:kernel/ksysfs.c:106: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
Quoted 1 line
Could we get suppress this gcc warning?
Oops! Try to replace '%lu' with '%zu'...
I didn't see this warning, will cook a delta patch.
Thanks!
Quoted 4 lines · Dan Carpenter
On Mon, Nov 23, 2009 at 04:37:02AM -0500, Amerigo Wang wrote:
[snip]Quoted 1 line
+size_t
crash_get_memory_size(void);[snip]
Quoted 10 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static ssize_t kexec_crash_size_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "%lu\n", crash_get_memory_size()); +}CC
kernel/ksysfs.okernel/ksysfs.c: In function ‘kexec_crash_size_show’:kernel/ksysfs.c:106: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘size_t’
Patch below fixes this.
Andrew, could you please fold it in? Thanks!
kernel/ksysfs.c +1 -1
@@ -103,7 +103,7 @@ KERNEL_ATTR_RO(kexec_crash_loaded);static ssize_t kexec_crash_size_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) { -return sprintf (buf,"%lu\n" ,crash_get_memory_size ()); +return sprintf (buf,"%zu\n" ,crash_get_memory_size ()); } static ssize_t kexec_crash_size_store(struct kobject *kobj, struct kobj_attribute *attr,