Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September...

21
Wednesday, 29 September 2010 CHAPTER 7 1 Fall 2010 - DE5 Memory Management M t d di g t f ti g t Most demanding aspect of an operating system Cost has dropped. Consequently size of main memory has expanded enormously. Can we say that we have enough still. Swapping in/out. Memory I/O still slow compared with the speed of processors. Dr. D. M. Akbar Dr. D. M. Akbar Hussain Hussain Department of Electronic Systems Department of Electronic Systems DE5 1 Memory Management What happens when a program starts ? It uses memory in two ways: Procedure Calls Dynamic Data Types Dr. D. M. Akbar Dr. D. M. Akbar Hussain Hussain Department of Electronic Systems Department of Electronic Systems DE5 2

Transcript of Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September...

Page 1: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

1Fall 2010 - DE5

Memory Management

M t d di g t f ti g tMost demanding aspect of an operating system

Cost has dropped. Consequently size of main memory has expanded enormously. Can we say that we have enough still. Swapping in/out. Memory I/O still slow compared with the speed of processors.

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 1

Memory Management

What happens when a program starts ?

It uses memory in two ways:

Procedure Calls

Dynamic Data Types

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 2

Page 2: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

2Fall 2010 - DE5

Used Free Used Free Used

0 1 2 3 4 5 6 7 8 9 10 11

Memory Management

0 1 2 3 4 5 6 7 8 9 10 11

U 0 3 F 3 2 U 5 2

F 7 3U 10 2

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 3

U 0 3

F 3 2

U 10 2

F 7 3

U 5 2

UniUni Programming SystemProgramming System

Kernel

Memory Management

Program (user) Just one large area

Multi Programming SystemMulti Programming System

Kernel

Program (user)

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 4

Program (user) The large area is sliced/sub-divided further dynamically to have

more then one program active (not suspended) in the mainmemory; which is basically memory management.

Page 3: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

3Fall 2010 - DE5

Memory Management

1. Relocation2. Protection3. Sharing4. Logical Organization5. Physical Organization

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 5

Chief responsibility of a MMS (Memory Management System) is tobring/putbring/put processesprocesses inin andand outout ofof mainmain memorymemory forfor thethe executionexecution

Memory Management

bring/putbring/put processesprocesses inin andand outout ofof mainmain memorymemory forfor thethe executionexecutionby the processor.

How that is achieved and from where to get the processes, obviously, someplace similar to main memory.

Basically two schemes are used:

PagingPaging

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 6

PagingPaging SegmentationSegmentation

Page 4: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

4Fall 2010 - DE5

1.1. Fixed partitioningFixed partitioning

Memory Management Schemes

2.2. Dynamic PartitioningDynamic Partitioning

3.3. Simple PagingSimple Paging

4.4. Simple SegmentationSimple Segmentation

55 Virtual Memory PagingVirtual Memory Paging

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 7

5.5. Virtual Memory PagingVirtual Memory Paging

6.6. Virtual Memory Segmentation Virtual Memory Segmentation

Techniques Description Strengths Weaknesses

Fixed Partitioning

Main memory is divided into a number of static partitions at system generation time. A process may be loaded into a partition of equal or greater size.

Simple to implement, small o/s overhead

Inefficient usage of memory (internal fragmentation)internal fragmentation), fixed number of active processes

Dynamic Partitions are created dynamically so that each Efficient usage of memory no Inefficient usage ofInefficient usage of

Memory Management Schemes

Dynamic Partitioning

Partitions are created dynamically, so that each process is loaded into a partition of exactly the same size as that process.

Efficient usage of memory, no internal fragmentation

Inefficient usage of Inefficient usage of processor processor to counter external fragmentation.external fragmentation.

Simple Paging Main memory is divided into a number of equal size frames. Each process is divided into equal size pages of the same size as frames. Process is loaded by putting all the pages into available but not necessarily contiguous frames.

No external fragmentation Small internal Small internal fragmentation.fragmentation.

Simple Segmentation

Each process is divided into number of segments. A process is loaded by putting all of its segments into dynamically created partitions not necessarily contiguous.

