Skip to contentSkip to conversation

Implement support for mem command line parameter

PATCH In review Bernhard Walle 2 participants 6 messages Jun 2, 2008 – Jun 11, 2008

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

PATCH 1/1 Implement support for mem command line parameter

When the kernel is booted with the "mem" kernel command line (see Documentation/kernel-parameters.txt of kernel source tree), the /proc/iomem is not modified. Instead, it shows the whole memory space as "System RAM". I consider that as correct because the file is named "iomem", and for I/O, the behaviour makes sense.

However, when the kernel is booted with the "mem" parameter, the user expects the crashdump to be as small as the system memory, not containing the whole unused system RAM. To implement this, there are several options:

1. Modify /proc/iomem.
2. Add a new /proc/iomem_used or something like that, i.e. a new kernel interface.
3. Parse /proc/meminfo to read the system RAM.
4. Parse /proc/cmdline to read the command line.

I choosed the 4th possibility because of several reasons.

- The /proc/iomem interface should be stable and not modified. That may break other stuff we don't know. It may also be difficult to convince kernel maintainers.
- We should not add yet another interface between kernel and userspace for a feature 99 % of the people don't need and don't even know about.

The semantics of mem is different on different architectures. i386 and x86_64 (x86) treat the limit specified on the command line as physical address limit while IA64 count the real memory. That is because of different practises of memory mapping on PC architecture vs. "new" architectures.

However, on x86 (which that implementation covers) it's most easy to read the /proc/cmdline and the mem parameter. That parameter should be very stable since bootloaders need to parse it, so no fancy features are likely to be added in future. So we can use that.

The new function limit_system_memory() now reads the memory map kexec built for ELF core headers and limits it to (for mem=X) X bytes physical address space. All other memory map entries are moved so that no ACPI or otherwise reserved ranges behind that limit are lost.

Also, the mem parameter is removed when --reuse-cmdline is used in that case. If no mem parameter is specified, that implementation should do nothing.

---
 kexec/arch/i386/Makefile               |    1 +
 kexec/arch/i386/crashdump-x86-common.c |   77 +++++++++++++++++++++++++++++
 kexec/arch/i386/crashdump-x86.c        |    3 +
 kexec/arch/i386/kexec-bzImage.c        |    2 +-
 kexec/arch/i386/kexec-elf-x86.c        |    2 +-
 kexec/arch/i386/kexec-multiboot-x86.c  |    2 +-
 kexec/arch/i386/kexec-x86.h            |    3 +
 kexec/arch/x86_64/Makefile             |    1 +
 kexec/arch/x86_64/crashdump-x86_64.c   |    3 +
 kexec/arch/x86_64/kexec-elf-x86_64.c   |    2 +-
 kexec/kexec.c                          |   84 +++++++++++++++++++++++++++++--
 kexec/kexec.h                          |    3 +-
 12 files changed, 172 insertions(+), 11 deletions(-)
 create mode 100644 kexec/arch/i386/crashdump-x86-common.c
kexec/arch/i386/Makefile +1 -0
index f2d9636..d166730 100644
@@ -10,6 +10,7 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c
 i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c
 i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c
 i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c
+i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86-common.c
 
 dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS)			\
 	kexec/arch/i386/kexec-x86.h kexec/arch/i386/crashdump-x86.h	\
kexec/arch/i386/crashdump-x86-common.c new file +77 -0

77 lines not on this page · raw message

kexec/arch/i386/crashdump-x86.c +3 -0
index 7717219..cb0d562 100644
@@ -128,6 +128,9 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 		}
 	}
 	fclose(fp);
+
+	limit_system_memory(crash_memory_range, &memory_ranges);
+
 	if (exclude_crash_reserve_region(&memory_ranges) < 0)
 		return -1;
 	*range = crash_memory_range;
