Virtual Memory: Memory Protection

  • Read Slide.
  • Random offsets are used for security purpose so no one can change the data.
  • Kernel space maps to same location in RAM for all programs.




Virtual Memory: Address Translation

  • Virtual address bits are decided by ISA (Instruction Set Architecture), and P address bits are based on RAM available. In the cases considered here, there is 32-bit ISA and 256MB RAM.
  • Page offsets depend upon frame/page size. Here each page has a size of 4KB.


  • This is how an address in RAM is translated.


  • When T. address (Page) is on Disk.
  • In this case, CPU generates an exception: Page Fault
  • Hardware gives control to OS’s Page Fault Exception handler.
  • OS decides which page to move out from RAM to replace with this recently accessed one.
  • If the page is dirty, it has to be written on the disk too.[ The bit indicates that its associated block of memory has been modified and has not yet been saved to storage. ], then update page table. Now OS jumps to the same instruction what caused fault.
  • Page Faults are very expensive.


How Virtual Memory Works?

  • Each programs has its on virtual address space and Map(Translator). Map maps to the physical address either in RAM or Disk.
  • When address is mapped in Disk, it is first loaded to RAM, also mapping table is updated and then data is loaded.
  • This Map is called Page Table and the entry in it is called Page Table Entry.
    • Well, if, for each virtual address an entry is used, the size of Page Table alone would be large. Also, note that for each program we have a Page Table.
    • So, each entry instead of handling each V. address, handles chunk of V. addresses(range) and maps that to chunk of P. addresses(range).
    • The point above resolves the problem of large memory usage.
    • We typically have 4kB of pages(1024 words).
    • Bigger the page size, moving from the disk would take more time. Lesser the page size, more memory is needed to store page table.
  • A V. address is divided in V. Page number and Page offset. V. Page number is mapped to P. page address and page offset just concatenates with it.Screenshot from 2016-06-22 22-13-50

Introduction: Virtual Memory


  • Not enough RAM-> CRASH
    • MIPS provides 32 bit address space(4GB memory), suppose we have only 1GB RAM. How to access address out of 1GB range?
  • Secure address space-> CORRUPT
    • Two programs can write on same address
  • Holes in the address space-> OUT OF SPACE
    • Say there are 3 programs like-> p1 needs 1GB, p2 needs 2GB and p3 need 1GB. In out 4GB address space p1 and p2 fit in, respectively. Say p1 is terminated. We have 2 address spaces of 1GB above and below of p2.
      Although we have enough space but we cannot allocate it to p3 because of Memory Fragmentation.


  • By mapping the virtual memory space given to the program to actual memory space.
  • In this, way all the programs have different VS.


  • It is an indirection from virtual address spaces generated by program to some address from where the required data can be accessed.


  • Not enough RAM-> CRASH
    • Map has the mapping to disk also, whenever some address that is accessed that’s not in RAM, Map goes to the Disk, takes that data and pages out some other data to Disk to put this new, recently accessed data into RAM.
      Along with this, Map updates it self for the address whose data has been paged out.
  • Holes in the address space-> OUT OF SPACE
    • Considering the same situation as above, both p2 and p3(as well p1) would have their Maps, now p3’s address space can be mapped to 2 chunks of 1GB.
  • Secure address space-> CORRUPT
    • If 2 programs are accessing same address to write, Map of each can prevent them to write on same address.
    • Two prevent complete isolation though, programs can have same mappings.