Multiprocessing Memory Management

22
Multiprocessing Memory Management • Partitioning • Relocation • Fragmentation • Relocation • Virtual Memory • Swapping

description

Multiprocessing Memory Management. Partitioning Relocation Fragmentation Relocation Virtual Memory Swapping. Partitioning. Every process including OS needs its own part of memory Memory partitioning: One partition per process static (fixed) vs. dynamic partitioning - PowerPoint PPT Presentation

Transcript of Multiprocessing Memory Management

Multiprocessing Memory Management

• Partitioning • Relocation• Fragmentation• Relocation• Virtual Memory• Swapping

Partitioning• Every process including OS needs its own part

of memory• Memory partitioning: One partition per

process – static (fixed) vs. dynamic partitioning– static disadvantage: waste, large programs can’t

run

• Relocation: After assigning a partition to a process you have to adjust all addresses in the program

• Security: Every process has only access to its own memory – Bounds register

Fixed Partition Example

Swapping

• Example: multiprocessing environment and a round robin scheduling

• 2 big processes to execute that need partition 3– either only allow one of them in the ready queue– or whenever you start the next process you have

to liberate partition 3 to make room for the next one

• “Swapping”: moving of memory content from and to disk as processes switch

• Can be very expensive

Dynamic Partitioning

• No fixed size partition• Before a process starts running it

allocates as much memory as it needs• You waste less memory, instead of waiting

for partition 3, the second big process can have a combination of 1 and 2.

• Same problem with swapping as before if the total size of all processes is bigger than total memory

• Additional Problem: Fragmentation

Round Robin and Swapping

Fragmentation

Process A

Process B

Process C

Free

Process D

Process E

Process F

Free

Free

Free

A FinishesD startsB FinishesE startsC FinishesF starts

What about G?

G

Fragmentation continued• Happens in all forms of memory that

you can alter (RAM, disk …)• Hard drive solution: instead of

looking for a block that is big enough you start saving and if you run into some used part you leave a link to the nextB C D

B A_1 C A_2 D A_rest

Fragmentation

• Problem of piecewise storage: slow access

• More general solution: Rearrange memory content from time to time

B C D

B C D

Virtual Memory

• Motivation– More flexibility with memory partitioning– Independence of Physical memory size

and address space• physical memory (RAM) can be smaller than

the total memory requirement of a process• address space is limited (bus size and ISA)

than physical memory

• Address is not a real physical address but has to be translated

VM Example: Less physical memory than

needed• RAM: 32K with address size is 15 bit• Job needs 64 K (“virtual” address size is 16 bit)• You could store half in RAM and second half on

hard drive• You need data from 0010000000000100

– Determine: Is this location in RAM or on hard drive?

– If RAM: find corresponding physical address and read

– If hard drive: Load other half into RAM (done by OS), find corresponding physical address and read

VM: Technical Solution

• Instead of taking half’s you make smaller slices called pages

• Page table keeps track which page is in physical memory and where

• OS loads and stores pages from disk into physical memory (RAM) if a page miss happens

• Address translation in Memory Management Unit (MMU)– each virtual address gets translated into a

physical one

Memory access

Page Table

Task:

Virtual address is: 0010000000000100

How do you find correct entry in page table?How do you find the correct corresponding address?

Simple Address translation

Some address size computation:

• Virtual address size: 16• Physical address size: 15• Table size: 16 entries

– address size for table = 4

• Page size: 4K– How many bit do you need to

find something within the page: 12

• Number of pages in RAM: 8– You need 3 bit to find page

Example

• Virtual Address: 0010000000000100• Split address:

– first 4 bit: 0010 = address in page table– last 12 bit: 000000000100 = page offset

• Look up physical page address in page table at address 0010 (entry 2): 110

• Recombine physical page address and page offset to physical address:– 110000000000100

More Examples• Convert the following virtual

addresses given the page table:011011111100010010010010

Questions:• How big is physical

memory?• How big is a page?• How many pages are in

physical memory?

00 000 001 100 100 000 010 100 000 011 100 000 000 000 000 000 0

1514131211109876543210

Solutions• 16 entries in page table = 4 bit of

virtual address to locate page will be replaces by 2 bit (content of page table)– Physical address has 6 bit, size= 26

• virtual address was 8 bit of which 4 were for page table: 4 bit remaining for page offset– Page size = 16

• 4 pages in physical memory

01101111=11111111000100=00010010010010=100010

Page replacement strategy

• If process requests an address that is not in physical memory the present bit in page table is 0– OS interrupt: read page that contains that address

into physical memory and save one old page to disk

• Very similar to cache • Objective:

– Keep pages that are likely to be used again– Minimize computational overhead

• Strategies:– Least recently used– Oldest

What has to be done in case of page replacement?

• Write old page from physical memory to disk

• Load new page into physical memory• Update page table:

– Set present bit of old page to 0– Insert physical page address in table

at position given by first 4 bits of virtual address

Example of Table Update

You request address: 00110111

This results a page missAssume page 13 (01) is

the least used

00 000 001 000 100 000 010 100 000 011 100 000 001 000 000 000 0

1514131211109876543210

00 000 001 100 100 000 010 100 000 011 100 000 000 000 000 000 0

1514131211109876543210

Virtual Memory Summary

• Allow programs to run with some of their pages missing

• Hardware generates an interrupt if page table entry is missing (add column(s)to page table for missing entry)

• External page table used to locate page on disk• Page paged in, and instruction re-executed• Can now run programs larger than physical

memory• Programmers (usually) do not need to know

size of real memory.