cs presentation template - wordpress.com · department of computer science memory management...

40
Department of Computer Science DCS COMSATS Institute of Information Technology Memory Management Rab Nawaz Khan Jadoon Assistant Professor COMSATS Lahore Pakistan Operating System Concepts

Upload: others

Post on 22-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

DCS

COMSATS Institute of Information Technology

Memory Management

Rab Nawaz Khan JadoonAssistant Professor

COMSATS Lahore

Pakistan

Operating System Concepts

Page 2: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Objectives

Primary memory (real memory, physical memory) of computer system has been a major influence on OS design.

Main memory is still expansive compared to secondary storage.

Page 3: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory ManagementOperating System Release date Minimum

memory reqRecomm.Memory

Windows 1.0 Nov 1985 256 KB

Windows 2.03 Nov 1987 320 KB

Windows 3.0 Mar 1990 896 KB I MB

Windows 3.1 Apr 1992 2.6 MB 4 MB

Windows 95 Aug 1995 8 MB 16 MB

Windows NT 4.0 Aug 1996 32 MB 96 MB

Windows 98 Jun 1998 24 MB 64 MB

Windows ME Sep 2000 32 MB 128 MB

Windows 2000Professional

Feb 2000 64 MB 128 MB

Windows XP Home

Oct 2001 64 MB 128 MB

Windows XP prof Oct 2001 128 MB 256 MB

Windows Vista Jan 2007 512 MB 1 GB

Windows 7 Oct 2009 1 GB 2 GB

3

Page 4: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Hierarchy

4

Page 5: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Manager

It is the component of the OS concerned with the system’s memory organization scheme and memory management strategies.

It determines, how available memory space is allocated to processes and how to respond to changes in a memory process’s memory usage.

It also interact with special purpose memory management Hardware to improve performance.

5

Page 6: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory management strategies

Memory Management

Strategies

Fetch strategies

Demand fetch

Anticipatory fetch

Placement strategies

First fit

Best fit

Worst fit

Replacement strategies

6

Page 7: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Management Strategies cont…

Fetch Strategy

It determines when to move the next piece of a program or data to main memory from the secondary memory.

Demand Fetch

In the conventional methods, the system places the next piece of the code or data in main memory when a running program references it.

That is, programs are loaded into the RAM area when they are needed.

7

Page 8: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Management Strategies cont…

Anticipatory strategy

The program or data which is loaded on the basis of prediction that it will be reference in the near future.

This will increase the performance but if the loaded pages are not used, then there is an inefficient memory utilization.

8

Page 9: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Management Strategies cont…

Placement strategy

It determines where in main memory the system should place incoming program or data pieces.

First Fit Strategy

Place the incoming page into the first available hole in the memory

It is faster but leads to memory waste.

It allows the system to make a placement decision quickly.

Best Fit Strategy

Place the incoming page into the hole in which it fits tight.

Best use of memory space.

It is slower in making allocation.

9

Page 10: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Management Strategies cont…

Worst Fit Strategy

Worst-fit memory allocation is opposite to best-fit.

It allocates free available block to the new job and it is not the best choice for an actual system.

Place the incoming job in the largest available whole

Problem Memory fragmentation Memory

waste.

10

Page 11: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory Management Strategies cont…

Replacement strategy

When memory is too full to accommodate a new program, the system must remove some of program or data currently resides in memory.

The system’s replacement strategy determines which piece to remove for making room for incoming jobs.

11

Page 12: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Contiguous vs non contiguous Memory Allocations

To execute a program in the early systems, the OS had to find enough contiguous main memory to accommodate the entire program.

If the program size is larger than the available memory, the program could not execute it.

This is done in contiguous memory allocation, in which all the program pages are loaded into the adjacent memory allocations.

12

Page 13: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Contiguous vs non contiguous Memory Allocations

Non Contiguous Memory Allocation

In noncontiguous memory allocation, a program is divided into blocks or segments, that the system may place in non adjacent slots in main memory

This allows making use of holes (unused gaps) in memory that would be too small to hold whole programs.

The OS thereby incurs more overhead as for as using these unused holes for incoming pages.

13

Page 14: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Quiz

When is noncontiguous preferable to contiguous memory allocation???

14

ANSWER!When the available memory contain no area large enough to hold the incoming programs in one Contiguous space, but sufficient smaller pieces of memory are available, that in total are large enough.

Page 15: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Overlays

Contiguous memory allocation limited the size of programs that could execute on the system

One way in which software designer could overcome the memory limitation was to create overlays, which allowed the system to execute programs larger than main memory.

Programmer divides the program into logical sections.

When the program does not need the memory for one section, the system can replace some or all of its with the memory for a needed section.

Overlays enables a programmer to extend main memory.

15

Page 16: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Overlay structure

16

A

B

C

Operating System

Portion of user code and data than must remain in main memory for duration of execution

User portion with memory requirements larger than available portion of main memory

Initializationphase

Processingphase

Outputphase

Overlay Area

0

a

b

c

b b b

A Load initialization phase at b and run

B Load Processing phase at b and run

C Load Output phase at b and run

Page 17: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Overlay

Managed overlay requires careful and time consuming planning and the programmer often must have detailed knowledge of the system memory organization.

Later on virtual memory system obviate the need for programmer controlled overlays.

17

Page 18: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Protection in single user system

Protection in single user contiguous memory allocation systems can be implemented with a single boundary register built into the processor.

The boundary register contains the memory address at which the user’s program begins.

