Docsity

Memory Multiplexing and Paging Techniques, Study notes of Operating Systems

Partial preview of the text

Download Memory Multiplexing and Paging Techniques and more Study notes Operating Systems in PDF only on Docsity!

Memory:

Kernel and Address Spaces

Maxim Shevertalov Jay Kothari CS370: Operating Systems 7/31/

Virtualizing Resources

  • Physical Reality:
    • Different Processes/Threads share the same hardware
      • Need to multiplex CPU (Just finished: scheduling)
      • Need to multiplex use of Memory (Today)
      • Need to multiplex disk and devices (later in term)
  • Why worry about memory sharing?
    • The complete working state of a process and/or kernel is defined by its data in memory (and registers)
    • Consequently, cannot just let different threads of control use the same memory - Physics: two different pieces of data cannot occupy the same locations in memory
    • Probably don’t want different threads to even have access to each other’s memory (protection)

Example of General Address Translation

Prog 1 Virtual Address Space 1 Prog 2 Virtual Address Space 2 Code Data Heap Stack Code Data Heap Stack Data 2 Stack 1 Heap 1 OS heap & Stacks Code 1 Stack 2 Data 1 Heap 2 Code 2 OS code OS data Translation Map 1 Translation Map 2 Physical Address Space

Two Views of Memory

  • Recall: Address Space:
    • All the addresses and state a process can touch
    • Each process and kernel has different address space
  • Consequently: two views of memory:
    • View from the CPU (what program sees, virtual memory)
    • View from memory (physical memory)
    • Translation box converts between the two views
  • Translation helps to implement protection
    • If task A cannot even gain access to task B’s data, no way for A to adversely affect B
  • With translation, every program can be linked/loaded into same region of user address space - Overlap avoided through translation, not relocation Physical Addresses

CPU MMU

Virtual Addresses Untranslated read or write

Summary

  • Memory is a resource that must be shared
    • Controlled Overlap: only shared when appropriate
    • Translation: Change Virtual Addresses into Physical Addresses
    • Protection: Prevent unauthorized Sharing of resources
  • Simple Protection through Segmentation
    • Base+limit registers restrict memory accessible to user
    • Can be used to translate as well
  • Full translation of addresses through Memory Management Unit (MMU)
    • Every Access translated through page table
    • Changing of page tables only available to kernel
  • Dual-Mode
    • Kernel/User distinction: User restricted
    • User→Kernel: System calls, Traps, or Interrupts
    • Inter-process communication: shared memory, or through kernel

(system calls)

Segmentation with Base and Limit registers

  • Could use base/limit for dynamic address translation (often called “segmentation”): - Alter address of every load/store by adding “base” - User allowed to read/write within segment - Accesses are relative to segment so don’t have to be relocated when program moved to different segment - This gives program the illusion that it is running on its own dedicated machine, with memory starting at 0 - Program gets continuous region of memory - Addresses within program do not have to be relocated when program placed in different region of DRAM **DRAM

?

Base Limit CPU Virtual Address Physical Address Yes: Error!**

More Flexible Segmentation

  • Logical View: multiple separate segments
    • Typical: Code, Data, Stack
    • Others: memory sharing, etc
  • Each segment is given region of contiguous memory
    • Has a base and limit
    • Can reside anywhere in physical memory

logical address

subroutine symbol table stack main program 1 2 4 3 user view of memory space 1 4 3 2 physical memory space

Implementing the Multi-Segment Model

  • Segment map resides in processor
    • Segment number mapped into base/limit pair
    • Base added to offset to generate physical address
    • Error check catches offset out of range
  • As many chunks of physical memory as entries
    • Segment addressed by portion of virtual address
  • What is “V/N”?
    • Can mark segments as invalid; requires check as well Seg # Offset

Base0 Limit0 N Base1 Limit1 V Base2 Limit2 V Base3 Limit3 N Base4 Limit4 V

Error

Physical

Address

Multi-level Translation

  • What must be saved/restored on context switch?
    • Contents of top-level segment registers (for this example)
    • Pointer to top-level table (page table)
  • Sharing
    • Complete segments
    • Individual pages Virtual page # Offset Physical page # Offset page 0 v,r page 1 v,r,w page 2 n page 3 v,r,w page 4 v,r

Check Permissions Access Error Virtual Seg # Base0 Limit0 N Base1 Limit1 V Base2 Limit2 V Base3 Limit3 N Base4 Limit4 V (^) Access Error

Two level page table

Offset

  • page Virtual
  • page Virtual - page - page - page - page - page - page PageTablePointer - page - page - page - page - page - page - page - page - page - page - page - page

Schematic View of Swapping

  • Extreme form of Context Switch: Swapping
    • In order to make room for next process, some or all of the previous process is moved to disk »Likely need to send out complete segments
    • This greatly increases the cost of context-switching
  • Desirable alternative?
    • Some way to keep only active portions of a process in memory at any one time
    • Need finer granularity control over physical memory 31 Schematic View of Swapping
  • Extreme form of Context Switch: Swapping
  • In order to make room for next process, some or all of the previous process is moved to disk » Likely need to send out complete segments
  • This greatly increases the cost of context-switching
  • Desirable alternative?
  • Some way to keep only active portions of a process in memory at any one time
  • Need finer granularity control over physical memory

Summary

  • Multi-Segment Model enables each process to think it has access to all the memory it needs
  • Pages => finer granularity of data so that not everything needs to be swapped during a context switch
  • Swapping means moving all or some of the process’s memory from physical memory to the backing store
  • Simple Paging => page table may get very large for a sparse address space
    • Combine segmentation and paging => multi-level translation
  • Multi-level translation
    • May be slow if lots of levels
  • Inverted Page table
    • Store a hash table of of physical addresses
    • Size is independent of virtual address space

Why Cache???

Why Cache???

  • Processor-DRAM Memory Gap (latency)
  • Processor: ~60% per year (doubles every 1.5 years)
  • Memory: ~9% per year (doubles every 10 years)
  • Gap grows 50% per year CPU !Proc 60%/yr. (2X/1.5yr) DRAM 9%/yr. (2X/ yrs) DRAM

198019811982198319841985198619871988198919901991199219931994199519961997199819992000 Processor-Memory Performance Gap: (grows 50% / year)

Performance

Time “Moore’s Law” (really Joy’s Law) Processor-DRAM Memory Gap (latency) Why Bother with Caching? “Less’ Law?”