Skip to contentSkip to conversation

kexec: allow to shrink reserved memory

PATCH RESEND In review Amerigo Wang 3 participants 5 messages Nov 23, 2009 – Nov 24, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Cc Neil Horman <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Andi Kleen <[email protected]>

---

include/linux/kexec.h +2 -0
index adc34f2..c356b69 100644
@@ -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
index 528dd78..5b9276b 100644
@@ -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,
 #endif
 	NULL
Acked-by on v1 1/1
#1 lore raw
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_size

Note, you can only do this before loading the crash kernel.

Looks good to me.

Eric

#2 lore raw
In reply to Amerigo Wang

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.o
kernel/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

author
#3 lore raw
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.o
kernel/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!

author
#4 lore raw
In reply to Dan Carpenter
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.o
kernel/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
index 5b9276b..3feaf5a 100644
@@ -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,