kexec/arch/i386/kexec-bzImage.c +1 -1
index 1f40076..9a4b0a4 100644
@@ -378,7 +378,7 @@ int bzImage_load(int argc, char **argv, const char *buf, off_t len,
 			command_line = optarg;
 			break;
 		case OPT_REUSE_CMDLINE:
-			command_line = get_command_line();
+			command_line = get_command_line(1);
 			break;
 		case OPT_RAMDISK:
 			ramdisk = optarg;
kexec/arch/i386/kexec-elf-x86.c +1 -1
index ddd4a10..4961cee 100644
@@ -142,7 +142,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
 			command_line = optarg;
 			break;
 		case OPT_REUSE_CMDLINE:
-			command_line = get_command_line();
+			command_line = get_command_line(1);
 			break;
 		case OPT_RAMDISK:
 			ramdisk = optarg;
kexec/arch/i386/kexec-multiboot-x86.c +1 -1
index 9b41698..ed4d659 100644
@@ -198,7 +198,7 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,
 			command_line = optarg;
 			break;
 		case OPT_REUSE_CMDLINE:
-			command_line = get_command_line();
+			command_line = get_command_line(1);
 			break;
 		case OPT_MOD:
 			modules++;
kexec/arch/i386/kexec-x86.h +3 -0
index 36ed9d5..62e2bc1 100644
@@ -81,4 +81,7 @@ int nbi_probe(const char *buf, off_t len);
 int nbi_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
 void nbi_usage(void);
+
+void limit_system_memory(struct memory_range *mem_ranges, int *num_ranges);
+
 #endif /* KEXEC_X86_H */
kexec/arch/x86_64/Makefile +1 -0
index c59c41f..f2f5541 100644
@@ -7,6 +7,7 @@ x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c
 x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c
 x86_64_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c
 x86_64_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c
+x86_64_KEXEC_SRCS += kexec/arch/i386/crashdump-x86-common.c
 x86_64_KEXEC_SRCS += kexec/arch/x86_64/crashdump-x86_64.c
 x86_64_KEXEC_SRCS += kexec/arch/x86_64/kexec-x86_64.c
 x86_64_KEXEC_SRCS += kexec/arch/x86_64/kexec-elf-x86_64.c
kexec/arch/x86_64/crashdump-x86_64.c +3 -0
index 639ba48..631b9fd 100644
@@ -233,6 +233,9 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges)
 		memory_ranges++;
 	}
 	fclose(fp);
+
+	limit_system_memory(crash_memory_range, &memory_ranges);
+
 	if (exclude_crash_reserve_region(&memory_ranges) < 0)
 		return -1;
 	*range = crash_memory_range;
kexec/arch/x86_64/kexec-elf-x86_64.c +1 -1
index 1bb054a..a90eefa 100644
@@ -142,7 +142,7 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 			command_line = optarg;
 			break;
 		case OPT_REUSE_CMDLINE:
-			command_line = get_command_line();
+			command_line = get_command_line(1);
 			break;
 		case OPT_RAMDISK:
 			ramdisk = optarg;
kexec/kexec.c +78 -6

114 lines not on this page · raw message