No internal fragmentation External fragmentation, External fragmentation, better then dynamic partitioning

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 8

Virtual Memory Paging

Similar to simple paging, except not necessary to load all pages of a process, non resident pages can be loaded when required during execution.

No external fragmentation, large virtual address space, higher degrees of multi programming

Over head due to Over head due to complexity of MM.complexity of MM.

Virtual Memory Segmentation

Similar to simple segmentation, except not necessary to load all segments of a process, non resident segments can be loaded when required during execution.

No internal fragmentation, large virtual address space, higher degrees of multi programming, protection and sharing support

Same aboveSame above

Page 5: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

5Fall 2010 - DE5

Equal & Unequal Partitioning:Equal & Unequal Partitioning:

Issues with Fixed Partitioning

Equal size set will produce internal fragmentation. For fixed equal size scheme any partition can be used by the process. Unequal scheme may have better usage of memory. Both can have fixed number of processes in the memory. A program may be bigger compared with a partition, programmer must design

overlays scheme to bring in the relative part of the process. Smaller jobs can make system inefficient. In general this is not a useful system in terms of memory usage. When required which

process to swap out ?

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 9

process to swap out ?

Operating Operating SystemSystem

Operating Operating SystemSystem

Queue Scheme for Un-Equal Partition

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 10

Page 6: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

6Fall 2010 - DE5

To overcome the inefficient usage of memory Dynamic partitioning scheme was developed; meaning use as much as you required.

Operating 10M10M10M

Operating 10M

Operating 10M

Operating S

10M

Dynamic Partitioning

System

P 115M

10M10M10M

60 M60 M

gSystem

10M

60 M

gSystem

P1

P225 M

15M

10M

25 M

System

P1

P2

15 M

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 11

P3 10M

It looks fine until ?

10MOperating Operating Operating Operating

Dynamic Partitioning Problem

10MSystem

P1

P2

P3

P4

P5

System

P1

P2

P2

P4

System

P1

P2

P2

System

P2

P2

P0

This Process is to be loaded:

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 12

P5

P6

P4

P5 P5 P5

Page 7: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

7Fall 2010 - DE5

Compaction is not a very good idea; waste of CPU power

Operating system designers came up with several schemes to efficiently use the memory, question is:

Which is better

Placement Options for Dynamic Partitioning

First Fit (FF) Best Fit (BF) Next Fit (NF)

Simple & Fast Slowest Poor compared to FF

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 13

Front Loading

Frequent Compaction ?

Creates Small Holes

Frequent Compaction

Back end Loading

Frequent Fragmentation

It is really hard to put your finger on one of these techniques, basically it depends on the sequence of events.

Empty Occupied

8 M 15M 12 M 30 M

Example of BF, NF & FF

Last OccupiedLast Occupied

8 M 30 M

Next process is of 10 MNext process is of 10 M

10 M 10 M 10 MFF NF

15M 12 M

BF

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 14

With Dynamic replacement in a multi-programming system, at some point in time allthe processes will be in the blocked state and even with compaction there will not beenough space for new processes. TheThe o/so/s hashas toto swapswap oneone ofof thethe processesprocesses;;questionquestion isis whichwhich oneone ??

Page 8: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

8Fall 2010 - DE5

Buddy System

Fixed partition schemes suffers from the limitation of having fixedfixednumbernumber ofof activeactive (non(non suspended)suspended) processesprocesses and the usage of spacemay also not be optimal.

Dynamic partitioning as seen in our discussion is moremore complexcomplex tomaintain and compactioncompaction isis aa majormajor issueissue with it.

So what is the solution: aa buddybuddy systemsystem..

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 15

In buddy system, whole space is treated as one piece in the beginningtreated as one piece in the beginning, say 22UU..

Buddy System

Now suppose a size of ss is requested: if 2if 2UU--11<s <s 22UU

Allocate the whole block elseelse

Recursively divide the block equally & test the condition at each time; when it satisfies, allocate the block and get out of the loop.

System also keep the record of all the unun--allocated blocks (holes)allocated blocks (holes) each of size say ” ” ” ” d h diff i bl k k bi h k ( d

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 16

”a” ”a” and can merge these different size blocks to make one big chunk (see code on page 313).

Page 9: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

9Fall 2010 - DE5

Buddy System Example

if 2if 21010--1 1 < s < s 221010

AABBCCDD

EE

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 17

EE

Tree Representation of Buddy System

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 18

Buddy system provides reasonable solution compared with fixed and dynamicpartitioning techniques and has found applicable in most parallel systems. TheThe leafleafnodesnodes ofof treetree representationrepresentation showsshows thethe currentcurrent partitioningpartitioning ofof thethe memorymemoryand if two buddies are neighbor leaf nodes, so one can be allocated otherwise it shouldbebe coalescedcoalesced intointo biggerbigger blockblock.

Page 10: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

10Fall 2010 - DE5

Use of Buddy System

• The buddy system is known for its speedspeed andand simplicitysimplicity..

• Less Over Head.

• However, highhigh internalinternal andand externalexternal fragmentationfragmentation have made itunattractive for use in operating system file layout.

• Dartmouth Time-Sharing System (DTSS) uses this method

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 19

Dartmouth Time-Sharing System (DTSS) uses this method.

• LINUXLINUX also use Buddy Algorithm.

Initially, loaded processes have absolute references, whether occupying a contiguous block or non contiguous.

Relocation Issues

Compaction has to re-reference all the addresses.

Swapping of processes may not necessarily occur with the same partition initially assigned to that particular process.

Address DefinitionsAddress Definitions

Logical:Logical: It is independent of any current assignment of data memory.

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 20

Relative:Relative: As the name says, it is with respect to some known position.

Physical: Physical: Actual memory address allocated to a program/data etc.

Page 11: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

11Fall 2010 - DE5

Program Program

PCB

Process Image in Memory

DataData

Program Program

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 21

Stack

Object Code

Process Image in Main Memory

Library

Typical Loading Scenario

Module A

Module B

Lin

ke

r

Lo

ad

M

od

ul

e

Lo

ad

er

Process

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 22

Module Z

Page 12: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

12Fall 2010 - DE5

1. Programmer can hardcodehardcode thethe physicalphysical addressesaddresses in the program.

Loader Option for address Translation

g p yp y p g

2. Physical Addresses can be obtained at compilationcompilation timetime..

3. Another option is to ask compiler to generate relativerelative addressesaddresses andandtranslatetranslate themthem atat loadload timetime..

4. The last option is that loaderloader retainsretains thethe relativerelative addressesaddresses and they

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 23

are converted dynamically at run time by the processor hardware.

ProgramProgram TimeTime:: Programmer can put every sub-program and data referencesrequired in the program itself.

C ilC il TiTi A bl ll h f d b d d d

Linker Options

CompileCompile TimeTime:: Assembler get all the referenced sub-program and data andassemble them at compile time.

LoadLoad TimeTime:: References to external modules are not resolved until load time.Therefore, at load time all the required references are dynamically appended to theload module and loaded into the main memory.

RunRun TimeTime:: External References are not resolved until run time, therefore, when theexternal calls executed the processor is interrupted and the required module is linked.

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 24

LoadLoad ModuleModule CreationCreation:: Each individual modules are assembled usingrelative addresses. These modules are then re-referenced relative to theorigin of the final load module, this would not be true for program timecase.

Page 13: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

13Fall 2010 - DE5

Program always placed at the same memory location when ever loadedfor execution.

P h fi d ifi dd

Absolute Loading

Program has fixed specific addresses. Programmer or compiler can do the address translation.

ProgrammerProgrammer ChoiceChoice:: Each individual programmer has to know where to load the

program. Any change would mean re-referencing each address.

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 25

CompilerCompiler ChoiceChoice:: This has the advantage, it does not suffer from the above

limitations.

Program

Jump 1424

Absolute Addresses

Program

Jump x

Symbolic Addresses

Absolute Loading

Load 2224

Data

1424

Load y

Data

x

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 26

2224

Absolute Load Module

y

Object Module

Page 14: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

14Fall 2010 - DE5

Loading to a specific location limits the

Program

Jump 400

Relative Addresses

0

Re-Locatable Loading

Loading to a specific location limits thefunctionality, typically required in havingmultiple processes in the memory.

Compiler Produce addresses for a programrelative to the start of a program.

Job of the loader becomes simple.

Load 1200

Data

400

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 27

1200

Relative Load Module

Re-locatable loading has edge over absolute loading.

For m lti programming schemes process images are freq entl

Dynamic Run Time Loading

For multi-programming schemes process images are frequentlyswapped in and out of memory.

Re-locatable loading can not support swapping of images, as theaddresses are bounded absolutely at the initial time of loading.

Dynamic loading is very similar to re-locatable reference model butaddress translation is performed through the hardware.

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 28

p g

Dynamic loading provides swapping of processes.

Page 15: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

15Fall 2010 - DE5

PCB

ProgramBase Register

Relative Address

Dynamic Run Time Loading

g

Data

Base Register

Bound Register

Adder

ComparatorAbsolute Address

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 29

Stack

Process Image

Interrupt to o/s

Module A

CALL B

Return

Length LExternal Reference to

Module B

Relative Addresses

0Module A

Jump ”L”

Linking Scenario

Module B

CALL C

Return

Module C

Length M

Module C

L-1

L

L+M-1

L+M

Module B

Jump ”L+M”

Return

Return

External Reference to

Module C

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 30

Module C

Return

Length N

Object Module

ReturnL+M+N-1

Load Module

Page 16: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

16Fall 2010 - DE5

Process is broken into small equal pieces called pages.called pages.

Memory is divided into small pieces called framescalled frames, the size of frame is equal to that of page.

Frame Numbers Frame Numbers

Page

Pages of Process A

A3

A2

A1

A0

Pages of Process B

0

1

2

3

4

5

6

7 Memory

Frame Numbers

0

1

2

3

4

5

6

7

Frame Numbers

s A & B Loaded

B1

B0

A3

A2

A1

A0

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 31

B1

B0 8

9

10

11

7

8

9

10

11

Proces

Pages of Process A

A1

A0 0

1

Frame Numbers

0

1

Frame Numbers

edA1

A0

Page

A3

A2

B1

B0

Pages of Process B

1

2

3

4

5

6

7

8

9

Memory

2

3

4

5

6

7

8

9

Process A & B Loade

B1

B0

A3

A2

Pages of Process CC2

C1

C0

C5

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 32

10

11

10

11

C5

C4

C3

C2

C1

C0

C4

C3

Page 17: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

17Fall 2010 - DE5

Process A Page TableProcess A Page Table

3

2

1

00

1

2

3

Frame NumbersFrame Numbers

0 0

Frame NumbersFrame Numbers

A0

Data Structuring for Paging

8

7

Process B Page TableProcess B Page Table

0

1

Process C Page TableProcess C Page Table

11

10

90

1

2

Memory

Memory

1

2

3

4

5

6

7

8

910

0

1

2

3

4

5

6

7

8

9

10 ocess A & B Loaded

ocess A & B Loaded

B1

B0

A3

A2

A1

A0

C5

C1

C0

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 33

6

13

12

112

3

4

5

111213

10

11

12

13

Pro

Pro

C4

C3

C2

C1

5

4

Free FramesFree Frames

Consider this example, the page size is 1k (1024), 16 bit address is used, meaning 10 bits are needed for offset field (1k), leaving 6 bits for page number. This means a program can consist of a maximum 64 pages of 1k bytes. Suppose we have a logical address 1502

Relative address = 1502Relative address = 1502 Logical Address = page #, offset 478Logical Address = page #, offset 478

Paging Example

00000101110111100000010111011110

Pro

cess

Pro

cess

0 b

yte

s0

by

tes

000001 000001 01110111100111011110

# 1

# 1

Page # 0

Page # 0

478 478

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 34

Use

r P

Use

r P

2700

2700

PartitioningPartitioning

Page #

Page #

PagingPaging

Internal Internal FragmentationFragmentation

Page 18: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

18Fall 2010 - DE5

16 Bit Logical Address

6 Bit Page Number 10 Bit offset

Page Address Translation

Page Table

0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0

0 0 0 0 1 0 1

1 0 0 0 1 1 0

2 0 1 1 0 0 1

0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 35

16 Bit Physical Address

0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0

1. Similar to paging another option is to divide the program into segmentssegments of varying sizesbut should not exceed a maximummaximum segmentsegment sizesize.

2. It is similarsimilar toto dynamicdynamic partitioningpartitioning, the difference being that it is not necessary to load

Segmentation

the segmentssegments contiguouslycontiguously.

3. It eliminate internal fragmentation but dodo havehave externalexternal fragmentationfragmentation, however it isvery small.

4. In contrast to paging, segmentationsegmentation isis visiblevisible toto thethe useruser as it provides structuring ofdata and program. Typically, programmer or compiler assign segments for data andprogram.

5. Because of unequal size, addressaddress translationtranslation mechanismmechanism isis notnot simplesimple.

6 A simple segmentation scheme use a segmentationsegmentation tabletable for each process and a list of

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 36

6. A simple segmentation scheme use a segmentationsegmentation tabletable for each process and a list offree memory blocks, each table entry has a staring address in the main memory, length ofthe segment.

7. When a process is in running state, the address of its segment table is loaded into aspecialspecial registerregister used by the memory management hardware.

Page 19: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

19Fall 2010 - DE5

Logical Address = segment # 1 offset 752Logical Address = segment # 1 offset 752

0001 0001 001011110000001011110000

0 0 es

es

Segmentation

gm

en

t 1

gm

en

t 1

50

By

te

s5

0 B

yt

es

Se

gm

en

t

Se

gm

en

t

75

0 B

yt

e7

50

By

te

752 752

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 37

Se

gS

eg

19

51

95

SegmentationSegmentation

Consider this example, we have logical address 0001001011110000, 4 left bits forsegment number and the rest is offset, which mean we can have a segment equal to4096 (12 bits). The offset is 752 imagine that this segment is residing in the mainmemory staring at address 0010000000100000, so the physical address will be0010000000100000 + 001011110000 = 0010001100010000.

Segmentation Address Translation

0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0

0 001011101110 0000010000000000

16 Bit Logical Address

4 Bit Segment # 12 Bit offset

Length Base

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 38

0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0

0 001011101110 0000010000000000

1 011110011110 0010000000100000

Process Segment Table

16 Bit Physical Address

+

Page 20: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

20Fall 2010 - DE5

PagingPaging StepsSteps::

1. Extract the left nn most bits as the page number from the logical address.

2. Use this page number as the index into the process page table to find theframeframe numbernumber (k)(k)..

Address Translation Steps

frameframe numbernumber (k)(k)..

3. The starting physical address is kk xx 22mm (m = word length – n) and thephysical address of the referenced byte is that number plus the offset.

SegmentationSegmentation StepsSteps::

1. Extract the segment number from the left most nn bits of the logical address.

2. Use this segment number as index to the process segment table, to find the

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 39

g p g ,starting physical address of the segment.

3. Compare the offset finds in the right most mm bits to the length of thesegment, if it is greater it is invalid.

4. The desireddesired physicalphysical addressaddress is sum of the startingstarting physicalphysical addressaddress ofofthethe segmentsegment plusplus thethe offsetoffset..

Interesting Comment About Windows Paging

http://w-uh.com/posts/030621b-Windows_paging.html

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 40

Page 21: Memory Managementhomes.et.aau.dk/akh/2011/operatingsystem-11_files/LECT-5...Wednesday, 29 September 2010 CHAPTER 7 Fall 2010 - DE5 1 Memory Management M t d di g t f ti g tMost demanding

Wednesday, 29 September 2010

CHAPTER 7

21Fall 2010 - DE5

Dr. D. M. Akbar Dr. D. M. Akbar HussainHussain

Department of Electronic SystemsDepartment of Electronic SystemsDE5 41