Hi all,
I just read a nice article on false sharing by Nitsan Wakart:
http://psy-lob-saw.blogspot.ro/2014/06/notes-on-false-sharing.html?m=1
I asked if maybe those fields added for padding should be volatiles, because from what I understand, fields can be reordered by the JVM. Nitsan replied that the only field reordering fence is inheritance.
Martin Thomson in one of his articles does use volatile for padding. And I couldn’t find a reliable reference to how field reordering works other than looking at samples in blog posts.
The usage of inheritance has left me scratching my head for a bit. Lets take this example:
private volatile long p1, p2, p3, p4, p5, p6 = 7L
long myPaddedVar;
Questions:
private do? This of course can be problematic as unused private fields could get eliminated, but I was under the impression that volatile private fields don’t get eliminated. Thanks,
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I see Martin has given you some insight already, but just to answer a few of your other questions:
3) private fields are not eliminated/removed, so padding can stay private.
4) some processors use 2 (adjacent) cache lines as the coherence unit so writing to one line will invalidate the other as well. So if you wanted to cater to all sorts of architectures and play it safe in general, 128 byte padding would be it; for practical purposes and not to waste memory, 64 bytes should be sufficient.
Sent from my phone
--
It would be cool if @Contented also happened as a compiler plugin for older/current Java versions, otherwise it will be a long way before we'll start using it.
4) some processors use 2 (adjacent) cache lines as the coherence unit so writing to one line will invalidate the other as well. So if you wanted to cater to all sorts of architectures and play it safe in general, 128 byte padding would be it; for practical purposes and not to waste memory, 64 bytes should be sufficient.
There's also the case where the line *is* 64 bytes but adjacent line prefetching is used, which will induce false sharing effects on writes within 128 byte region.
Sent from my phone
--
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.