14,074 views
24 votes
24 votes

3 Answers

Best answer
74 votes
74 votes

WRITE THROUGH

On a write, memory and cache are often updated simultaneously (usually this will be specified in question) and so write time will be memory access time for a word. On a cache miss, usually only memory is updated (no write allocate policy). 

On a read, a cache block is retrieved from memory and hence the read time on cache miss will be the time to bring a block from memory plus cache access time on hierarchical access and just the memory access time for a block, if both memory and cache can be accessed in parallel. 

So, 

For hierarchical access and write-through:

$T_{read} = H \times T_{cache} + (1-H) \times (T_{cache} + T_{memory\_block}) \\= T_{cache} + (1-H) \times T_{memory\_block}$

For simultaneous access and write-through: 

$T_{read} = H \times T_{cache} + (1-H) \times (T_{memory\_block})$

Due to hit rates being larger and cache being much faster, the above 2 times are almost the same. 

Hierarchical access and write-though case for memory write is actually not present in practical as since memory is always accessed in case of write through, it makes sense to provide simultaneous write to cache and memory.

For simultaneous access and write-through: 

$T_{write} = T_{memory\_word} $

​Notice that on write, a $word$ is being updated and on read a $block$ is retrieved from memory.


WRITE BACK

In a write-back cache whenever a cache block is replaced, if it is dirty, then that block is written back to memory. So, this is an overhead on all cache misses. Write Back, policy usually follows write-allocate- i.e., on a cache miss during write, the corresponding memory block is brought from memory to cache. 

For hierarchical access and write-back:

$T_{read} = T_{write} = H \times T_{cache} + (1-H) \times (T_{cache} + T_{memory\_block} + T_{write\_back}) \\= T_{cache} + (1-H) \times (T_{memory\_block} + T_{write\_back}), \\ \text{ where } T_{write\_back} = x \times T_{memory\_block}, \text{ where } x \text{ is the fraction of dirty blocks} $

For simultaneous access and write-back: 

$T_{read} = T_{write} = H \times T_{cache} + (1-H) \times ( T_{memory\_block} + T_{write\_back}), \\ \text{ where } T_{write\_back} = x \times T_{memory\_block}, \text{ where } x \text{ is the fraction of dirty blocks} $

Ref: http://web.cs.iastate.edu/~prabhu/Tutorial/CACHE/interac.html

 

 

selected by
5 votes
5 votes

WRITE THROUGH

for hierarchical :

t avg read= Hc*Tc+(1-Hc)(TM+TC)

t avg write=Hc*TW+(1-Hc)(TM+TW)

here TW : is the time which is used to update the word in main memory i ,e MAX (TM,TC)

 

for simultaneous (called as parallel ) :

t avg read= Hc*Tc+(1-Hc)(TM)

t avg write=Hc*TW+(1-Hc)(TM+TW)

here TW : is the time which is used to update the word in main memory i ,e MAX (TM,TC)


WRITE BACK

for  hierarchical :

t avg read= Hc*Tc+(1-Hc)(% dirty bits(TM+TC)+% clean bits(TW+TM+TC))

t avg write=Hc*Tc+(1-Hc)(% dirty bits(TM+TC)+% clean bits(TW+TM+TC))

for simultaneous  ( called as parallel ):

t avg read= Hc*Tc+(1-Hc)(% dirty bits(TM)+% clean bits(TW+TM))

t avg write=Hc*Tc+(1-Hc)(% dirty bits(TM)+% clean bits(TW+TM))

 

here TW : is the time which is used to update the word in main memory i ,e MAX (TM,TC)


edited by
2 votes
2 votes

By Default

WRITE THROUGH using   WRITE NO ALLOCATE. 

And WRITE BACK is using WRITE ALLOCATE  

in both write through and write back , Hit and Miss possible.

In Write Through :

When cache hit occurs -- cache is updated and main memory is updated simultaneously. So both cache and MM is updated here at the same time.

When cache is missed -- main memory is updated; cache is not updated by default assuming write-no allocate policy being in use. 

In Write Back :

When cache Hit occurs - Only cache is updated and main memory is not updated. ( The modified cache block is written to main memory only when the cache block is replaced.)

When cache is Missed -  it updates the block in main memory and brings the updated block to the cache; 

Reference:

  1. https://web.cs.iastate.edu/~prabhu/Tutorial/CACHE/interac.html

Related questions

0 votes
0 votes
1 answer
1