Title: Virtual Memory Paging
1Virtual Memory / Paging
- Stewart Blakeway
- FML 208
- blakews_at_hope.ac.uk
- 0151 291 3113
2Session Aims
- Understand what Paging is
- Why Paging is used
- Characteristics and Implications of Paging
3Available RAM
- All computers have a limited amount of RAM
- Typically you can expect 256, 512, 1024 or 2048
Meg of RAM in your computer - This is NOT a lot in comparison to how much
Memory the Operating System, Applications and
Devices demand
4Main Memory
- Main Memory is essential for Processes to exist
- This is where instructions reside which are
interpreted by the CPU
5Single Process System
Memory
6Fixed Memory Partition
1000k
Partition 3 400k
600k
Partition 2 300k
300k
Partition 1 200k
100k
7Variable Memory Partition
1000k
600k
300k
100k
8Variable Memory Partition
1000k
600k
300k
100k
9Variable Memory Partition with Compaction
1000k
600k
300k
100k
10Simple Paging
Process A
Process B
Process C
Memory Space
11Simple Paging
Process A
Process C
Memory Space
12Simple Paging
Process A
Process D
Process C
Memory Space
Process E
13Main Memory
- In addition to holding instructions RAM is also a
workspace, a transient storage repository. - space must also me made available for
- Operating System Code
- Operating System Data
- User Program Code
- User Program Data
- Video Storage Space
- And so-forth
14Imagine
- Loading Microsoft Windows
- Microsoft Internet Explorer
- An email Application
- Microsoft Word
- And Listening to Music whilst you do all that
multi-tasking!
It doesnt stop there. You need memory for your
hardware. For example you require memory to
display images on your monitor
15Memory
- RAM is very quick, however it is very small.
- Each time a PROCESS starts it REQUESTS an amount
of RAM - The amount of total RAM requested is far too
great in comparison to the amount of Physical RAM
available in Multiprogramming Operating Systems
16Virtual Memory
- The Operating System has a Memory Management Unit
MMU that translates virtual addresses to physical
addresses in RAM. - This is known as Address Translation
17Swapping
- When a running program references an address of a
page which is not resident in RAM, the page has
to be located in secondary storage and loaded
into RAM. - If RAM is full the resident page has to be
swapped out to create space for the new page - This is know as SWAPPING
18Swapping
- Whenever the system requires a component that is
currently residing in Virtual Memory rather than
in physical RAM the MMU determines which item or
items in RAM are not being used at present and
moves them to the hard disk virtual memory and
loads the needed component into the just vacated
physical RAM.
19Question
- What is swapped in and out of RAM ?
Answer PAGES
20Principal Problems to be Handled by the MMU
- To provide memory space to enable several
processes to be executed at the same time - To provide a satisfactory level of performance
for the users - To protect each process from each other
- Where desired, to enable sharing of memory space
between processes - To make addressing of memory space as transparent
as possible for the programmer
21Question
- Can several processes be executed at the same
time?
22The Operating System
- Virtual Memory is mapped by the Operating System
to physical memory - This mapping is performed in chunks, called
pages, which are usually 4K each - This mapping is performed with help from the
hardware -- the CPU has built in support for
virtual memory to physical memory address
mappings.
23Memory Mapping
- It's this mapping that lets processes run in
isolated memory spaces, so as to not interfere
with other processes. - This whole scheme was introduced in Intel CPUs
with Intel 286/386 processors, and it's called
Protected Mode.
24Virtual Memory
- This virtual memory to physical memory address
mapping lets the operating system pretend that
there is more memory available than actual
physical memory in the machine.
25Question
Virtual Memory is space on the hard drive that is
mapped out and used to supplement the physical
RAM memory installed in the computer.
26(No Transcript)
27Page File
- The area of the hard disk that stores the RAM
image is called a page file. It holds pages of
RAM on the hard disk, and the Operating System
moves data back and forth between the page file
and RAM. - Previous versions of Windows called this a swap
file and had a .SWP extension.
28Key Points about Virtual RAM
- The key fact to remember about virtual memory is
that it exists to compensate for the lack of
physical RAM. Â Therefore the relationship between
them is an inverse one - More physical RAM means a reduced need for
virtual memory - Reducing the amount of physical RAM will mean an
increased need for virtual memory.
29Thrashing
- Hard Disks are incredibly slow in comparison to
RAM - When there is a limited amount of RAM, Virtual
Memory is accessed very frequently and this
causes Thrashing - Thrashing is the Operating System constantly
swapping PAGES back and forth between RAM and the
hard disk. - Thrashing slows down your computer considerably.
30Total Size of the Page File
- The size of the page file is based on how much
RAM is installed in the computer. - By default, Windows XP creates a page file which
is 1.5 times the amount of installed RAM - The page file is placed on the hard drive in the
same folder as XP
31Page Faults
- Only those parts of the program and data that are
currently in active use need to be held in
physical RAM. Other parts are then held in a page
file - When a program tries to access some address that
is not currently in physical RAM, it generates an
interrupt, called a Page Fault. - This asks the system to retrieve the page
containing the address from the page file - This a valid page fault normally happens
quite invisibly. If there is pressure on space in
RAM, then parts of code and data that are not
currently needed can be paged out in order to
make room
32Question
The Kernel remains resident in RAM, This is never
paged out.
33Invalid Page Faults
- Sometimes, through program or hardware error, the
page is not there. - The system then has an Invalid Page Fault
error. - This will be a fatal error if detected in a
program - The Application is normally shut down by the
Operating System
34Improving Performance
- The page file is a reserved section of the hard
drive where data may be written and retrieved as
needed. Since the paging file and operating
system files are by default located on the same
drive, parallel access to both locations is
impossible. One or the other has to wait, slowing
down overall system performance. Moving the
page file to another drive will improve
performance.
35Question
- How else could you improve performance?
Installing more RAM
36Memory Management in Windows
- Processes
- Processes
- Memory Usage
- Virtual Memory Usage
- Performance
- Commit Charge
- Physical Memory
- Kernel Memory
37Windows Task Manager
Virtual Memory Usage
Process Name
Physical Memory Usage
Each Process has a Virtual Amount of memory Limit
of 4GB
38Physical Memory
Commit Charge
Kernel Memory
39Question
The scattering of parts of a file throughout a
disk, eg when the operating system breaks up the
file and fits it into the spaces left vacant by
previously deleted files.
40Non-Contiguous Page Files
- Paging files are normally created when a drive is
relatively empty and finding a large contiguous
block of space is not a problem. - A page file is dynamic by default, it can be
expanded and contracted depending on the amount
of extra virtual memory that's needed. - If the initial block of drive space that was
allocated at setup becomes surrounded by
additional files that have been saved to the
drive, a split page file can occur when the
operating system expands it past the initial
size.
41Question
- How do you defragment files?
Windows comes with a utility called Disk
Defragmenter which will reorganise the files
stored on disk
42Question
- What creates the Page File?
- The CPU
- The RAM
- The Operating System
- Its created by magic
43What is loaded in RAM?
- The Non-Paged area. Parts of the System which are
so important that they may never be paged out -
the area of RAM used for these in XP is called
the Non-Paged area. This mainly contains core
code of the system. - The Page Pool which can be used to hold
- Program code,
- Data pages that have had actual data written to
them - A basic amount of space for the file cache (known
in Windows 9x systems as Vcache) of files that
have recently been read from or written to hard
disk. - Any remaining RAM will be used to make the file
cache larger.
44Splitting the Memory
- This Virtual address space is split up into
chunks, commonly 4K in size, called pages. - The physical memory is also split up into chunks,
also commonly 4K in size, called frames
45Page Table
- A page table is the data structure used by a
virtual memory system in a computer operating
system to store the mapping between virtual
addresses and physical addresses - The page table is stored in physical RAM
46Addressing
- How addressing works will be looked at in future
Lectures
47So What do we Know?
- RAM is Limited
- Virtual Memory gives the impression that there is
more RAM than Physical RAM - Every Process and Device requires RAM
- The Kernel is never Paged Out
- Paging is Managed by the MMU
- Page Faults are normal interrupts
- Invalid Page Faults are bad
- How to view Memory Allocation and Resources in
Windows
48Any Questions?