kvm: align ram_size to page boundary
PATCH 1/1 kvm: align ram_size to page boundary
kvm is not able to execute out of partial pages; align the RAM size so partial pages aren't present.
--- kvm-all.c | 2 ++ 1 file changed, 2 insertions(+)
kvm-all.c +2 -0
@@ -1311,6 +1311,8 @@ int kvm_init(void) cpu_interrupt_handler = kvm_handle_interrupt; + ram_size =TARGET_PAGE_ALIGN (ram_size); +return 0 ; err:
Signature · 1 line
1.7.10.1
Quoted 14 lines · Avi Kivity
kvm is not able to execute out of partial pages; align the RAM size so partial pages aren't present.
Reported-by Michael Tokarev <[email protected]>Signed-off-by Avi Kivity <[email protected]>--- kvm-all.c | 2 ++ 1 file changed, 2 insertions(+)kvm-all.c +0
-0
kvm-all.c int kvm_init(void) · line 1318
Quoted 8 lines
kvm-all.c +2
-0@@ -1311,6 +1311,8 @@ int kvm_init(void) cpu_interrupt_handler = kvm_handle_interrupt; + ram_size =TARGET_PAGE_ALIGN (ram_size); +return 0 ; err:
I think this should rather go into generic code. What sense does it make to have partial pages with TCG?
Jan
Quoted 18 lines · Jan Kiszka
Quoted 17 lines · Avi Kivity
kvm is not able to execute out of partial pages; align the RAM size so partial pages aren't present.
Reported-by Michael Tokarev <[email protected]>Signed-off-by Avi Kivity <[email protected]>--- kvm-all.c | 2 ++ 1 file changed, 2 insertions(+)kvm-all.c +0
-0@@ -1311,6 +1311,8 @@ int kvm_init(void) cpu_interrupt_handler = kvm_handle_interrupt;
Quoted 7 lines
kvm-all.c int kvm_init(void) · line 1318
Quoted 5 lines
kvm-all.c +2
-0+ ram_size =TARGET_PAGE_ALIGN (ram_size); +return 0 ; err:I think this should rather go into generic code.
To be honest, I put this in kvm-specific code because vl.c doesn't have TARGET_PAGE_ALIGN. Maybe we should have machine->page_size or machine->ram_alignment.
Quoted 2 lines
What sense does it make
to have partial pages with TCG?
Why impose an artificial restriction?
(answer: to reduce differences among various accelerators)
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 27 lines · Avi Kivity
Quoted 18 lines · Jan Kiszka
Quoted 17 lines · Avi Kivity
kvm is not able to execute out of partial pages; align the RAM size so partial pages aren't present.
Reported-by Michael Tokarev <[email protected]>Signed-off-by Avi Kivity <[email protected]>--- kvm-all.c | 2 ++ 1 file changed, 2 insertions(+)kvm-all.c +0
-0@@ -1311,6 +1311,8 @@ int kvm_init(void) cpu_interrupt_handler = kvm_handle_interrupt;Quoted 7 lines
kvm-all.c int kvm_init(void) · line 1318
Quoted 5 lines
kvm-all.c +2
-0+ ram_size =TARGET_PAGE_ALIGN (ram_size); +return 0 ; err:I think this should rather go into generic code.
Quoted 8 lines
To be honest, I put this in kvm-specific code because
vl.cdoesn't haveTARGET_PAGE_ALIGN. Maybe we should havemachine->page_sizeormachine->ram_alignment.Quoted 2 lines
What sense does it make
to have partial pages with TCG?Why impose an artificial restriction?
Beca...
Quoted 3 lines
(answer: to reduce differences among various accelerators)
Oh, you found the answer. :)
At least, it should be enforce for the x86 target, independent of the accelerator.
Jan
Quoted 12 lines · Jan Kiszka
Quoted 11 lines
Quoted 2 lines
I think this should rather go into generic code.
To be honest, I put this in kvm-specific code because
vl.cdoesn't haveTARGET_PAGE_ALIGN. Maybe we should havemachine->page_sizeormachine->ram_alignment.Quoted 2 lines
What sense does it make
to have partial pages with TCG?Why impose an artificial restriction?
Quoted 7 lines
Beca...
Quoted 3 lines
(answer: to reduce differences among various accelerators)
Oh, you found the answer. :)
Reducing round-trips across the Internet.
Quoted 3 lines
At least, it should be enforce for the x86 target, independent of the accelerator.
Yeah. So there's machine->page_size or machine->ram_alignment. Not sure which is best.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 21 lines · Avi Kivity
Quoted 12 lines · Jan Kiszka
Quoted 11 lines
Quoted 2 lines
I think this should rather go into generic code.
To be honest, I put this in kvm-specific code because
vl.cdoesn't haveTARGET_PAGE_ALIGN. Maybe we should havemachine->page_sizeormachine->ram_alignment.Quoted 2 lines
What sense does it make
to have partial pages with TCG?Why impose an artificial restriction?
Quoted 7 lines
Beca...
Quoted 3 lines
(answer: to reduce differences among various accelerators)
Oh, you found the answer. :)
Quoted 8 lines
Reducing round-trips across the Internet.
Quoted 3 lines
At least, it should be enforce for the x86 target, independent of the accelerator.
Yeah. So there's
machine->page_sizeormachine->ram_alignment. Not sure which is best.
The boards should make sure that the amount of RAM is feasible with the board memory slots. It's not possible to put 256kb SIMMs to a slot that expects 1GB DIMMs. We can allow some flexibility there though, I'm not sure if the current chipsets would support very much memory if we followed the docs to the letter.
Maybe strtosz() should just enforce 1MB granularity.
What about ballooning (memory hotplug?), can that reduce the memory by smaller amount than page size?
Quoted 6 lines
--
error compilingcommittee.c: too many arguments to function
Quoted 5 lines · Blue Swirl
The boards should make sure that the amount of RAM is feasible with the board memory slots. It's not possible to put 256kb SIMMs to a slot that expects 1GB DIMMs. We can allow some flexibility there though, I'm not sure if the current chipsets would support very much memory if we followed the docs to the letter.
Last time I tried to propose a means for boards to specify their memory restrictions it got shot down for being insufficiently general :-)
Quoted 1 line
Maybe
strtosz()should just enforce 1MB granularity.
That seems even more random a restriction than whole-page requirements.
-- PMM
Quoted 28 lines · Blue Swirl
Quoted 27 lines · Avi Kivity
Quoted 12 lines · Jan Kiszka
Quoted 11 lines
Quoted 2 lines
I think this should rather go into generic code.
To be honest, I put this in kvm-specific code because
vl.cdoesn't haveTARGET_PAGE_ALIGN. Maybe we should havemachine->page_sizeormachine->ram_alignment.Quoted 2 lines
What sense does it make
to have partial pages with TCG?Why impose an artificial restriction?
Quoted 7 lines
Beca...
Quoted 3 lines
(answer: to reduce differences among various accelerators)
Oh, you found the answer. :)
Reducing round-trips across the Internet.
Quoted 3 lines
At least, it should be enforce for the x86 target, independent of the accelerator.
Quoted 8 lines
Quoted 2 lines
Yeah. So there's
machine->page_sizeormachine->ram_alignment. Not sure which is best.The boards should make sure that the amount of RAM is feasible with the board memory slots. It's not possible to put 256kb SIMMs to a slot that expects 1GB DIMMs. We can allow some flexibility there though, I'm not sure if the current chipsets would support very much memory if we followed the docs to the letter.
Right. And generally memory modules are sized a power of two, creating the silly "mega == 1048576" movement.
Quoted 2 lines
Maybe
strtosz()should just enforce 1MB granularity.
strtosz() is much too general. We could do it in vl.c without trouble.
However, it takes away our ability to emulate a "640k should be enough
for everyone" machine.
Quoted 3 lines
What about ballooning (memory hotplug?), can that reduce the memory by smaller amount than page size?
Ballooning removes individual pages, that has no effect on the slot size.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 42 lines · Avi Kivity
Quoted 28 lines · Blue Swirl
Quoted 27 lines · Avi Kivity
Quoted 12 lines · Jan Kiszka
Quoted 11 lines
Quoted 2 lines
I think this should rather go into generic code.
To be honest, I put this in kvm-specific code because
vl.cdoesn't haveTARGET_PAGE_ALIGN. Maybe we should havemachine->page_sizeormachine->ram_alignment.Quoted 2 lines
What sense does it make
to have partial pages with TCG?Why impose an artificial restriction?
Quoted 7 lines
Beca...
Quoted 3 lines
(answer: to reduce differences among various accelerators)
Oh, you found the answer. :)
Reducing round-trips across the Internet.
Quoted 3 lines
At least, it should be enforce for the x86 target, independent of the accelerator.
Quoted 8 lines
Quoted 2 lines
Yeah. So there's
machine->page_sizeormachine->ram_alignment. Not sure which is best.The boards should make sure that the amount of RAM is feasible with the board memory slots. It's not possible to put 256kb SIMMs to a slot that expects 1GB DIMMs. We can allow some flexibility there though, I'm not sure if the current chipsets would support very much memory if we followed the docs to the letter.
Right. And generally memory modules are sized a power of two, creating the silly "mega == 1048576" movement.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Maybe
strtosz()should just enforce 1MB granularity.
strtosz()is much too general. We could do it invl.cwithout trouble. However, it takes away our ability to emulate a "640k should be enough for everyone" machine.
Then how about current max of target page sizes: 8k? No machine should want less than that.
Quoted 11 lines
Quoted 4 lines
What about ballooning (memory hotplug?), can that reduce the memory by smaller amount than page size?
Ballooning removes individual pages, that has no effect on the slot size.
--
error compilingcommittee.c: too many arguments to function
Quoted 6 lines · Blue Swirl
Quoted 3 lines
strtosz()is much too general. We could do it invl.cwithout trouble.
However, it takes away our ability to emulate a "640k should be enough
for everyone" machine.Then how about current max of target page sizes: 8k? No machine should want less than that.
Okay by me, but I can hear the we-should-have-a-generic-mechanism crowd charging their megaphone batteries.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Blue Swirl
Quoted 3 lines
strtosz()is much too general. We could do it invl.cwithout trouble.
However, it takes away our ability to emulate a "640k should be enough
for everyone" machine.Then how about current max of target page sizes: 8k? No machine should want less than that.
Okay by me, but I can hear the we-should-have-a-generic-mechanism crowd charging their megaphone batteries.
So, is there some bottom line in that? I think I'll put a (temp) fix/workaround for the debian package to require memory size to be a multiple of 8K, and to produce a warning if that requiriment hasn't met.
Something like this:
vl.c +9 -1
@@ -2671,7 +2675,15 @@ int main(int argc, char **argv, char **envp)fprintf (stderr,"qemu: ram size too large\n" );exit (1 ); } - ram_size = value; +#define RAM_SIZE_GRANULARITY (8*1024) + ram_size = value /RAM_SIZE_GRANULARITY ; + ram_size *=RAM_SIZE_GRANULARITY ; +if (ram_size != value) { +fprintf (stderr, +"warning: requested memory size (%" PRIu64" bytes) " +"truncated to %" PRIu64" bytes\n" , + value, (uint64_t )ram_size); + }break ; }case QEMU_OPTION_mempath:
With this patch, running
qemu-system-x86_64 -m 1.4g
produces the following:
warning: requested memory size (1503238553 bytes) truncated to 1503232000 bytes
Thanks,
/mjt