SlideShare a Scribd company logo
1 of 15
Cache Memory


                          V.Saranya
                              AP/CSE
Sri Vidya College of Engineering and
                         Technology,
                       Virudhunagar
Cache Memories
 Processor is much faster than the main memory.
   As a result, the processor has to spend much of its time waiting while instructions and data
    are being fetched from the main memory.
   Major obstacle towards achieving good performance.
 Speed of the main memory cannot be increased
  beyond a certain point.
 Cache memory is an architectural arrangement which
  makes the main memory appear faster to the
  processor than it really is.
 Cache memory is based on the property of computer
  programs known as “locality of reference”.
Locality of Reference
 Analysis of programs indicates that many instructions in
  localized areas of a program are executed repeatedly during
  some period of time, while the others are accessed relatively
  less frequently.
   These instructions may be the ones in a loop, nested loop
     or few procedures calling each other repeatedly.
   This is called “locality of reference”.
 Temporal locality of reference:
   Recently executed instruction is likely to be executed
     again very soon.
 Spatial locality of reference:
   Instructions with addresses close to a recently instruction
     are likely to be executed soon.
Cache memories

                                                          Main
                                                         Main
              Processor               Cache
                                      cache              memory
                                                        Memory



• Processor issues a Read request, a block of words is transferred from the
  main memory to the cache, one word at a time.
• Subsequent references to the data in this block of words are found in the
  cache.
• At any given time, only some blocks in the main memory are held in the
  cache. Which blocks in the main memory are in the cache is determined
  by a “mapping function”.
• When the cache is full, and a block of words needs to be transferred
  from the main memory, some block of words in the cache must be
  replaced. This is determined by a “replacement algorithm”.
Cache hit
• Existence of a cache is transparent to the processor. The
  processor                issues               Read                and
  Write requests in the same manner.
• If the data is in the cache it is called a Read or Write hit.
• Read hit:
   The data is obtained from the cache.
• Write hit:
   Cache has a replica(copy) of the contents of the main
     memory.
   Contents of the cache and the main memory may be updated
     simultaneously.      This is the write-through protocol.
   Update the contents of the cache, and mark it as updated by
     setting a bit known          as the dirty bit or modified bit. The
     contents of the main memory are updated                 when this
     block is replaced. This is write-back or copy-back protocol.
Cache miss
• If the data is not present in the cache, then a Read miss or
  Write miss occurs.
• Read miss:
   Block of words containing this requested word is transferred from
    the memory.
   After the block is transferred, the desired word is forwarded to the
    processor.
   The desired word may also be forwarded to the processor as soon
    as it is transferred without waiting for the entire block to be
    transferred. This is called load-through or early-restart.

• Write-miss:
   Write-through protocol is used, then the contents of the main
    memory are updated directly.
   If write-back protocol is used, the block containing the
    addressed word is first brought into the cache. The desired word
    is overwritten with new information.
Cache Coherence Problem

• A bit called as “valid bit” is provided for each block.
• If the block contains valid data, then the bit is set to 1, else
  it is 0.
• Valid bits are set to 0, when the power is just turned on.
• When a block is loaded into the cache for the first time, the
  valid bit is set to 1.
• Data transfers between main memory and disk occur
  directly bypassing the cache.
• When the data on a disk changes, the main memory block is
  also updated.
Cache Coherence Problem
• However, if the data is also resident in the cache, then the valid
  bit is set to 0.
• What happens if the data in the disk and main memory
  changes and the write-back protocol is being used?
• In this case, the data in the cache may also have changed and is
  indicated by the dirty bit.
• The copies of the data in the cache, and the main memory are
  different. This is called the cache coherence problem.
• One option is to force a write-back before the main memory is
  updated from the disk.
Mapping functions
 Mapping functions determine how memory
  blocks are placed in the cache.
 A simple processor example:
    Cache consisting of 128 blocks of 16 words each.
    Total size of cache is 2048 (2K) words.
    Main memory is addressable by a 16-bit address.
    Main memory has 64K words.
    Main memory has 4K blocks of 16 words each.
 Three mapping functions:
  Direct mapping
  Associative mapping
  Set-associative mapping.
Direct mapping
                                    Main      Block 0

             Cache                 memory     Block 1
tag
               Block 0
tag
               Block 1

                                            Block 127

                                            Block 128
tag
             Block 127                      Block 129




                                            Block 255
      T ag     Block       W ord
       5           7         4              Block 256

                                            Block 257
        Main memory
        address
                                            Block 4095
Direct mapping
•More than one memory block is mapped onto the same position in the
cache.
•May lead to contention for cache blocks even if the cache is not full.
•Resolve the contention by allowing new block to replace the old block,
leading to a trivial replacement algorithm.
•Memory address is divided into three fields:
   - Low order 4 bits determine one of the 16 words in a block.
   - When a new block is brought into the cache, the next 7 bits
