review important os concepts
play

Review: important OS concepts Time-sharing, context, context-switch - PowerPoint PPT Presentation

Review: important OS concepts Time-sharing, context, context-switch Interprocess communication Exception control flow Priority and scheduling Cache and memory hierarchy (this lecture) Cache & Memory Hierarchy Recall our


  1. Review: important OS concepts • Time-sharing, context, context-switch • Interprocess communication • Exception control flow • Priority and scheduling • Cache and memory hierarchy (this lecture)

  2. Cache & Memory Hierarchy

  3. Recall our abstraction: CPU + memory CPU Address Content # ffffffff 8bits Register1 CPU has a number of registers. … Memory is a two-column table. … Register2 #00000002 8bits #00000001 8bits (More registers) #00000000 8bits

  4. Recall our abstraction: CPU + memory CPU Address Content load instruction # ffffffff 8bits Register1 … store instruction … Register2 #00000002 8bits Load and store cost constant time. #00000001 8bits (More registers) #00000000 8bits

  5. Why cache in the middle? CPU Address Content Cache # ffffffff byte Register1 … Cache is faster than memory. … Register2 Memory has larger capacity #00000002 byte than cache. #00000001 byte (More registers) Memory is cheaper than cache #00000000 byte in terms of $/byte.

  6. What to learn about cache? CPU Address Content Cache # ffffffff 8bits Register1 … What is the interface of a cache? … Register2 What is the structure of a cache? #00000002 8bits #00000001 8bits (More registers) #00000000 8bits

  7. Write-through and Write-back cache • Write-through and write-back are two types of cache. • You are going to implement both in P3. • The general structure is a 3-column table. Cache Cache Address Content In use? a cache line or cache entry Addr1 8bits Yes ???? ???? NO …

  8. Read in Write-back and Write-through CPU Address Content Cache # ffffffff 8bits Address Content In use? load read Register1 … … Register2 #00000002 8bits content_t read(addr_t) { #00000001 8bits (More registers) // read local structure or #00000000 8bits // read memory using load }

  9. Write in both Write-back and Write-through CPU Address Content Cache # ffffffff 8bits Address Content In use? Register1 … store write … Register2 #00000002 8bits void write(addr_t, content_t) { #00000001 8bits (More registers) // write local structure #00000000 8bits // and maybe write memory // using store }

  10. Sync (or flush) in Write-back cache CPU Address Content Cache # ffffffff 8bits Address Content In use? Register1 … store sync … Register2 #00000002 8bits void sync() { #00000001 8bits (More registers) // write memory using store #00000000 8bits // content that is in cache // but not yet in memory }

  11. Write-through and Write-back cache • Write-through and write-back are two types of cache. • You are going to implement both in P3. • The general structure is a 3-column table. Cache • Write-through cache: Cache • read + write using load + store Address Content In use? • Write-back cache: Addr1 8bits Yes • read + write + sync using load + store ???? ???? NO …

  12. Question: what about dirty bit? When is a dirty bit useful? You may recall something called dirty bit that you learned in 3410.

  13. Cache eviction • When the cache is full and a new entry needs to be added, the cache evicts an entry back to the memory. • In write-through cache, the evicted cache entry does NOT need to be Cache stored back to memory. • In write-back cache, the evicted cache entry, if dirty, needs to be stored back to memory. • In P3, you will implement the CLOCK algorithm for cache eviction which will be taught in 4410 (Oct 27).

  14. Cache & Memory Hierarchy

  15. Memory Hierarchy High Cache Price ($ per byte) Low Picture source: https://link.springer.com/article/10.1007/s00778-019-00546-z

  16. Example: internal of Intel i7 CPU

  17. CPU cache hierarchy L1 cache L2 cache L3 cache

  18. CPU cache hierarchy Registers L1 cache L2 cache L3 cache From Figure 6.39 of Main memory Computer Systems A Programmer’s Perspective

  19. Memory hierarchy performance and capacity Cache level Access time Capacity L1 4 cycles 32KB L2 10 cycles 256KB L3 40-75 cycles 8MB Main memory 200 cycles 4-16GB Disk >1M cycles >1TB

  20. Take-aways • Cache makes memory access faster, but cache has smaller capacity and is more expensive. • Di ff erent levels of cache form a memory hierarchy. • CPU cache hosts KB and costs tens of CPU cycles • Main memory hosts GB and costs hundreds of CPU cycles • Disks hosts TB and costs millions of CPU cycles

  21. Homework • P3 is released today due on Nov 6. Implement write-back and write-through cache with the CLOCK algorithm. • Read page241 of the Intel’s IA-32 manual Volume2 (https://www.intel.com/content/dam/www/public/us/en/ documents/manuals/64-ia-32-architectures-software- developer-instruction-set-reference-manual-325383.pdf) about the CLFLUSH instruction.

  22. Just for fun • Main memory internal structure and row-hammer attack What is inside here?

  23. Just for fun • Main memory internal structure and row-hammer attack • Further reading: section 6.1 of Computer Systems A Programmer’s Perspective.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend