Ask a memory-controller engineer what quietly eats bandwidth and you'll often hear "read/write turnarounds." Interviewers like this topic because the fix is a small policy with a big payoff: write draining with watermarks. Here's the problem, the policy, and the follow-up questions you should expect.
Why switching direction is expensive
The DRAM data bus is shared by reads and writes, and it can only go one way at a time. Every time the controller flips direction, it pays dead cycles:
- Write to read is the painful one. After the last write data goes in, the DRAM needs time before it can accept a read (tWTR). In DDR5 that's longer within the same bank group (tWTR_L, around 10 ns) than across bank groups (tWTR_S, a few ns).
- Read to write costs bus turnaround so the controller and the DRAM aren't both driving the bus.
If reads and writes are interleaved one by one, the bus spends a large share of its time turning around instead of moving data.
The policy: buffer writes, drain in bursts
Reads matter more to performance because a CPU core is usually stalled waiting on them. Writes usually aren't urgent: the data has already left the cache. So the controller:
- Serves reads by default and parks incoming writes in a write queue.
- When the write queue fills past a high watermark, it switches to write mode and drains writes back to back.
- It keeps draining until the queue falls below a low watermark, then switches back to reads.
One turnaround pair now covers a whole batch of writes instead of a single one.
A worked example
Say the write queue holds 32 entries, with a high watermark of 28 and a low watermark of 12. When the queue hits 28, the controller drains 16 writes in a row, paying the turnaround penalty twice for 16 writes instead of 32 times.
Choosing the watermarks
This is where the interview gets interesting, because it's a trade-off:
- Watermarks too close together: short drains, frequent switching, and you're back to wasting bandwidth on turnarounds.
- High watermark too high: a burst of incoming writes can fill the queue completely, and the controller has to stall new writes.
- Low watermark too low: long drains block reads for a long time, and read latency spikes.
A good answer says the watermarks should be tuned to the workload: read-heavy traffic wants short, infrequent drains, while streaming writes can tolerate long ones.
Follow-ups you should expect
- "What if a read hits an address that's in the write queue?" The controller must return the newer data from the write queue (read-after-write forwarding), or it would return stale data from DRAM.
- "What else can force a drain?" An idle read queue (drain opportunistically), a refresh coming up, or a write that has waited too long.
- "How does bank-group structure help?" During a drain, the scheduler still prefers row hits and spreads writes across bank groups so the short tCCD_S applies.
How to answer in an interview
Name the cost (tWTR and bus turnaround), propose buffering with high and low watermarks, explain the trade-off in picking them, and mention read-after-write forwarding before you're asked.
Free cheat sheet
Every DDR5-4800 timing parameter, including the write and turnaround timings, on one page: download it free. For 30 interview questions with model answers, see the DRAM & DDR5 Interview Field Guide.
This article was generated with AI from the author's study notes.
Top comments (0)