Each time a process reference a memory address the system determines if the request is for an address greater than or equal to that stored in the boundary register.

If yes, system service the memory request.

Else program is trying to access OS, request is terminated with an error message.

18

Page 19: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Protection in single user system

19

Operating System

User Area

Unused Area

a

Boundary register

Processor

0

a

b

c

Note:Operating System prevents the user from accessing the addresses less than a.

Memory protection with single user contiguous memory allocation

Page 20: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

Even with batch processing OSs, a single user systems still wasted a considerable amount of the computing resource.

A processor wait until IO finished. Because IO speeds were extremely slow compared with processor speed, the CPU was severely underutilized.

Designer saw that they could further increase CPU utilization by implementing multiprogramming systems, in which several users simultaneously compete for the system resources.

The process currently waiting for IO yields the processor if another process is ready to do calculation.

20

Page 21: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

Thus IO and processing operation done simultaneously.

Greatly increases CPU utilization and system throughput.

To take advantage of Multiprogramming several processes must reside in the computer’s main memory at the same time.

When one process requests IO, the CPU may switch to another process and continue without any delay associated with loading programs from secondary storage.

21

Page 22: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

The earlier multiprogramming systems used fixed partition multiprogramming.

In which, system divides main memory into a number of fixed size partitions.

Each partition holds a single job, and the system switches the processor rapidly between jobs to create the illusion of simultaneously.

22

Page 23: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

In the early multiprogramming systems, the programmer translated a job using an absolute assembler or compiler (comp. , linking, and loading),

A job had its precise location in memory determined before it was launched and could run only in a specific partition.

This restriction led to wasted memory because the job had to wait for its designated partition (if occupied), even if other partitions were available.

23

Page 24: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

24

Operating system

Partition 1

Partition 2

Partition 3

Job Queue for partition 1

Job Queue for partition 2

Job Queue for partition 3

These Jobs run only in partition 1

These Jobs run only in partition 2

These Jobs run only in partition 3

0

a

b

c

d

Fixed partition multiprogramming with absolute translation and loading

Page 25: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

25

Operating system

Partition 1

Partition 2

Partition 3(in use)

Job Queue for partition 1

Job Queue for partition 2

Job Queue for partition 3

No jobs waiting for partition 1

0

a

b

c

d

Memory waste under Fixed partition multiprogramming with absolute translation and loading

No jobs waiting for partition 2

Page 26: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fixed Partition Multiprogramming

26

Operating system

Partition 1

Partition 2

Partition 3

0

a

b

c

d

Job Queue

…..

Fixed partition multiprogramming with relocateable translation and loading

jobs

Page 27: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory protection in Multiprogramming

The system can delimit each partition with two boundary registers,

Low and

High

Also called the base and limit register

If a process issues a request for memory, the system checks whether the requested is greater than or equal to the process low boundary register value and less then the high register value.

If so, the system honors the request. Else terminate the request with error.

27

Page 28: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Protection in Multiprogramming

28

Operating system

Partition 1

Partition 2

Partition 3

0

a

b

c

d

2

Low Boundary

Processor

b

c

Currently activepartition

High Boundary

Memory protection in contiguous allocation multiprogramming systems

Page 29: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fragmentation

One problem prevalent in all memory organizations is that of fragmentation (loss of memory).

This states that certain area of the available RAM that system cannot use.

Fixed partition multiprogramming suffers from internal fragmentation, which occurs when the size of the process’s memory and data is smaller than that of the partition in which the process execute.

29

Page 30: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Fragmentation

30

Operating system

Partition 1

Partition 2

Partition 3

0

a

b

c

d

Used Memory

Unused Memory

Internal Fragmentation in a Fixed Partition Multiprogramming System

Page 31: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Quiz 1

Explain the need for relocating compilers, assemblers and loaders???

31

AnswerBefore such tools, programmer manually specified the partition into whichTheir program had to be loaded, which potentially wasted memory andProcessor utilization and reduce application portability.

Page 32: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Quiz 2

Explain the benefits and drawbacks of large and small partition sizes???

32

AnswerLarger partition allows large program to run, but result in internal fragmentation For small programs. Small partition reduce the amount of internal fragmentation And increase the level of multiprogramming by allowing more programs to reside In memory at once, but limit program size.

Page 33: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Variable Partition Multiprogramming

This scheme allows a process to occupy only as much space as needed (up to the amount of available main memory).

This scheme is called variable partition multiprogramming.

The figure on next slide shows the contiguous allocation schemes where a process must occupy adjacent memory allocations.

The queue at the top contains available jobs and information about their memory requirements.

33

Page 34: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Variable partitioning

34

Page 35: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Holes in variable partitioning

Variable partitioning does not suffer from internal fragmentation, because the process’s partition is exactly the size of the process.

Holes can be created upon process execution / completion.

These holes cannot accommodate the incoming processes which are larger than these available holes.

These holes are called external fragmentation.

35

Page 36: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory holes in variable partition multiprogramming

36

Page 37: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Defragmentation Techniques

There are two techniques to overcome the problems of external fragmentation created in variable partitioning system.

The techniques are,

Coalescing (Merging adjacent locations)

Compaction

37

Page 38: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Coalescing Memory Holes

38

Page 39: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science

Memory compaction Technique

39

Page 40: CS Presentation template - WordPress.com · Department of Computer Science Memory Management Operating System Release date Minimum memory req Recomm. Memory Windows 1.0 Nov 1985 256

Department of Computer Science 40