0% found this document useful (0 votes)
51 views

Chapter 8 - Main Memory - Part II

The document discusses the concepts of logical versus physical addresses, virtual address translation using page tables, and paging. It provides examples of how virtual addresses are translated to physical addresses through the use of a page table located in physical memory. Page tables contain the physical frame numbers and valid bits to map virtual pages to physical frames. When a page fault occurs, the operating system intervenes to locate the desired page from disk and update the page table.

Uploaded by

as ddada
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Chapter 8 - Main Memory - Part II

The document discusses the concepts of logical versus physical addresses, virtual address translation using page tables, and paging. It provides examples of how virtual addresses are translated to physical addresses through the use of a page table located in physical memory. Page tables contain the physical frame numbers and valid bits to map virtual pages to physical frames. When a page fault occurs, the operating system intervenes to locate the desired page from disk and update the page table.

Uploaded by

as ddada
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Chapter 8 – Main Memory – Part II

Abraham Silberschatz, Peter Baer Galvin, Greg Gagne,


Operating System Concepts, 9th Eds. Wiley – 2012.
Logical Versus Physical Address Space
An address generated by the CPU is commonly referred to as a logical
address.

Whereas an address seen by the memory unit—that is, the one loaded
into the memory-address register of the memory—is commonly referred
to as a physical address.

We usually refer to the logical address as a virtual address.

The run-time mapping from virtual to physical addresses is done by a


hardware device called the memory-management unit (MMU).
Logical Versus Physical Address Space

VIRTUAL ADDRESS TRANSLATION:


When translating a virtual-address to a physical-address we only deal
with the page number. The essence of the procedure is to take the page
number of the given address and look it up in the page-table to find
a pointer to a physical address, to which the offset from the virtual
address is added, giving the actual location in system memory.
https://www.bottomupcs.com/virtual_addresses.xhtml

• https://www.differencebtw.com/difference-between-logical-and-
physical-address-in-operating-system/
VIRTUAL
ADDRESS
TRANSLATION:

• https://www.bottomupcs.com/virtual_addresses.xhtml
Relocation Registers

Relocation is typically done by the linker at link time,


but it can also be done at load time by a relocating
loader, or at run time by the running program itself.
Some architectures avoid relocation entirely.

https://en.wikipedia.org/wiki/Relocation_(computing)#64-bit_Windows

Relocation is the process of assigning load addresses


to position-dependent, but locatable code of a program and adjusting the Memory-Management Unit (MMU)
code and data in the program to reflect the assigned addresses [1][2].

https://en.wikipedia.org/wiki/Relocation_(computing)#64-bit_Windows
Memory Protection

In paging the memory address space is


divided into equal-sized blocks called pages.
Using virtual memory hardware, each page
can reside in any location of the computer's
physical memory, or be flagged as being protected.
Virtual memory makes it possible to have a
linear virtual memory address space and to
use it to access blocks fragmented over physical
memory address space. https://en.wikipedia.org/wiki/Memory_protection
Segmentation

Memory segmentation is the division of a computer's


primary memory into segments or sections.
In a computer system using segmentation,
a reference to a memory location includes a
value that identifies a segment and an offset
(memory location) within that segment.

https://en.wikipedia.org/wiki/Memory_segmentation

Segmentation with paging Instead of an actual


memory location the segment information
includes the address of a page table for the segment.
When a program references a memory location
the offset is translated to a memory address
using the page table. A segment can be extended
simply by allocating another memory page and
adding it to the segment's page table.

https://en.wikipedia.org/wiki/Memory_segmentation#Segmentation_with_paging
Example of
Segmentation
Because segmented memory is allocated
in non-uniform chunks it has the problem
of “fragmentation”. If you keep allocating
and deallocating memory chunks of
different sized then eventually between
two adjacent chunks of memory you will
start building up small pieces of memory –
these pieces are very small and usually
not worth allocating on their own but
collectively they start occupying a larger
and larger amount of the overall memory.
If the OS utilizes these small chunks there
starts to get a huge number of segments
allocated to a process (since each chunk
is very small) and this leads to inefficiency. Because the more overall physical segments
there are the more work the OS has to do. Paged memory is free from that high level fragmentation
because each chunk of memory is the same size. The only fragmentation is the internal fragmentation
at the end of the last page which is unutilized. But that is not a big problem because it does not get bigger
over time. https://www.quora.com/What-is-the-difference-between-paging-and-segment-in-memory-management
Segmentation
with Paging
1. The Translation Lookaside buffer is
located in the MMU.

2. The segment table is located in the


MMU.

3. The Page Table is located in the RAM


and is cached in the Translation
Lookaside buffer. However, the location
depends on computer architectures.

4. The relocation registers are located


In the MMU.

• http://www.cs.jhu.edu/~yairamir/cs418/os5/sld043.htm
How Paging Works: Access of Data
at the Given Virtual Address

Steps:

1. Extract the page number from the virtual address.

2. Extract the offset from the virtual address.


How Paging Works: Access of Data
at the Given Virtual Address
3. Translate the page number into a physical page frame
number by accessing the page table.

• A. Look up the page number in the page table.

• B. Check the valid bit for that page.

B1. If the valid bit is 0, there is a page fault and


the OS intervenes to:
How Paging Works: Access of Data
at the Given Virtual Address
B1.a  Locate the desired page in the disk.

B1.b  Find a free page frame (this may necessitate


removing a page and copying it back to the disk if the memory is full).

B1.c  Copy the desired page into the free page frame in main memory.

B1.d  Update the page table (the virtual page just brought in must have its
frame number and valid bit modified.

B1.e  Resume execution (go to B2).


How Paging Works: Access of Data
at the Given Virtual Address
B2. If the valid bit is 1, then the page is in memory.

B2.a  Replace the virtual page number with the actual frame
number.

B2.b  Access data at offset in physical page frame by


adding the offset to the frame number for the given virtual page.
Current State Using Paging and the
Associated Page Table
Virtual
Memory Page
0 0 Frame # Valid Bit
0 2 1
1 1 1 - 0
2 2 2 - 0
3 0 1
3 3
4 1 1
4 5 - 0
Physical
6 - 0
5 Memory
7 3 1
6 Page Table:
7 Located in Main Memory
(Physical Memory)
8-bit Virtual Address

3 bits 5 bits

Page Offset

8 bits
8-bit Virtual Address: Paging
Page Virtual Address: 000011012 = 1310
Frame # Valid Bit 3 bits 5 bits
0 2 1
1 - 0 000 01101
2 - 0
3 0 1
8 bits
4 1 1
5 - 0 Physical Address: 010011012 = 7710
6 - 0
3 bits 5 bits
7 3 1
Page Table: 010 01101
Located in Main
Memory (Physical
8 bits
Memory)
A Small Memory Example Using
Paging
Page Frame Valid Bit Virtual Address 1010 = 10102
0 2 1
Page Table: Located in 1 0 1 101 0
Main Memory 2 - 0 Page 5 Offset 0
(Physical Memory) 3 1 1
4 - 0
Physical Address
5 3 1
6 - 0 011 0
7 - 0
Page 3 Offset 0
Making VM
work:
Translation

• https://www.youtube.com/watch?v=59rEMnKWoS4
Paging

A page fault is a type of exception raised by computer hardware


when a running program accesses a memory page that is not
currently mapped by the memory management unit (MMU)
into the virtual address space of a process. Logically, the page
may be accessible to the process, but requires a mapping to
be added to the process page tables, and may additionally
require the actual page contents to be loaded from a backing
store such as a disk.

https://en.wikipedia.org/wiki/Page_fault

You might also like