3 ms·
Unaligned words within a cacheline is one thing, but what about unaligned words that straddle the end of a cacheline - or worse, the end of a page? In particul
by caf 11y ago
Unaligned words within a cacheline is one thing, but what about unaligned words that straddle the end of a cacheline - or worse, the end of a page?
In particular, consider how these accesses will interact with atomic operations.
- userbinator 11y agoIn particular, consider how these accesses will interact with atomic operations. For x86, Intel has guaranteed that since the P6, any accesses within a cache line are atomic. The LOCK prefix can be used to enforce atomicity even with accesses that cross cachelines. or worse, the end of a page? I suppose you're thinking about page faults? If a #PF occurs, if the handler returns with a valid mapping, the instruction just gets restarted as usual. This reduces to the crossing cacheline case. I'm not saying that alignment is entirely unimportant and can always be ignored, but the number of cases in which it is important, seems to be decreasing with the newer CPUs.
- caf 11y agoI was responding mainly to the assertion about the trivial amount of extra circuitry required. The cacheline-crossing case means that it's a more complicated affair than just shuffling some bytes around as in the within-cacheline case. The "accesses across cachelines require LOCK to be atomic" x86 case is also illustrative - for example should the pthreads implementation include the LOCK prefix just in case you have embedded your pthread_mutex_t in a packed structure where it ends up unaligned?