Write-allocate (also called fetch-on-write) is a cache policy that says: on a write miss, fetch the block from memory into the cache, THEN perform the write.
Because caches operate on block granularity, not individual bytes. The cache line size is typically 64 bytes. Even if you're writing just 1 byte, the cache needs the full block to maintain coherence and support future reads to neighboring addresses.
No-allocate (also called write-around or write-no-allocate) is a cache policy that says: on a write miss, write directly to the next level of memory WITHOUT bringing the block into cache.
Let's think through what happens with write-back + no-allocate:
Write miss occurs to address A
No-allocate policy: Don't bring A into cache
Write-back policy: Only write to memory when evicting dirty line
Problem: How do we handle the write to A? We can't store it in cache (no-allocate), and we can't defer it (write-back means write later). We're forced to write immediately memory, which is actually write-through behavior!
Therefore, write-back requires write-allocate to be consistent.
Streaming Stores: ISA instructions that force no-allocate behavior
Cache Pollution: Problem that no-allocate helps avoid
Write Combining Buffers: Optimization that batches writes before memory access
Dirty Bit: Tracking mechanism required for write-back + write-allocate
#flashcards/hardware
What happens on a write miss with write-allocate policy?
Fetch the entire block from memory into cache, then perform the write in the cached block. Mark the line as valid (and dirty if write-back).
What happens on a write miss with no-allocate policy?
Write the data directly to the next level of memory without allocating a cache line or fetching the block.
Why does write-back require write-allocate?
Write-back defers writes until eviction, which requires the data to be in cache. If we don't allocate on write miss, we have nowhere to defer the write to, forcing immediate memory write (which contradicts write-back).
What is the standard pairing for write-through caches?
Write-through can pair with EITHER write-allocate or no-allocate, depending on expected temporal locality of writes.
When is no-allocate better than write-allocate?
When writes have low temporal locality (streaming writes, one-time initialization, I/O operations). Avoids cache pollution and fetch bandwidth waste.
What is the main disadvantage of write-allocate on write miss?
Higher latency due to fetching the block from memory before writing, and increased memory read traffic.
What is cache pollution in the context of write policies?
When write-allocate brings blocks into cache that won't be reused, evicting potentially useful data and wasting cache space.
What is a non-temporal store instruction?
An ISA instruction (like x86 movnti) that writes to memory with no-allocate behavior, bypassing the cache to avoid pollution.
Why does write-allocate fetch the entire block even for a single-byte write?
Caches operate at block granularity. Other bytes in the block might be accessed later, so the cache needs the full block to maintain coherence and support spatial locality.
What optimization can skip the fetch in write-allocate, and what should it NOT be confused with?
Full-line-write optimization (write-validate): if a write covers the entire cache line, skip the fetch and directly overwrite. Do NOT confuse it with write-combining, which merges adjacent writes into bursts before issuing to memory (a write-buffering technique, not a fill policy).
Dekho, is topic ka core sawaal bahut simple hai: jab hum kisi memory location pe likhna (write) chahte hain aur wo location cache mein present nahi hai (yani write miss ho gaya), tab hum kya karein? Do choices hain. Write-allocate kehta hai ki pehle us block ko memory se cache mein le aao, phir likho — jaise grocery shopping mein milk cart mein daal ke rakhte ho future ke liye. No-allocate kehta hai ki bas seedha memory mein likh do, cache ko bother mat karo — jaise saman seedha car ki dikki mein daal diya. Ye poora decision ek cheez pe depend karta hai: temporal locality, yani kya ye data thodi der baad phir se chahiye hoga ya nahi?
Ab yaad rakho ek important cheez — cache hamesha poore block (typically 64 bytes) pe kaam karta hai, na ki single byte pe. Toh agar tum sirf 1 byte likhna chahte ho aur write-allocate use kar rahe ho, tab bhi cache ko pura block memory se fetch karna padega. Isliye write-allocate mein ek extra memory read ka cost aata hai, aur latency zyada hoti hai. Lekin agar wahi data ya uske neighbouring addresses jaldi phir se access hone waale hain, toh ye extra cost worth it hai kyunki aage ke accesses cache hit ban jaate hain. No-allocate ka fayda ye hai ki wo cache ko un data se pollute nahi karta jo dobara use nahi hone waala, aur cache space bachta hai.
Sabse important baat jo exam aur real hardware dono mein aati hai: write-back policy hamesha write-allocate ke saath hi pair hoti hai. Iska logic samajh lo — write-back ka matlab hai ki hum data ko turant memory mein nahi likhte, cache mein rakh ke dirty bit track karte hain aur baad mein evict hone pe likhte hain. Ab agar tum no-allocate use karoge, toh write miss pe data cache mein aayega hi nahi, matlab tumhe turant memory mein likhna padega — jo actually write-through ban gaya, aur write-back ka pura point khatam! Isliye write-back ko kaam karne ke liye write-allocate chahiye hi chahiye. Dusri taraf write-through dono ke saath chal sakta hai — high locality data ke liye write-allocate, aur low locality data ke liye no-allocate. Ye combinations samajhna zaroori hai kyunki yahi memory hierarchy ki performance ko real mein decide karte hain.