Damian Gordon
HARD DISK
(MAIN
MEMORY)
(SECONDARY
MEMORY)
2
CACHE 1
HARD DISK
(MAIN
MEMORY)
(SECONDARY
MEMORY)
2
CACHE 1
HARD DISK
(MAIN
MEMORY)
(SECONDARY
MEMORY)
2
CACHE 1
Computer
programs
are stored
here
HARD DISK
(MAIN
MEMORY)
(SECONDARY
MEMORY)
2
CACHE 1
Computer
programs
are stored
here
Until they
need to
be
executed
HARD DISK
(MAIN
MEMORY)
(SECONDARY
MEMORY)
2
CACHE 1
Computer
programs
are stored
here
Until they
need to
be
executedThen they
are moved
to here
 In modern operating systems, before a
program is loaded into main memory, it is
divided into chunks, called PAGES.
 In modern operating systems, before a
program is loaded into main memory, it is
divided into chunks, called PAGES.
Program 3
 In modern operating systems, before a
program is loaded into main memory, it is
divided into chunks, called PAGES.
Program 3
Page 2
Page 3
Page 4
Page 5
Page 6
Page 1
Page 7
 Each PAGE is loaded into memory locations
called PAGE FRAMES.
 Each PAGE is loaded into memory locations
called PAGE FRAMES.
200K
available
MAIN
MEMORY
 Each PAGE is loaded into memory locations
called PAGE FRAMES.
MAIN
MEMORY
Page Frame 1
Page Frame 2
Page Frame 3
Page Frame 4
Page Frame 5
Page Frame 6
Page Frame 7
Page Frame 8
Page Frame 9
Page Frame 10
200K
available
 If the PAGES are the exact
same size as the PAGE
FRAMES (and the same
size as the disk sectors),
this scheme works very
well. MAIN
MEMORY
Page Frame 1
Page Frame 2
Page Frame 3
Page Frame 4
Page Frame 5
Page Frame 6
Page Frame 7
Page Frame 8
Page Frame 9
Page Frame 10
200K
available
 The Memory Manager prepares a program for
execution by doing the following:
1. Determine the number of pages in the program
2. Locate enough empty page frames in main
memory
3. Load all the program’s pages into them
The empty page frame does not have to be
contagious.
 Consider a program that 350 bytes, and the
page size is 100 bytes.
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Program 4:
350 bytes
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Program 4:
350 bytes
Page 0
Program 4:
350 bytes
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Page 0
Page 1
Program 4:
350 bytes
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Page 0
Page 1
Page 2
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Page 3
Program 4:
350 bytes
Page 0
Page 1
Page 2
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Main
Memory
Page 3
Program 4:
350 bytes
Page 0
Page 1
Page 2
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Main
Memory
Operating
System
Page 3
Program 4:
350 bytes
Page 0
Page 1
Page 2
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Main
Memory
Operating
System
Page 2
Page 0
Page 1
Page 3
Page 3
Program 4:
350 bytes
Page 0
Page 1
Page 2
 Consider a program that 350 bytes, and the
page size is 100 bytes.
Main
Memory
Operating
System
Page 2
Page 0
Page 1
Page 3
A little bit of
internal
fragmentation
Page 3
Program 4:
350 bytes
Page 0
Page 1
Page 2
 A useful extension to the notion of PAGING is
DEMAND PAGING.
 Demand Paging introduces the notion that
you don’t have to load the whole program
into memory, just part of it.
 Because not all of the program needs to be in
memory at the same time.
 This means that lots of programs can be run
at the same time, and there is an illusion of a
significantly larger amount of memory than
with regular paging.
 To make this work, pages have to be moved
very quickly from Secondary Storage to Main
Memory and back again (this is called
“swapping”).
 This leads to the concept of VIRTUAL
MEMORY
 The size of main memory appears much
larger than the actual size, since many
programs can appear to be fully loaded into
main memory at the same time, when in
actual fact, only part of many programs are
loaded into main memory.

Operating Systems: Virtual Memory

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
    HARD DISK (MAIN MEMORY) (SECONDARY MEMORY) 2 CACHE 1 Computer programs arestored here Until they need to be executedThen they are moved to here
  • 7.
     In modernoperating systems, before a program is loaded into main memory, it is divided into chunks, called PAGES.
  • 8.
     In modernoperating systems, before a program is loaded into main memory, it is divided into chunks, called PAGES. Program 3
  • 9.
     In modernoperating systems, before a program is loaded into main memory, it is divided into chunks, called PAGES. Program 3 Page 2 Page 3 Page 4 Page 5 Page 6 Page 1 Page 7
  • 10.
     Each PAGEis loaded into memory locations called PAGE FRAMES.
  • 11.
     Each PAGEis loaded into memory locations called PAGE FRAMES. 200K available MAIN MEMORY
  • 12.
     Each PAGEis loaded into memory locations called PAGE FRAMES. MAIN MEMORY Page Frame 1 Page Frame 2 Page Frame 3 Page Frame 4 Page Frame 5 Page Frame 6 Page Frame 7 Page Frame 8 Page Frame 9 Page Frame 10 200K available
  • 13.
     If thePAGES are the exact same size as the PAGE FRAMES (and the same size as the disk sectors), this scheme works very well. MAIN MEMORY Page Frame 1 Page Frame 2 Page Frame 3 Page Frame 4 Page Frame 5 Page Frame 6 Page Frame 7 Page Frame 8 Page Frame 9 Page Frame 10 200K available
  • 14.
     The MemoryManager prepares a program for execution by doing the following: 1. Determine the number of pages in the program 2. Locate enough empty page frames in main memory 3. Load all the program’s pages into them The empty page frame does not have to be contagious.
  • 15.
     Consider aprogram that 350 bytes, and the page size is 100 bytes.
  • 16.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Program 4: 350 bytes
  • 17.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Program 4: 350 bytes Page 0
  • 18.
    Program 4: 350 bytes Consider a program that 350 bytes, and the page size is 100 bytes. Page 0 Page 1
  • 19.
    Program 4: 350 bytes Consider a program that 350 bytes, and the page size is 100 bytes. Page 0 Page 1 Page 2
  • 20.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Page 3 Program 4: 350 bytes Page 0 Page 1 Page 2
  • 21.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Main Memory Page 3 Program 4: 350 bytes Page 0 Page 1 Page 2
  • 22.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Main Memory Operating System Page 3 Program 4: 350 bytes Page 0 Page 1 Page 2
  • 23.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Main Memory Operating System Page 2 Page 0 Page 1 Page 3 Page 3 Program 4: 350 bytes Page 0 Page 1 Page 2
  • 24.
     Consider aprogram that 350 bytes, and the page size is 100 bytes. Main Memory Operating System Page 2 Page 0 Page 1 Page 3 A little bit of internal fragmentation Page 3 Program 4: 350 bytes Page 0 Page 1 Page 2
  • 25.
     A usefulextension to the notion of PAGING is DEMAND PAGING.  Demand Paging introduces the notion that you don’t have to load the whole program into memory, just part of it.  Because not all of the program needs to be in memory at the same time.
  • 26.
     This meansthat lots of programs can be run at the same time, and there is an illusion of a significantly larger amount of memory than with regular paging.
  • 27.
     To makethis work, pages have to be moved very quickly from Secondary Storage to Main Memory and back again (this is called “swapping”).
  • 28.
     This leadsto the concept of VIRTUAL MEMORY  The size of main memory appears much larger than the actual size, since many programs can appear to be fully loaded into main memory at the same time, when in actual fact, only part of many programs are loaded into main memory.