kexec/kexec.h +2 -1
index 7db8227..2e225fb 100644
@@ -230,7 +230,8 @@ int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
-char *get_command_line(void);
+char *get_command_line(int filtered);
+unsigned long long get_memory_limit(void);
 
 int kexec_iomem_for_each_line(char *match,
 			      int (*callback)(void *data,
Signature · 7 lines
1.5.4.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 6 lines · Bernhard Walle

When the kernel is booted with the "mem" kernel command line (see Documentation/kernel-parameters.txt of kernel source tree), the /proc/iomem is not modified. Instead, it shows the whole memory space as "System RAM". I consider that as correct because the file is named "iomem", and for I/O, the behaviour makes sense.

IIUC, in the past the behavior of /proc/iomem was different for i386 and x86_64. One arch used to truncate it and other would not. I don't remember which one used to do what.

I had a quick look at the current code and looks like truncation of e820 map is taking place before request_resource(). In that case we should see the truncated map. But I am not sure and will test it tomorrow...

I am not sure which one is the right behavior as one can argue for both. So it essentially boils down to two interfaces. One view corresponds to BIOS view and other view corresponds to kernel view (override BIOS by user options). I think we need to export both to user space.

We need BIOS view so that pure "kexec" can pass it to new kernel, irrespecitve of the view seen by first kernel. For example if system has 4G of memory but user passed mem=2G and first kernel is using only 2G, but if we kexec a new kernel, it should see the full 4G mememory as obtained by BIOS.

We need user view for "kdump" purposes as we don't want to dump memory not used by first kernel. (you have already explained it).

Quoted 10 lines

However, when the kernel is booted with the "mem" parameter, the user expects the crashdump to be as small as the system memory, not containing the whole unused system RAM. To implement this, there are several options:

1. Modify /proc/iomem.
2. Add a new /proc/iomem_used or something like that, i.e. a new kernel interface.
3. Parse /proc/meminfo to read the system RAM.
4. Parse /proc/cmdline to read the command line.

Quoted 5 lines

I choosed the 4th possibility because of several reasons.

- The /proc/iomem interface should be stable and not modified. That may break other stuff we don't know. It may also be difficult to convince kernel maintainers.

We probably will not touch /proc/iomem. We need to create a new interface which will change based on user options. That should not break any user space applications?

Quoted 5 lines

- We should not add yet another interface between kernel and userspace for a feature 99 % of the people don't need and don't even know about.

The semantics of mem is different on different architectures. i386 and x86_64 (x86) treat the limit specified on the command line as physical address limit

You mean system RAM limit? Because PCI devices are still mapped at higher physical addresses. So it is not physical address limit?

Quoted 9 lines

while IA64 count the real memory. That is because of different practises of memory mapping on PC architecture vs. "new" architectures.

However, on x86 (which that implementation covers) it's most easy to read the /proc/cmdline and the mem parameter. That parameter should be very stable since bootloaders need to parse it, so no fancy features are likely to be added in future. So we can use that.

The new function limit_system_memory() now reads the memory map kexec built for

What happens if user booted first kernel with user specified map (using memmap=exactmap)? How will /proc/iomem look like? I think it will show user specified IO regions and ignore BIOS map?

So lets say a system has got 4G of RAM, and for testing purpose a user boots with user speicified map which says 1G of RAM is available. Now we kexec into second kernel. Should second kernel see 4G of RAM or 1G of RAM. I feel, second kernel should see 4G of RAM.

Hence I feel that we need to create two views. /proc/iomem can serve as unmodied io resource view as reported by BIOS, and /proc/iomem_used can serve as modified view as seen by kernel (due to user options.)

I think its the hard way of doing things as it might break something but I feel this will also make semantics very clear than patching things in user space.

Thanks
Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 9 lines · Vivek Goyal
Quoted 6 lines · Bernhard Walle

When the kernel is booted with the "mem" kernel command line (see Documentation/kernel-parameters.txt of kernel source tree), the /proc/iomem is not modified. Instead, it shows the whole memory space as "System RAM". I consider that as correct because the file is named "iomem", and for I/O, the behaviour makes sense.

Quoted 3 lines

IIUC, in the past the behavior of /proc/iomem was different for i386 and x86_64. One arch used to truncate it and other would not. I don't remember which one used to do what.

Right. I just checked with 2.6.22.5 (openSUSE 10.3 kernel), and

- i386: /proc/iomem contains full memory
- x86_64: /proc/iomem contains truncated memory

After the x86 merge, x86_64 now has the behaviour of i386.

Quoted 3 lines

I had a quick look at the current code and looks like truncation of e820 map is taking place before request_resource(). In that case we should see the truncated map. But I am not sure and will test it tomorrow...

2.6.25 shows the full /proc/iomem.

Quoted 3 lines

We probably will not touch /proc/iomem. We need to create a new interface which will change based on user options. That should not break any user space applications?

That would make sense. I will prepare a patch tomorrow, I hope such a interface will be accepted. One might argue that "just don't use mem, it's only for debugging" or something.

Quoted 8 lines
Quoted 5 lines

- We should not add yet another interface between kernel and userspace for a feature 99 % of the people don't need and don't even know about.

The semantics of mem is different on different architectures. i386 and x86_64 (x86) treat the limit specified on the command line as physical address limit

You mean system RAM limit? Because PCI devices are still mapped at higher physical addresses. So it is not physical address limit?

In x86 the mem=3G means that the highest RAM memory address is 3*1024*1024*1024 bytes physical address space. Removing the hole between 640K and 1M and 15M and 16M, that's not exactly 3G memory.

Quoted 2 lines
Quoted 2 lines

while IA64 count the real memory. That is because of different practises of memory mapping on PC architecture vs. "new" architectures.

And IA64 really counts that memory, so 'free -m' will show 3*1024 in that case.

Quoted 3 lines

Hence I feel that we need to create two views. /proc/iomem can serve as unmodied io resource view as reported by BIOS, and /proc/iomem_used can serve as modified view as seen by kernel (due to user options.)

Right, that's the more *clean* solution, but it needs a new kernel interface.

Bernhard

Signature · 6 lines
Bernhard Walle, SUSE LINUX Products GmbH, Architecture Maintenance

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw
Quoted 14 lines · Bernhard Walle
Quoted 9 lines · Vivek Goyal
Quoted 6 lines · Bernhard Walle

When the kernel is booted with the "mem" kernel command line (see Documentation/kernel-parameters.txt of kernel source tree), the /proc/iomem is not modified. Instead, it shows the whole memory space as "System RAM". I consider that as correct because the file is named "iomem", and for I/O, the behaviour makes sense.

Quoted 3 lines

IIUC, in the past the behavior of /proc/iomem was different for i386 and x86_64. One arch used to truncate it and other would not. I don't remember which one used to do what.

Quoted 7 lines

Right. I just checked with 2.6.22.5 (openSUSE 10.3 kernel), and

- i386: /proc/iomem contains full memory
- x86_64: /proc/iomem contains truncated memory

After the x86 merge, x86_64 now has the behaviour of i386.

Cool. Now atleast behavior across x86 and x86_64 is same.

Quoted 33 lines
Quoted 3 lines

I had a quick look at the current code and looks like truncation of e820 map is taking place before request_resource(). In that case we should see the truncated map. But I am not sure and will test it tomorrow...

2.6.25 shows the full /proc/iomem.

Quoted 3 lines

We probably will not touch /proc/iomem. We need to create a new interface which will change based on user options. That should not break any user space applications?

That would make sense. I will prepare a patch tomorrow, I hope such a interface will be accepted. One might argue that "just don't use mem, it's only for debugging" or something.

Quoted 8 lines
Quoted 5 lines

- We should not add yet another interface between kernel and userspace for a feature 99 % of the people don't need and don't even know about.

The semantics of mem is different on different architectures. i386 and x86_64 (x86) treat the limit specified on the command line as physical address limit

You mean system RAM limit? Because PCI devices are still mapped at higher physical addresses. So it is not physical address limit?

In x86 the mem=3G means that the highest RAM memory address is 3*1024*1024*1024 bytes physical address space. Removing the hole between 640K and 1M and 15M and 16M, that's not exactly 3G memory.

Quoted 2 lines
Quoted 2 lines

while IA64 count the real memory. That is because of different practises of memory mapping on PC architecture vs. "new" architectures.

And IA64 really counts that memory, so 'free -m' will show 3*1024 in that case.

Quoted 7 lines
Quoted 3 lines

Hence I feel that we need to create two views. /proc/iomem can serve as unmodied io resource view as reported by BIOS, and /proc/iomem_used can serve as modified view as seen by kernel (due to user options.)

Right, that's the more *clean* solution, but it needs a new kernel interface.

I think this interface might be acceptable to community. Lets write a patch and present our case to community.

Thanks
Vivke

Quoted 5 lines

Bernhard

Signature · 1 line
Bernhard Walle, SUSE LINUX Products GmbH, Architecture Maintenance

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
Quoted 10 lines · Vivek Goyal
Quoted 8 lines

Right. I just checked with 2.6.22.5 (openSUSE 10.3 kernel), and

- i386: /proc/iomem contains full memory
- x86_64: /proc/iomem contains truncated memory

After the x86 merge, x86_64 now has the behaviour of i386.

Cool. Now atleast behavior across x86 and x86_64 is same.

After studying the code, well, that was wrong. I tested again:

- i386: /proc/iomem contains truncated memory
- x86_64: /proc/iomem contains full memroy

And after the merge, it stays the same, i.e. /proc/iomem in i386 is truncated.

Sorry for the confusion. :-|

The question is: Is that "accidentally" or by design. The file Documentation/kernel-parameters.txt:

[X86-32] Use together with memmap= to avoid physical address space collisions. Without memmap= PCI devices could be placed at addresses belonging to unused RAM.

implies that it's "by design".

(And EFI code might be different again. However, I have no non-IA64 EFI machine to test.)

Bernhard

Signature · 6 lines
Bernhard Walle, SUSE LINUX Products GmbH, Architecture Development

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#5 lore raw
Quoted 12 lines · Bernhard Walle
Quoted 10 lines · Vivek Goyal
Quoted 8 lines

Right. I just checked with 2.6.22.5 (openSUSE 10.3 kernel), and

- i386: /proc/iomem contains full memory
- x86_64: /proc/iomem contains truncated memory

After the x86 merge, x86_64 now has the behaviour of i386.

Cool. Now atleast behavior across x86 and x86_64 is same.

Quoted 7 lines

After studying the code, well, that was wrong. I tested again:

- i386: /proc/iomem contains truncated memory
- x86_64: /proc/iomem contains full memroy

And after the merge, it stays the same, i.e. /proc/iomem in i386 is truncated.

:-(

Quoted 12 lines

Sorry for the confusion. :-|

The question is: Is that "accidentally" or by design. The file Documentation/kernel-parameters.txt:

[X86-32] Use together with memmap= to avoid physical address space collisions. Without memmap= PCI devices could be placed at addresses belonging to unused RAM.

implies that it's "by design".

IIUC, does that mean if a system has got 3G of RAM then during normal boot PCI devices will be mapped at physical addresses higher than 3G. But if I boo the system with mem=2G, then there are changes that PCI devices get mapped at physical address between 2G and 3G?

If yes, what's the issue with that? Anyway kernel will never see RAM beyond 2G.

So if we make these two arch consistent, that is /proc/iomem does not see truncated memory even user passes mem= option, hopefully it works for everybody.

Thanks
Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec