Docsity

Understanding Virtual Memory: Paging and Segmentation, Slides of Operating Systems

Toggle sidebar
bg1
Virtual Memory
–Early computers had a small and fixed amount to memory.
•All programs had to be able to fit in this memory.
•Overlays were used when the program was to big.
•The programmer was responsible for bringing in the overlays and
managing the overlay process.
•In 1961, researchers at Manchester, England proposed a technique
for automating the overlay process, relieving the programmer of
this job. This method is now known as virtual memory.
•By the early 1970s, it was available on most computers.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a

Partial preview of the text

Download Understanding Virtual Memory: Paging and Segmentation and more Slides Operating Systems in PDF only on Docsity!

Virtual Memory

  • Early computers had a small and fixed amount to memory.
    • All programs had to be able to fit in this memory.
    • Overlays were used when the program was to big.
    • The programmer was responsible for bringing in the overlays and managing the overlay process.
    • In 1961, researchers at Manchester, England proposed a technique for automating the overlay process, relieving the programmer of this job. This method is now known as virtual memory.
    • By the early 1970s, it was available on most computers.

Paging

  • The idea of the Manchester group was to separate

the concepts of address space and memory

locations.

  • The number of addressable words depends only on the number of bits used in the address, not on the amount of physical memory.
  • The address space is the set of all possible addresses.
  • At any one time, only a subset of the addresses in the address space are actually in physical memory, the other addresses are on secondary storage. A mapping shows where any address actually resides.

Paging

  • This technique is called paging and the chunks of

memory read in from disk are called pages.

  • A more sophisticated way of mapping addresses

from the address space onto actual memory

addresses is also possible.

  • A memory map or page table relates virtual addresses to physical addresses.
  • We presume that there is enough room on disk to store the entire virtual address space.
  • Programs are written as if the entire virtual address space is available.

Paging

  • Paging gives the programmer the illusion of a

large, continuous, linear main memory, the same

size as the virtual address space.

  • In reality, the physical memory may be smaller (or

larger) than the virtual address space.

  • The paging mechanism is transparent to the

programmer.

Implementation of Paging

  • Every computer with virtual memory has a device

for doing the virtual-to-physical mapping.

  • This device is called the MMU ( Memory

Management Unit ).

  • It may be on the CPU chip, or it may be on a separate chip that works closely with the CPU chip.
  • Since our sample MMU maps from a 32-bit virtual address to a 15-bit physical address, it needs a 32-bit input register and a 15-bit output register.

Implementation of Paging

  • On the following slide, the MMU is presented with

a 32-bit virtual address.

  • It separates the address into a 20-bit virtual page

number and a 12-bit offset within the page

(because the pages are 4K).

  • The virtual page number is used as an index into the page table to find the entry for the page referenced.
  • In the example, the virtual page number is 3, so entry 3 of the page table is selected, as shown.
  • The first thing the MMU does is check to see if the

page referenced is in main memory.

Implementation of Paging

  • Not all virtual pages can be in memory at once.
  • The MMU makes this check by examining the present/absent bit in the page table entry.
  • In the example, the bit is 1, meaning the page is currently in memory.
  • Now, the page frame value from the selected entry (6 in this case) is copied into the upper 3 bits of the 15-bit output register.
  • In parallel with this operation, the low-order 12-bits of the virtual address (the page offset field) are copied into the low-order 12 bits of the output register.

Implementation of Paging

Demand Paging and the Working Set

Model

  • When a reference is made to a page not present in

main memory, it is called a page fault.

  • After a page fault has occurred, it is necessary for the OS to read in the required page from the disk, enter its new physical memory location in the page table, and then repeat the instruction that caused the fault.
  • In this way, we can start a program running on a machine with virtual memory even when none of the program is in main memory.
  • This method of operating a virtual memory is

known as demand paging.

Demand Paging and the Working Set

Model

  • An alternative approach is based on the

observation that most programs do not reference

their address space uniformly but that the

references tend to cluster on a small number of

pages.

  • At any instant in time, there exists a set consisting

of all the pages used by the k most recent

memory references.

  • This set is called the working set of the program

and can be loaded when the program is restarted.

Page Replacement Policy

Page Size and Fragmentation

  • If the user’s program and data happen to fill an

integral number of pages exactly, there will be no

wasted space when they are in memory.

  • If not, there will be wasted space on the last page.
  • This is called internal fragmentation (because the wasted space is internal to some page).
  • A small page size means less internal fragmentation.
  • On the other hand, this requires a larger page table and more page faults.
  • Small page sizes also make inefficient use of the disk bandwidth.

Segmentation

Segmentation

  • One solution to this problem is to provide many

completely independent address spaces, called

segments.

  • Different segments may, and usually do, have different lengths.
  • A segment is a logical entity which the programmer is aware of and uses as a single logical entity.
  • It usually does not contain a mixture of different types.
  • Segments can also be used for each procedure.