SWMR (single write multiple read)
-
- Member
- Posts: 396
- Joined: Wed Nov 18, 2015 3:04 pm
- Location: San Jose San Francisco Bay Area
- Contact:
SWMR (single write multiple read)
the primer on cache coherency book I am going through has one interesting assumption which says in a typical modern systems, "it is not possible to for one core to be writing to the first byte of a block while another core is writing to another byte within that block." and defines it to be SWMR (single write and multiple read) invariant, that made me wonder why? Would not it be possible that two or more cores processing completely unrelated process or threads attempt to write to same block of memory? Or is it prevented by some hardware mechanism if so how and why?
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
Re: SWMR (single write multiple read)
That processor running completely unrelated process or thread would have to wait the other processor finish its write, (or do hyper-threading while waiting).
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: SWMR (single write multiple read)
If two processors write a different value to the same location at the exact same time, what happens then? Would you want two caches with different content? Would the result be a mixture of both values written? Neither is desired, so instead writes take turns.
The next thing is that "locations" are bus-sized cache lines and thus typically worth 16 bytes and up. This is an efficiency trick, but it does mean that writing different bytes in the same cache line still block each other as if it were the same byte.
The last step is that when you want to write somewhere, you must prevent anything else from writing there. So if you write to two locations, you have to make sure both locations are safe from writing by other processes. This introduces the possibility of deadlocks if two processes want to write to A and B, and one claims A while the other claims B and neither can claim the other half. Reads require less blocking so it's only a technical requirement to have single writes per operation.
The next thing is that "locations" are bus-sized cache lines and thus typically worth 16 bytes and up. This is an efficiency trick, but it does mean that writing different bytes in the same cache line still block each other as if it were the same byte.
The last step is that when you want to write somewhere, you must prevent anything else from writing there. So if you write to two locations, you have to make sure both locations are safe from writing by other processes. This introduces the possibility of deadlocks if two processes want to write to A and B, and one claims A while the other claims B and neither can claim the other half. Reads require less blocking so it's only a technical requirement to have single writes per operation.
-
- Member
- Posts: 396
- Joined: Wed Nov 18, 2015 3:04 pm
- Location: San Jose San Francisco Bay Area
- Contact:
Re: SWMR (single write multiple read)
OK got it, then it is a deliberate design, obviously. Thanks!
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails