operating systems - sourceforgealphapeeler.sourceforge.net/uit/2016_fall/cs311/week08.pdf · 2016....

26
Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) [email protected] [email protected] alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net pk.linkedin.com/in/armahmood http://alphapeeler.tumblr.com www.twitter.com/alphapeeler [email protected] www.facebook.com/alphapeeler [email protected] abdulmahmood-sss alphasecure mahmood_cubix 48660186 [email protected] [email protected] http://alphapeeler.sf.net/me http://alphapeeler.sf.net/acms/ VC++, VB, ASP Operating Systems

Upload: others

Post on 07-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Engr. Abdul-Rahman MahmoodMS, PMP, MCP, QMR(ISO9001:2000)

[email protected] [email protected]

alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net

pk.linkedin.com/in/armahmood http://alphapeeler.tumblr.com

www.twitter.com/alphapeeler [email protected]

www.facebook.com/alphapeeler [email protected]

abdulmahmood-sss alphasecure mahmood_cubix 48660186

[email protected] [email protected]

http://alphapeeler.sf.net/me http://alphapeeler.sf.net/acms/

VC++, VB, ASP

Operating Systems

Page 2: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Memory Management

Memory Management Terms:

Frame

Page

Segment

Memory management Requirements:

Relocation

Protection

Sharing

Logical organization

Physical organization

A fixed-length block of main memory.

A fixed-length block of data that resides in secondary memory

A variable-length block of data that resides in secondary memory.

Page 3: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Addressing Requirements

• Branch instructions contain an address to reference the instruction to be

executed next.

• The process stack contains a list of all threads currently running.

Page 4: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Logical Organization Memory is organized as linear, 1D array (bytes/words

sequence)

Segmentation satisfies logical organization requirements.

Programs are written in modules

• modules can be written and compiled independently

• different degrees of protection given to modules (read-only, execute-only)

• sharing on a module level corresponds to the user’s way of viewing the problem

Page 5: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Physical Organization

overlaying allows various modules to be assigned

the same region of memory but is time

consuming to program

Cannot leave the programmer with the

responsibility of memory flow from main to

secondary for 2 reasons

(1) Memory available for a program plus its data

may be insufficient

(2) Programmer does not know how much space

will be available

Page 6: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Memory Partitioning

Memory management brings processes into main memory for

execution by the processor

involves virtual memory

based on segmentation and paging

Partitioning

used in several variations in some now-obsolete operating

systems

does not involve virtual memory

Page 7: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Memory Management TechniquesTechnique Description Strengths Weaknesses

Fixed

Partitioning

MM is divided into static partitions at

system generation time.

Simple to implement;

little OS overhead.

Waste of MM due

to internal

fragmentation

Dynamic

Partitioning

Partitions created dynamically, process

loads in MM partition of same size.

No internal

fragmentation; Efficient

use of MM.

Load on processor

due to compaction

to remove external

fragmentation.

Simple Paging

MM is divided in equal-size frames.

Process is divided in equal-size pages

of frame length. A process is loaded

by loading all of pages into memory frames.

No external

fragmentation.

A small amount of

internal

fragmentation.

Simple

Segmentation

Process divided in segments. Process is

loaded by loading all of its segments

into dynamic partitions.

No internal

fragmentation; improved

MM utilization

compared to dynamic

partitioning.

External

fragmentation.

Virtual

Memory

Paging

Similar to simple paging, but may not

load all process pages. Nonresident

pages may be brought in later from SS.

No ext frag.; higher

degree of

multiprogramming; large

virtual address space.

Overhead of

complex memory

management.

Virtual

Memory

Segmentation

Similar to simple segmentation, but

may not load all process segments.

Nonresident segments may be brought

in later from SS.

No ext frag.;

multiprogramming; large

virtual address space.

protection & sharing

support.

Overhead of

complex memory

management.

Page 8: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Fixed vs Dynamic Partitioning

Page 9: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Memory Assignment for Fixed Partitioning

F

i

x

e

d

P

a

r

t

i

t

i

o

n

i

n

g

Page 10: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

The number of partitions specified at system

generation time limits the number of active

processes in the system

Small jobs will not utilize partition space

efficiently

Page 11: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Partitions are of variable length and number

Process is allocated exactly as much memory as it

requires

This technique was used by IBM’s mainframe operating

system, OS/MVT

Page 12: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Effect of

Dynamic

Partitioning

Page 13: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Dynamic Partitioning

• memory becomes more and more fragmented

• memory utilization declines

External Fragmentation

• technique for overcoming external fragmentation

• OS shifts processes so that they are contiguous

• free memory is together in one block

• time consuming and wastes CPU time

Compaction

Page 14: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Placement Algorithms

Best-fit

• chooses the block that is closest in size to the request

First-fit

• begins to scan memory from the beginning and chooses the first available block that is large enough

Next-fit

• begins to scan memory from the location of the last placement and chooses the next available block that is large enough

Page 15: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Memory

Configuration

Example

Page 16: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Buddy System

Comprised of fixed and dynamic partitioning

schemes

Space available for allocation is treated as a

single block

Memory blocks are available of size 2K words,

L ≤ K ≤ U, where 2L = smallest size block that is allocated

2U = largest size block that is allocated; generally 2U is the size of the

entire memory available for allocation

Page 17: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Buddy System Example

Page 18: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

T

r

e

e

R

e

p

r

e

s

e

n

t

a

t

i

o

n

Page 19: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Addresses

• reference to a memory location independent of the current assignment of data to memory

Logical

• address is expressed as a location relative to some known point (a particular example of logical address)

Relative

• actual location in main memory

Physical or Absolute

Page 20: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory
Page 21: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Partition memory into equal fixed-size chunks (termed frames)

that are relatively small

Process is also divided into small fixed-size chunks (termed pages)

of the same size

Pages

• chunks of a process

Frames

• available chunks of memory

Page 22: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Assignment of

Process to

Free Frames

Page 23: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Page Table

Maintained by operating system for each process

Contains the frame location for each page in the process

Processor must know how to access for the current process

Used by processor to produce a physical address

Page 24: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Data Structures

Page 25: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Logical Addresses

Logical address

= page #

+ offset within page

16-bit address

Page size = 1KB

= 210 Bytes

Page 26: Operating Systems - SourceForgealphapeeler.sourceforge.net/uit/2016_fall/CS311/week08.pdf · 2016. 11. 17. · Memory Partitioning Memory management brings processes into main memory

Logical-to-Physical Address

Translation - Paging