determine which cache block this new block is placed in.
   - High order 5 bits determine which of the possible 32 blocks is
currently present in the cache. These are tag bits.
•Simple to implement but not very flexible.
Associative mapping
                                Main memory
                                      Block 0

               Cache                  Block 1
tag
               Block 0
tag
               Block 1

                                    Block 127

                                    Block 128
tag
           Block 127                Block 129




                                    Block 255
           Tag           Word
          12                4       Block 256

                                    Block 257
      Main memory address


                                   Block 4095
Associative mapping
•Main memory block can be placed into any cache
position.
•Memory address is divided into two fields:
   - Low order 4 bits identify the word within a block.
   - High order 12 bits or tag bits identify a memory block
when it is resident in the cache.
•Flexible, and uses cache space efficiently.
•Replacement algorithms can be used to replace an existing
block in the cache when the cache is full.
•Cost is higher than direct-mapped cache because of the need
to search all 128 patterns to determine whether a given block
is in the cache.
Set-Associative mapping
                           Cache             Main      Block 0
                                            memory     Block 1
       Block 0
           tag            Block 1
tag                       Block 2
          tag

       Block 3
                                                     Block 63

                                                     Block 64
tag
          tag
                        Block 126                    Block 65
      Block 127



tag
                                                     Block 127
                 T ag     Block     W ord
                  5           7       4              Block 128

                                                     Block 129
                   Main memory address

                                                     Block 4095
•Blocks of cache are grouped into sets.
•Mapping function allows a block of the main memory to reside
in any block of a specific set.
•Divide the cache into 64 sets, with two blocks per set.
•Memory block 0, 64, 128 etc. map to block 0, and they can
occupy either of the two positions.
Memory address is divided into three fields:
    - 6 bit field determines the set number.
    - High order 6 bit fields are compared to the tag
       fields of the two blocks in a set.
Set-associative mapping combination of direct and associative
mapping.
Number of blocks per set is a design parameter.
   - One extreme is to have all the blocks in one set,
      requiring no set bits (fully associative mapping).
   - Other extreme is to have one block per set, is
      the same as direct mapping.

More Related Content

What's hot

Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
Mustapha Fatty
 
Salient featurs of 80386
Salient featurs of 80386Salient featurs of 80386
Salient featurs of 80386
aviban
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 Microprocessor
Nikhil Kumar
 

What's hot (20)

PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386PAI Unit 3 Multitasking in 80386
PAI Unit 3 Multitasking in 80386
 
8086 modes
8086 modes8086 modes
8086 modes
 
Computer instruction
Computer instructionComputer instruction
Computer instruction
 
Interrupts
InterruptsInterrupts
Interrupts
 
Direct memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA ControllerDirect memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA Controller
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
PAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentationPAI Unit 2 Protection in 80386 segmentation
PAI Unit 2 Protection in 80386 segmentation
 
RTOS for Embedded System Design
RTOS for Embedded System DesignRTOS for Embedded System Design
RTOS for Embedded System Design
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Microprocessor and Interfacing Notes
Microprocessor and Interfacing NotesMicroprocessor and Interfacing Notes
Microprocessor and Interfacing Notes
 
8086 memory segmentation
8086 memory segmentation8086 memory segmentation
8086 memory segmentation
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086
 
Cache replacement policies,cache miss,writingtechniques
Cache replacement policies,cache miss,writingtechniquesCache replacement policies,cache miss,writingtechniques
Cache replacement policies,cache miss,writingtechniques
 
Salient featurs of 80386
Salient featurs of 80386Salient featurs of 80386
Salient featurs of 80386
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 Microprocessor
 
8086 Microprocessor powerpoint
8086  Microprocessor  powerpoint8086  Microprocessor  powerpoint
8086 Microprocessor powerpoint
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 

Viewers also liked (9)

cache memory
cache memorycache memory
cache memory
 
Cache memory presentation
Cache memory presentationCache memory presentation
Cache memory presentation
 
cache memory management
cache memory managementcache memory management
cache memory management
 
CS6303 - Computer Architecture
CS6303 - Computer ArchitectureCS6303 - Computer Architecture
CS6303 - Computer Architecture
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
INSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMINSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISM
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache memory
Cache memoryCache memory
Cache memory
 

Similar to Cachememory

coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
Ruhul Amin
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystem
Sandeep Kamath
 

Similar to Cachememory (20)

coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
 
cache memory
 cache memory cache memory
cache memory
 
Cache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.pptCache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.ppt
 
cache memory introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, function
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystem
 
