Skip to contentSkip to conversation

hw/arm/virt: Replace memory_region_init_ram with memory_region_allocate_system_memory

PATCH In review zhuyijun 3 participants 10 messages Oct 14, 2014 – Oct 17, 2014

lore
Share & tools
lore

zhuyijun

author
#0 lore raw

PATCH 1/1 hw/arm/virt: Replace memory_region_init_ram with memory_region_allocate_system_memory

From: Zhu Yijun <[email protected]>

Commit 0b183fc871:"memory: move mem_path handling to memory_region_allocate_system_memory" split memory_region_init_ram and memory_region_init_ram_from_file. Also it moved mem-path handling a step up from memory_region_init_ram to memory_region_allocate_system_memory.

Therefore for any board that uses memory_region_init_ram directly, -mem-path is not supported.

Commit e938ba0c35:"ppc: memory: Replace memory_region_init_ram with memory_region_allocate_system_memory" have already fixed this on ppc.

arm/arm64 board also occurs, this patch is only for arm64 board(virt).

---
 hw/arm/virt.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
hw/arm/virt.c +2 -3
index 8c6b171..32646a1 100644
@@ -580,9 +580,8 @@ static void machvirt_init(MachineState *machine)
     fdt_add_cpu_nodes(vbi);
     fdt_add_psci_node(vbi);
 
-    memory_region_init_ram(ram, NULL, "mach-virt.ram", machine->ram_size,
-                           &error_abort);
-    vmstate_register_ram_global(ram);
+    memory_region_allocate_system_memory(ram, NULL, "mach-virt.ram",
+                                         machine->ram_size);
     memory_region_add_subregion(sysmem, vbi->memmap[VIRT_MEM].base, ram);
 
     create_flash(vbi);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 7 lines · zhuyijun

From: Zhu Yijun <[email protected]>

Commit 0b183fc871:"memory: move mem_path handling to memory_region_allocate_system_memory" split memory_region_init_ram and memory_region_init_ram_from_file. Also it moved mem-path handling a step up from memory_region_init_ram to memory_region_allocate_system_memory.

Quoted 7 lines

Therefore for any board that uses memory_region_init_ram directly, -mem-path is not supported.

Commit e938ba0c35:"ppc: memory: Replace memory_region_init_ram with memory_region_allocate_system_memory" have already fixed this on ppc.

arm/arm64 board also occurs, this patch is only for arm64 board(virt).

Why is this patch only changing this board? What's special about virt that means we don't want to also make this change for the other ARM boards? What about all the other boards for the other architectures?

The commit message for 0b183fc871 suggests we decided to just break -mem-path for all those boards, which seems an odd thing to do... Paolo?

Incidentally I can't see anything that guards against calling memory_region_allocate_system_memory() twice, so I think you would end up with two blocks of RAM both backed by the same file then. Or have I misread the code?

-- PMM

#2 lore raw

Il 14/10/2014 06:54, Peter Maydell ha scritto:

Quoted 4 lines

Why is this patch only changing this board? What's special about virt that means we don't want to also make this change for the other ARM boards? What about all the other boards for the other architectures?

-mem-path is not too useful without KVM (TCG is too slow to notice the difference. PPC and S390 have already been fixed.

For other boards, I have patches but I had no time to submit them until now.

Quoted 3 lines

The commit message for 0b183fc871 suggests we decided to just break -mem-path for all those boards, which seems an odd thing to do... Paolo?

The plan _was_ in fact to fix it up. :(

Quoted 5 lines

Incidentally I can't see anything that guards against calling memory_region_allocate_system_memory() twice, so I think you would end up with two blocks of RAM both backed by the same file then. Or have I misread the code?

That would be a bug in the board, it is caught here:

        if (memory_region_is_mapped(seg)) {
            char *path = object_get_canonical_path_component(OBJECT(backend));
            error_report("memory backend %s is used multiple times. Each "
                         "-numa option must use a different memdev value.",
                         path);
            exit(1);
        }

The error message gives the common user error rather than the less common developer error, but still you catch it.

Paolo

#3 lore raw
Quoted 8 lines · Paolo Bonzini

Il 14/10/2014 06:54, Peter Maydell ha scritto:

Quoted 4 lines

Why is this patch only changing this board? What's special about virt that means we don't want to also make this change for the other ARM boards? What about all the other boards for the other architectures?

-mem-path is not too useful without KVM (TCG is too slow to notice the difference. PPC and S390 have already been fixed.

MIPS has KVM too now...

Quoted 25 lines

For other boards, I have patches but I had no time to submit them until now.

Quoted 3 lines

The commit message for 0b183fc871 suggests we decided to just break -mem-path for all those boards, which seems an odd thing to do... Paolo?

The plan _was_ in fact to fix it up. :(

Quoted 5 lines

Incidentally I can't see anything that guards against calling memory_region_allocate_system_memory() twice, so I think you would end up with two blocks of RAM both backed by the same file then. Or have I misread the code?

That would be a bug in the board, it is caught here:

        if (memory_region_is_mapped(seg)) {
            char *path = object_get_canonical_path_component(OBJECT(backend));
            error_report("memory backend %s is used multiple times. Each "
                         "-numa option must use a different memdev value.",
                         path);
            exit(1);
        }
Quoted 2 lines

The error message gives the common user error rather than the less common developer error, but still you catch it.

That's only in the NUMA code path though, isn't it? I was looking at the non-numa codepath, which is what all the boards I care about are going to be taking :-)

What's the right thing for a board where the system RAM isn't contiguous, by the way?

thanks
-- PMM

#4 lore raw

Il 14/10/2014 07:42, Peter Maydell ha scritto:

Quoted 11 lines · Paolo Bonzini
Quoted 8 lines

Il 14/10/2014 06:54, Peter Maydell ha scritto:

Quoted 4 lines

Why is this patch only changing this board? What's special about virt that means we don't want to also make this change for the other ARM boards? What about all the other boards for the other architectures?

-mem-path is not too useful without KVM (TCG is too slow to notice the difference. PPC and S390 have already been fixed.

MIPS has KVM too now...

Yes.

Quoted 16 lines
Quoted 16 lines
Quoted 5 lines

Incidentally I can't see anything that guards against calling memory_region_allocate_system_memory() twice, so I think you would end up with two blocks of RAM both backed by the same file then. Or have I misread the code?

That would be a bug in the board, it is caught here:

        if (memory_region_is_mapped(seg)) {
            char *path = object_get_canonical_path_component(OBJECT(backend));
            error_report("memory backend %s is used multiple times. Each "
                         "-numa option must use a different memdev value.",
                         path);
            exit(1);
        }
Quoted 6 lines
Quoted 2 lines

The error message gives the common user error rather than the less common developer error, but still you catch it.

That's only in the NUMA code path though, isn't it? I was looking at the non-numa codepath, which is what all the boards I care about are going to be taking :-)

The non-NUMA path will allocate memory from two separate files. -mem-path takes a path, not a file.

Quoted 2 lines

What's the right thing for a board where the system RAM isn't contiguous, by the way?

x86 allocates a big RAM region and uses aliases to split it into non-contiguous areas.

Paolo

#5 lore raw
Quoted 7 lines · Paolo Bonzini

Il 14/10/2014 07:42, Peter Maydell ha scritto:

Quoted 3 lines

That's only in the NUMA code path though, isn't it? I was looking at the non-numa codepath, which is what all the boards I care about are going to be taking :-)

The non-NUMA path will allocate memory from two separate files. -mem-path takes a path, not a file.

Thanks. I hadn't followed the code all the way down...

Quoted 5 lines
Quoted 2 lines

What's the right thing for a board where the system RAM isn't contiguous, by the way?

x86 allocates a big RAM region and uses aliases to split it into non-contiguous areas.

Why don't we just do that automatically for all RAM regions the machine creates? We're already splitting up a contiguous chunk of RAM to parcel out to RAM regions, that's what the indirection through ramaddrs is all about.

-- PMM

#6 lore raw

Il 14/10/2014 14:48, Peter Maydell ha scritto:

Quoted 4 lines

Why don't we just do that automatically for all RAM regions the machine creates? We're already splitting up a contiguous chunk of RAM to parcel out to RAM regions, that's what the indirection through ramaddrs is all about.

I can think of one reason to not do this. If we just mmap-ed RAM regions consecutively from a file, the offset in the file should be aligned to the huge page size for "main" RAM region(s). For example, assume gigabyte-sized huge pages; the offset for main RAM must be gigabyte aligned. If the board creates 16MiB of VRAM first, and 2 GiB of main RAM second, you will end up wasting 1024-16 MiB of RAM for VRAM.
This same waste happened before the introduction of
memory_region_allocate_system_memory, in fact.

Of course this could in principle be fixed by having boards create main RAM first, but it would be an even more complicated change. You could come up with a way of reserving ram_addr_t ranges, which would also help hotplug; however, I am not sure if all architectures require the maximum hotplugged memory size to be specified upfront.

Ultimately, if a RAM region other than main RAM has benefits from huge pages, the device that creates it probably should have a memdev property. This is not the case for any current device, except perhaps ivshmem.

Paolo

author
#7 lore raw
In reply to Peter Maydell

Hi Peter,

Quoted 14 lines · Peter Maydell
Quoted 13 lines · zhuyijun

From: Zhu Yijun <[email protected]>

Commit 0b183fc871:"memory: move mem_path handling to memory_region_allocate_system_memory" split memory_region_init_ram and memory_region_init_ram_from_file. Also it moved mem-path handling a step up from memory_region_init_ram to memory_region_allocate_system_memory.

Therefore for any board that uses memory_region_init_ram directly, -mem-path is not supported.

Commit e938ba0c35:"ppc: memory: Replace memory_region_init_ram with memory_region_allocate_system_memory" have already fixed this on ppc.

Quoted 7 lines
Quoted 1 line

arm/arm64 board also occurs, this patch is only for arm64 board(virt).

Why is this patch only changing this board? What's special about virt that means we don't want to also make this change for the other ARM boards? What about all the other boards for the other architectures?

I think all of the other ARM boards should be changed. If changes in virt is ok, I will make the patch again including the modification of other ARM boards.

Best regards,
Yijun

Quoted 13 lines

The commit message for 0b183fc871 suggests we decided to just break -mem-path for all those boards, which seems an odd thing to do... Paolo?

Incidentally I can't see anything that guards against calling memory_region_allocate_system_memory() twice, so I think you would end up with two blocks of RAM both backed by the same file then. Or have I misread the code?

-- PMM

#8 lore raw

Il 14/10/2014 08:04, Yijun Zhu ha scritto:

Quoted 2 lines

I think all of the other ARM boards should be changed. If changes in virt is ok, I will make the patch again including the modification of other ARM boards.

Don't worry, it's not your fault. :) I introduced the bug, and if you prefer I will rebase and post the patches I had.

Paolo

author
#9 lore raw
Quoted 7 lines · Paolo Bonzini

Il 14/10/2014 08:04, Yijun Zhu ha scritto:

Quoted 2 lines

I think all of the other ARM boards should be changed. If changes in virt is ok, I will make the patch again including the modification of other ARM boards.

Don't worry, it's not your fault. :) I introduced the bug, and if you prefer I will rebase and post the patches I had.

OK, I'll test it at that time. thanks!

Best regards,
Yijun

Quoted 4 lines

Paolo