Skip to contentSkip to conversation

2 MiB alignment in qemu_vmalloc()

Qemu-devel Stefan Weil 5 participants 9 messages Oct 12, 2011 – Oct 16, 2011

lore
Share & tools
lore
#0 lore raw

Hello Avi,

commit 36b58628 increased the alignment for some large memory blocks (typically the system RAM) to 2 MiB (QEMU_VMALLOC_ALIGN) on x86_64 Linux hosts.

As far as I know, this was only required for KVM.

There is a bad side effect of this increase: the Valgrind tool only supports an alignment of up to 1 MiB. It aborts execution with current QEMU for any target (even non-KVM targets).

It might be possible to modify Valgrind (as far as I know this is already discussed), and of course I can also patch my local QEMU. Nevertheless, I think the alignment should be reduced again when there is no KVM support or KVM is disabled. Maybe the large alignment has other unwanted side effects.

The code is in oslib-posix.c (target independent) and needs something like kvm_enabled() (currently a macro). What would you suggest? Maybe you can provide a patch.

Kind regards,
Stefan

#1 lore raw
Quoted 12 lines · Stefan Weil

Hello Avi,

commit 36b58628 increased the alignment for some large memory blocks (typically the system RAM) to 2 MiB (QEMU_VMALLOC_ALIGN) on x86_64 Linux hosts.

As far as I know, this was only required for KVM.

There is a bad side effect of this increase: the Valgrind tool only supports an alignment of up to 1 MiB. It aborts execution with current QEMU for any target (even non-KVM targets).

Quoted 5 lines

It might be possible to modify Valgrind (as far as I know this is already discussed), and of course I can also patch my local QEMU. Nevertheless, I think the alignment should be reduced again when there is no KVM support or KVM is disabled. Maybe the large alignment has other unwanted side effects.

Actually, I'd much rather prefer to keep the differences between KVM and non-KVM low here. THP can potentially also work on TCG, so the alignment isn't completely moot here. Though it's certainly a lot less useful, as code isn't directly executed from there and we the rest of the overhead is a lot higher either way (especially the softmmu one).

Either way, why does valgrind break when we enforce big alignment? That really sounds more like a valgrind bug than anything else. Memalign is there for exactly that reason, no?

Alex

#2 lore raw

Am 12.10.2011 22:02, schrieb Alexander Graf:

Quoted 5 lines

Actually, I'd much rather prefer to keep the differences between KVM and non-KVM low here. THP can potentially also work on TCG, so the alignment isn't completely moot here. Though it's certainly a lot less useful, as code isn't directly executed from there and we the rest of the overhead is a lot higher either way (especially the softmmu one). Either way, why does valgrind break when we enforce big alignment? That really sounds more like a valgrind bug than anything else. Memalign is there for exactly that reason, no?

Alex

Actually, there is even a difference between KVM (x86_64) and KVM (non x86_64) in the current code: only x86_64 hosts use the 2 MiB alignment.

Valgrind breaks because it has an assertion which limits the alignment. This limitation was already discussed in 2008 and still exists in latest Ubuntu and other distributions (and also in latest Valgrind SVN trunk).

Therefore I don't expect that it will be fixed soon.

See these bug reports, for example:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=489297
http://bugs.kde.org/show_bug.cgi?id=203877

Cheers,
Stefan

#3 lore raw
Quoted 9 lines · Stefan Weil

Am 12.10.2011 22:02, schrieb Alexander Graf:

Quoted 5 lines

Actually, I'd much rather prefer to keep the differences between KVM and non-KVM low here. THP can potentially also work on TCG, so the alignment isn't completely moot here. Though it's certainly a lot less useful, as code isn't directly executed from there and we the rest of the overhead is a lot higher either way (especially the softmmu one). Either way, why does valgrind break when we enforce big alignment? That really sounds more like a valgrind bug than anything else. Memalign is there for exactly that reason, no?

Alex

Actually, there is even a difference between KVM (x86_64) and KVM (non x86_64) in the current code: only x86_64 hosts use the 2 MiB alignment.

Right. It might make sense to find a reasonable alignment for all archs and just set it to that. I vote for 16MB :).

Quoted 10 lines

Valgrind breaks because it has an assertion which limits the alignment. This limitation was already discussed in 2008 and still exists in latest Ubuntu and other distributions (and also in latest Valgrind SVN trunk).

Therefore I don't expect that it will be fixed soon.

See these bug reports, for example:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=489297
http://bugs.kde.org/show_bug.cgi?id=203877

Well, yes, my point is that it's a bug in valgrind that should be fixed. I don't think we should special-case QEMU because of bugs in debugging software :)

Alex

#4 lore raw

Am 12.10.2011 22:47, schrieb Alexander Graf:

Quoted 3 lines

Well, yes, my point is that it's a bug in valgrind that should be fixed. I don't think we should special-case QEMU because of bugs in debugging software :)

Alex

Yes, the valgrind bug should be fixed. I don't know why it isn't, but that's not the point:

Valgrind is very valuable for finding certain kinds of bugs in QEMU which we want to find and fix (I hope we agree on this). Therefore developers should be able to use it.

Today, they cannot use Valgrind with QEMU out-of-the box, because they get an assertion. Some developers will stop here. Others will ask Google, look in Valgrind's code and spend some time to find and fix the problem before they start using Valgrind to find QEMU bugs.

They could have spent their time better.

I can try to make QEMU more useable with Valgrind by changing the QEMU code (which was Valgrind compatible up to Avi's change).

I cannot change the Valgrind code, and even if I could, it would take a lot of time until all Linux distributions would include a fixed Valgrind :-(

If all existing gdb versions did not work with QEMU, but there were a simple QEMU change which made them work, what would you do?

Cheers,
Stefan

#5 lore raw
Quoted 23 lines · Stefan Weil

Am 12.10.2011 22:47, schrieb Alexander Graf:

Quoted 3 lines

Well, yes, my point is that it's a bug in valgrind that should be fixed. I don't think we should special-case QEMU because of bugs in debugging software :)

Alex

Yes, the valgrind bug should be fixed. I don't know why it isn't, but that's not the point:

Valgrind is very valuable for finding certain kinds of bugs in QEMU which we want to find and fix (I hope we agree on this). Therefore developers should be able to use it.

Today, they cannot use Valgrind with QEMU out-of-the box, because they get an assertion. Some developers will stop here. Others will ask Google, look in Valgrind's code and spend some time to find and fix the problem before they start using Valgrind to find QEMU bugs.

They could have spent their time better.

I can try to make QEMU more useable with Valgrind by changing the QEMU code (which was Valgrind compatible up to Avi's change).

Quoted 7 lines

I cannot change the Valgrind code, and even if I could, it would take a lot of time until all Linux distributions would include a fixed Valgrind :-(

If all existing gdb versions did not work with QEMU, but there were a simple QEMU change which made them work, what would you do?

I would add a command line option to modify the alignment in runtime, defaulting it to something sane (16MB), so you can work around bugs in vagrind with a simple parameter :)

Alex

#6 lore raw
In reply to Stefan Weil

Hi,

Quoted 2 lines

I can try to make QEMU more useable with Valgrind by changing the QEMU code (which was Valgrind compatible up to Avi's change).

Is there some way for apps to figure they are running in valgrind? Then we could choose a different alignment automagically.

Who aborts btw? Is this valgrind itself? Or qemu due to memalign failing? In case of the latter we could simply catch it and try again with another alignment ...

cheers,
Gerd

#7 lore raw
Quoted 3 lines · Gerd Hoffmann

Is there some way for apps to figure they are running in valgrind? Then we could choose a different alignment automagically.

Yes, valgrind.h (on RH distros that's in package valgrind-devel; there is a valgrind.pc file to add the correct include path) provides a RUNNING_ON_VALGRIND macro.

Paolo

#8 lore raw
In reply to Alexander Graf
Quoted 14 lines · Alexander Graf
Quoted 12 lines · Stefan Weil

Hello Avi,

commit 36b58628 increased the alignment for some large memory blocks (typically the system RAM) to 2 MiB (QEMU_VMALLOC_ALIGN) on x86_64 Linux hosts.

As far as I know, this was only required for KVM.

There is a bad side effect of this increase: the Valgrind tool only supports an alignment of up to 1 MiB. It aborts execution with current QEMU for any target (even non-KVM targets).

Quoted 7 lines
Quoted 5 lines

It might be possible to modify Valgrind (as far as I know this is already discussed), and of course I can also patch my local QEMU. Nevertheless, I think the alignment should be reduced again when there is no KVM support or KVM is disabled. Maybe the large alignment has other unwanted side effects.

Actually, I'd much rather prefer to keep the differences between KVM and non-KVM low here. THP can potentially also work on TCG, so the alignment isn't completely moot here. Though it's certainly a lot less useful, as code isn't directly executed from there and we the rest of the overhead is a lot higher either way (especially the softmmu one).

Note thp will still work with tcg, even without alignment. The alignment requirement is specific to kvm.

Quoted 2 lines

Either way, why does valgrind break when we enforce big alignment? That really sounds more like a valgrind bug than anything else. Memalign is there for exactly that reason, no?

Agreed, seems like a valgrind limitation that needs to be lifted if possible.

Signature · 1 line
error compiling committee.c: too many arguments to function