cache memory
cache memorycache memory
cache memory
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 
Elements of cache design
Elements of cache designElements of cache design
Elements of cache design
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
 
FlashCache
FlashCacheFlashCache
FlashCache
 
Mapping
MappingMapping
Mapping
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 
CAO-Unit-III.pptx
CAO-Unit-III.pptxCAO-Unit-III.pptx
CAO-Unit-III.pptx
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
CPU Caching Concepts
CPU Caching ConceptsCPU Caching Concepts
CPU Caching Concepts
 

More from Slideshare

Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010
Slideshare
 
Report generation
Report generationReport generation
Report generation
Slideshare
 
Security in Relational model
Security in Relational modelSecurity in Relational model
Security in Relational model
Slideshare
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Slideshare
 
Major issues in data mining
Major issues in data miningMajor issues in data mining
Major issues in data mining
Slideshare
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
Slideshare
 
What is in you
What is in youWhat is in you
What is in you
Slideshare
 
Propositional logic & inference
Propositional logic & inferencePropositional logic & inference
Propositional logic & inference
Slideshare
 
Logical reasoning 21.1.13
Logical reasoning 21.1.13Logical reasoning 21.1.13
Logical reasoning 21.1.13
Slideshare
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
Slideshare
 
Resolution(decision)
Resolution(decision)Resolution(decision)
Resolution(decision)
Slideshare
 
Reinforcement learning 7313
Reinforcement learning 7313Reinforcement learning 7313
Reinforcement learning 7313
Slideshare
 
Neural networks
Neural networksNeural networks
Neural networks
Slideshare
 
Instance based learning
Instance based learningInstance based learning
Instance based learning
Slideshare
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
Slideshare
 
Neural networks
Neural networksNeural networks
Neural networks
Slideshare
 
Logical reasoning
Logical reasoning Logical reasoning
Logical reasoning
Slideshare
 

More from Slideshare (20)

Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010
 
Report generation
Report generationReport generation
Report generation
 
Trigger
TriggerTrigger
Trigger
 
Security in Relational model
Security in Relational modelSecurity in Relational model
Security in Relational model
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
OLAP
OLAPOLAP
OLAP
 
Major issues in data mining
Major issues in data miningMajor issues in data mining
Major issues in data mining
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
 
What is in you
What is in youWhat is in you
What is in you
 
Propositional logic & inference
Propositional logic & inferencePropositional logic & inference
Propositional logic & inference
 
Logical reasoning 21.1.13
Logical reasoning 21.1.13Logical reasoning 21.1.13
Logical reasoning 21.1.13
 
Logic agent
Logic agentLogic agent
Logic agent
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
 
Resolution(decision)
Resolution(decision)Resolution(decision)
Resolution(decision)
 
Reinforcement learning 7313
Reinforcement learning 7313Reinforcement learning 7313
Reinforcement learning 7313
 
Neural networks
Neural networksNeural networks
Neural networks
 
Instance based learning
Instance based learningInstance based learning
Instance based learning
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
 
Neural networks
Neural networksNeural networks
Neural networks
 
Logical reasoning
Logical reasoning Logical reasoning
Logical reasoning
 

Recently uploaded

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Cachememory

  • 1. Cache Memory V.Saranya AP/CSE Sri Vidya College of Engineering and Technology, Virudhunagar
  • 2. Cache Memories  Processor is much faster than the main memory.  As a result, the processor has to spend much of its time waiting while instructions and data are being fetched from the main memory.  Major obstacle towards achieving good performance.  Speed of the main memory cannot be increased beyond a certain point.  Cache memory is an architectural arrangement which makes the main memory appear faster to the processor than it really is.  Cache memory is based on the property of computer programs known as “locality of reference”.
  • 3. Locality of Reference  Analysis of programs indicates that many instructions in localized areas of a program are executed repeatedly during some period of time, while the others are accessed relatively less frequently.  These instructions may be the ones in a loop, nested loop or few procedures calling each other repeatedly.  This is called “locality of reference”.  Temporal locality of reference:  Recently executed instruction is likely to be executed again very soon.  Spatial locality of reference:  Instructions with addresses close to a recently instruction are likely to be executed soon.
  • 4. Cache memories Main Main Processor Cache cache memory Memory • Processor issues a Read request, a block of words is transferred from the main memory to the cache, one word at a time. • Subsequent references to the data in this block of words are found in the cache. • At any given time, only some blocks in the main memory are held in the cache. Which blocks in the main memory are in the cache is determined by a “mapping function”. • When the cache is full, and a block of words needs to be transferred from the main memory, some block of words in the cache must be replaced. This is determined by a “replacement algorithm”.
  • 5. Cache hit • Existence of a cache is transparent to the processor. The processor issues Read and Write requests in the same manner. • If the data is in the cache it is called a Read or Write hit. • Read hit:  The data is obtained from the cache. • Write hit:  Cache has a replica(copy) of the contents of the main memory.  Contents of the cache and the main memory may be updated simultaneously. This is the write-through protocol.  Update the contents of the cache, and mark it as updated by setting a bit known as the dirty bit or modified bit. The contents of the main memory are updated when this block is replaced. This is write-back or copy-back protocol.
  • 6. Cache miss • If the data is not present in the cache, then a Read miss or Write miss occurs. • Read miss:  Block of words containing this requested word is transferred from the memory.  After the block is transferred, the desired word is forwarded to the processor.  The desired word may also be forwarded to the processor as soon as it is transferred without waiting for the entire block to be transferred. This is called load-through or early-restart. • Write-miss:  Write-through protocol is used, then the contents of the main memory are updated directly.  If write-back protocol is used, the block containing the addressed word is first brought into the cache. The desired word is overwritten with new information.
  • 7. Cache Coherence Problem • A bit called as “valid bit” is provided for each block. • If the block contains valid data, then the bit is set to 1, else it is 0. • Valid bits are set to 0, when the power is just turned on. • When a block is loaded into the cache for the first time, the valid bit is set to 1. • Data transfers between main memory and disk occur directly bypassing the cache. • When the data on a disk changes, the main memory block is also updated.
  • 8. Cache Coherence Problem • However, if the data is also resident in the cache, then the valid bit is set to 0. • What happens if the data in the disk and main memory changes and the write-back protocol is being used? • In this case, the data in the cache may also have changed and is indicated by the dirty bit. • The copies of the data in the cache, and the main memory are different. This is called the cache coherence problem. • One option is to force a write-back before the main memory is updated from the disk.
  • 9. Mapping functions  Mapping functions determine how memory blocks are placed in the cache.  A simple processor example:  Cache consisting of 128 blocks of 16 words each.  Total size of cache is 2048 (2K) words.  Main memory is addressable by a 16-bit address.  Main memory has 64K words.  Main memory has 4K blocks of 16 words each.  Three mapping functions:  Direct mapping  Associative mapping  Set-associative mapping.
  • 10. Direct mapping Main Block 0 Cache memory Block 1 tag Block 0 tag Block 1 Block 127 Block 128 tag Block 127 Block 129 Block 255 T ag Block W ord 5 7 4 Block 256 Block 257 Main memory address Block 4095
  • 11. Direct mapping •More than one memory block is mapped onto the same position in the cache. •May lead to contention for cache blocks even if the cache is not full. •Resolve the contention by allowing new block to replace the old block, leading to a trivial replacement algorithm. •Memory address is divided into three fields: - Low order 4 bits determine one of the 16 words in a block. - When a new block is brought into the cache, the next 7 bits determine which cache block this new block is placed in. - High order 5 bits determine which of the possible 32 blocks is currently present in the cache. These are tag bits. •Simple to implement but not very flexible.
  • 12. Associative mapping Main memory Block 0 Cache Block 1 tag Block 0 tag Block 1 Block 127 Block 128 tag Block 127 Block 129 Block 255 Tag Word 12 4 Block 256 Block 257 Main memory address Block 4095
  • 13. Associative mapping •Main memory block can be placed into any cache position. •Memory address is divided into two fields: - Low order 4 bits identify the word within a block. - High order 12 bits or tag bits identify a memory block when it is resident in the cache. •Flexible, and uses cache space efficiently. •Replacement algorithms can be used to replace an existing block in the cache when the cache is full. •Cost is higher than direct-mapped cache because of the need to search all 128 patterns to determine whether a given block is in the cache.
  • 14. Set-Associative mapping Cache Main Block 0 memory Block 1 Block 0 tag Block 1 tag Block 2 tag Block 3 Block 63 Block 64 tag tag Block 126 Block 65 Block 127 tag Block 127 T ag Block W ord 5 7 4 Block 128 Block 129 Main memory address Block 4095
  • 15. •Blocks of cache are grouped into sets. •Mapping function allows a block of the main memory to reside in any block of a specific set. •Divide the cache into 64 sets, with two blocks per set. •Memory block 0, 64, 128 etc. map to block 0, and they can occupy either of the two positions. Memory address is divided into three fields: - 6 bit field determines the set number. - High order 6 bit fields are compared to the tag fields of the two blocks in a set. Set-associative mapping combination of direct and associative mapping. Number of blocks per set is a design parameter. - One extreme is to have all the blocks in one set, requiring no set bits (fully associative mapping). - Other extreme is to have one block per set, is the same as direct mapping.