14
Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com , or www.amazon.com

Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Embed Size (px)

Citation preview

Page 1: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Operating System Concepts and

Techniques Lecture 8

Memory Management-1

M. Naghibzadeh

ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011.

To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com

Page 2: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Memory Management (MM)

Memory management policies and techniques have tremendously changed throughout the years

The simplest being single contiguous partition memory management

The most complex being multilevel-page table virtual memory with cache

A Brief list follows

2

Page 3: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

A Brief list of MM policies

Old policies Single contiguous partition MM

Static partition MM

Dynamic partition MM

Multiple partition MM

Middle age policies Segmentation MM

Relocatable partition MM

Page (non-virtual memory) MM

Virtual memory policies Page-based virtual memory MM

Multilevel page table page-based virtual memory MM

3

Page 4: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Single contiguous partition MM

MM is divided into two partsOne part for operating system

The other is called user memorySo simple that there is no MM subsystem,

loader takes care of itMake sure user program does not destroy OS

Many disadvantagesSupports only single-programming

System utilization is very lowWaste of memory for small programs

A program larger than the user’s main memory will not be able to run

4

Page 5: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Static Partition MMMore than one user partition with fixed sizes

Sizes are different to reduce memory waste and accept larger programs

Make sure user programs do not interfere and do not destroy OS

Number of partitions determines degree of multiprogramming

AdvantagesSimple to implement; a table for partitions information

Multiprogramming is possiblethe size of runable programs limited to the largest partition size

Memory wasteA program larger than users main memory will not be able to

run

5

Page 6: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Dynamic Partition MMMore than one user partition with variable sizes

Sizes are different to reduce memory waste and accept larger programs

Make sure user programs do not interfere and do not destroy OS

Number of partitions determines the degree of multiprogramming

At start there is only one big free partitionWhen new programs are accepted new partitions are created

Upon program completion free neighbor partitions can join

AdvantagesSimple to implement; two tables, free and allocated partitions

Multiprogramming is possibleThe size of a runable programs limited to the size of user memoryA program larger than users main memory will not be able to run

6

Page 7: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Dynamic Partition Memory waste

There is a smallest memory allocation unit, usually 1K bytes

A program which is 1025 bytes will be given 2K bytes, 1023 bytes are wasted in the form of

internal fragmentation

We are not allowed to relocate programsExternal fragmentation occurs when all free

memory partitions combined are large enough to load the coming program into,

but these spaces do not form a contiguous partition and each one cannot accept the

coming program

7

Page 8: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Dynamic Partition Memory waste…

The 50% rule: Without other information, on the average, the number of free partitions is

half the number of allocated partitions Remember: adjacent free partitions join, but

adjacent occupied partitions house different programs

Let C = (average free partition size)/(average program size), then

external fragmentation fraction=

8

2CC

Page 9: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Partition allocationFirst-Fit

Look at the free partitions data structure (not the main memory itself) and select the first which is as

large as the program

Next-Fit From partitions data structure, from where the

pointer points, select the first which is as large as the program

Best-Fit pick a qualified partition whose size is closest to the

size of the program

Worst-Fit Pick the largest free partition

9

Page 10: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Partition allocation- Buddy syatemThe size of a partition is 2i

*m

A partition size of 2i*K could split into two size 2i-1

*K which are called buddies

Remember that any two partition of size 2i*m are

not buddies even if they are adjacentA complete partition is given to a program

Remember partitions cannot start from any arbitrary address

A program the size of xK is given a partition of size 2i

*K, where 2i x and i is the smallest such integer

Any two free buddies have to merge

10

Page 11: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

Buddy system tree

11

512M

256M

128M

64M

32M

: Processed

: Allocated

: Available

Figure shows certain state of a small 512 Mega Bytes (MB) main memory. A black circle represents a partition that has been broken and no longer exists. Dark circles represent a partition that is occupied by a program. An unfilled circle represents a free (available) partition

Advantage: easy to find a partition for a programDisadvantage: Internal fragmentation increases

Page 12: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

SummaryThere are variety of memory management

The simplest, single contiguous memory management

The most complex, multilevel page table page-based virtual memory with segmentation and cache

memory

Older managements are good for special purpose computer such as embedded control systems and intelligent machinery electronics

This lecture introduced static and dynamic partition memory managements

Base register is a central concept to dynamic partition MM

12

Page 13: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

13

Find outWhat the degree of multiprogramming is in

your computerPractical systems which use single partition MM

If we can have a buddy system in which buddies are not the same size

In buddy system, why can’t any two adjacent partitions the size of 2i

*K, join to form a partition the size of 2i+1

*K

In what situations worst-fit will perform better than other partition selection algorithms

Page 14: Operating System Concepts and Techniques Lecture 8 Memory Management-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,

14

Any questions?