0% found this document useful (0 votes)
6 views4 pages

Lecture 21 Virtual Memory

Virtual memory is a technique that uses main memory as a cache for secondary storage, allowing virtual pages to be mapped to physical pages. Each program has its own page table that contains mappings from virtual addresses to physical addresses, facilitating address translation. When a virtual page is not found in physical memory, a page fault occurs, prompting the system to retrieve the page from disk storage.

Uploaded by

Shibly Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Lecture 21 Virtual Memory

Virtual memory is a technique that uses main memory as a cache for secondary storage, allowing virtual pages to be mapped to physical pages. Each program has its own page table that contains mappings from virtual addresses to physical addresses, facilitating address translation. When a virtual page is not found in physical memory, a page fault occurs, prompting the system to retrieve the page from disk storage.

Uploaded by

Shibly Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Virtual memory

A technique that uses main memory


as a “cache” for secondary storage.
Virtual Memory Virtual address
-Both the virtual memory An address that corresponds to a
and the physical memory Virtual addresses Physical addresses
location in virtual space. The
are broken into pages, so
Virtual addresses Physical addresses
Address translation processor produces a virtual address
that a virtual page is Physical address
mapped to a physical An address in main memory.
page. - A virtual memory block is called a
page, and a virtual memory miss is
-Of course, it is also
called a page fault.
possible for a virtual page - With virtual memory, the
to be absent from main processor produces a virtual
memory and not be address, which is translated by a
Disk addresses

combination of hardware and


mapped to a physical
software to a physical address, which
address; in that case, the in turn can be used to access main
page resides on disk. Virtual address
Virtual address
memory.
-Physical pages can be 31 30 29 28 27 15 14 13 12 11 10 9 8 3210 - The top Figure shows the virtually
addressed memory with pages
shared by having two Virtual page number Page offset
mapped to main memory. This
virtual addresses point to process is called address mapping
the same physical Translation
or address translation.
address. 29 28 27 15 14 13 12 11 10 9 8 3210

Physical page number Page offset

Physical address

FIG. 5.25 (Bottom) Mapping from a virtual to a physical address: The page size both for physical & virtual memory is
212 = 4 KB since 12 bits for offset. The number of physical pages allowed in memory is 218, since the physical page number
has 18 bits in it. Thus, main memory can have at most 1 GB (230), while the virtual address space is 4 GB (232).
Virtual memory addressing: page tables
Page table:
Page table
-The• page table
Library containing
analogy: the card thecatalog
virtual to physical address translations in a
virtual memoryall
• Indexing system.
pages in virtual memory
-Page• Each
table,program
which ishas stored
its ownin page
memory,tableis typically indexed by the virtual
page• number;
OS creates each entry
disk space in the table
for all the contains
pages of the physical
every processpage number for
that virtual pageofif athe
• The state page isiscurrently
process specifiedinbymemory.
the page table, PC and registers
• Active and
-To indicate inactive processes
the location of the page(saving
table inand loadingthe
memory, page table register,
hardware includes
PC and the other registers)
a register that points to the start of the page table; we call this the page table
register.
Page table entries
-Each program has its own page table.
• Physical page or disk address
-OS•creates disk space for all the pages of every process.
Tag is not necessary (the index specifies the page address)
• Validthe
-Because page
bit: 1 - thetable
page contains a mapping
is in memory; for every
0 - the page possible virtual
is on disk
page, no tags are
• Reference required.
(use) bit: LRU scheme for replacing pages
• Dirty bit ( the page has been written): write-back scheme
• Information for the process using the page (memory protection)

Example
• 32-bit virtual address, 4KB page, 4 byte entry - 4MB for a page table
• 250 processes X 4MB = 1GB !
• Reducing the page table size
Virtual memory addressing: address translation

Page table register


FIGURE 5.26 The page table is
Page table: Virtual address
indexed with the virtual page
-The page table containing the virtual 31 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
number to obtain the
to physical address translations in a Virtual page number Page offset corresponding portion of the
virtual memory system. 20 12 physical address.
-Page table, which is stored in Valid Physical page number -We assume a 32-bit virtual
memory, is typically indexed by the address. The page table pointer
virtual page number; each entry in the gives the starting address of the
table contains the physical page page table. In this figure, the page
number for that virtual page if the
page is currently in memory. Page table
size is 212 bytes, or 4 KB. The
-To indicate the location of the page virtual address space is 232 bytes,
table in memory, the hardware or 4 GB, and the physical address
includes a register that points to the
space is 230 bytes, which allows
start of the page table; we call this the 18
If 0 then page is notı main memory of up to 1 GB.
page table register.
-The number of entries in the page
present in memory

-Each program has its own page


table is 220 (1 million entries). The
29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
table.
-OS creates disk space for all the
Physical page number Page offset
valid bit for each entry indicates
pages of every process. Physical address whether the mapping is legitimate.
-Because the page table If it is off, then the page is not
contains a mapping for every present in memory. The page table
possible virtual page, no tags entry shown here need only be 19
are required. bits wide.
Handling page faults

Virtual pageı
number
Page table
Physical memory
Physical page orı
Valid disk address
Virtual page

1
1
1
1
0
1
1
0
1 Disk storage
1
0
1

FIGURE 5.27 The page table


• Transfer themaps eachto
control pageOSinby
virtual
usingmemory to either a mechanism
the exception page in main memory or a page
stored on disk, which is the next level in the hierarchy.
• Read
-The virtual page numberthe page
is used to from disk
index the page table. If the valid bit is on, the page table supplies the physical
• Determine
page number (i.e., the starting which
addresspage
of the in memory
page in memory)to replace (LRU)
corresponding to the virtual page. If the valid bit is
off, the page currently
• Writeresides
backonly on disk,
to disk theat replaced
a specified disk
page address.
(if its dirty bit is on)
-In many systems, the table of physical page addresses and disk page addresses, while logically one table, is stored
• Write the physical address in the page table entry
in two separate data structures. Dual tables are justified in part because we must keep the disk addresses of all the
pages, even if they are currently in main memory. Remember that the pages in main memory and the pages on disk
are the same size.

You might also like