memory management y. colette lemard. memory management the management of memory is one of the...

55
MEMORY MEMORY MANAGEMENT MANAGEMENT Y. Colette Y. Colette Lemard Lemard

Upload: jahiem-dobbs

Post on 29-Mar-2015

242 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

MEMORY MEMORY MANAGEMENTMANAGEMENT

Y. Colette LemardY. Colette Lemard

Page 2: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

MEMORY MEMORY MANAGEMENTMANAGEMENT

The management of The management of memory is memory is

one of the functions of one of the functions of the Operating Systemthe Operating System

MEMORY = MAIN MEMORY = RAM

Page 3: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Each process must have enough Each process must have enough memory in which to executememory in which to execute

A process must not encroach on the A process must not encroach on the memory space of other processes nor memory space of other processes nor have its memory space encroached on have its memory space encroached on by other processesby other processes

The different types of memory must The different types of memory must be used properly and effectivelybe used properly and effectively

The AIMS

of memory

management

Page 4: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Note that as processes Note that as processes executeexecute

the CPU either reads data the CPU either reads data from memory or writes data from memory or writes data

to memoryto memory

Page 5: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

How is memory How is memory organized organized

to facilitate these to facilitate these

objectives?objectives?

Page 6: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SEGMENTATIONSEGMENTATION

Page 7: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Memory is partitioned into large Memory is partitioned into large sections of sections of fixed sizesfixed sizes called called segments. The segments are segments. The segments are separated by boundaries.separated by boundaries.

The segments are used for the The segments are used for the different types of software.different types of software.

Page 8: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

Memory is like Memory is like a fixed set of a fixed set of slots slots (segments) (segments)

Each segment Each segment has a unique has a unique addressaddress

RAM

Page 9: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

When the When the system is system is booted the booted the O/S is loaded O/S is loaded into memory into memory first. It first. It occupies the occupies the lower level of lower level of memory. memory. O/S

Page 10: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

The drivers The drivers needed to needed to control the control the hardware hardware are next are next loaded into loaded into memorymemory

O/S

Drivers

Page 11: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

The rest of the space The rest of the space is normally used for is normally used for application application programsprograms( user processes ). ( user processes ).

One entire process One entire process is loaded into is loaded into one segmentone segment O/S

Drivers

Process 1

Process 2

Process 3

Page 12: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentsSegments

Partitions may all be of the same size Partitions may all be of the same size or the sizes may vary.or the sizes may vary.

The size(s) is(are) fixed however.The size(s) is(are) fixed however.

They must be large enough to hold They must be large enough to hold all the data for an entire processall the data for an entire process

Page 13: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

The O/S is responsible for :The O/S is responsible for :

- Keeping track of which parts of memory are Keeping track of which parts of memory are currently being used and by what processcurrently being used and by what process

- Knowing which parts of memory are freeKnowing which parts of memory are free

- Deciding which process is to be loaded into Deciding which process is to be loaded into memory when space becomes available.memory when space becomes available.

Page 14: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

The segmentation approach The segmentation approach sometimes causes sometimes causes

difficulties because of the difficulties because of the inflexibility of the partition inflexibility of the partition

sizes.sizes.

Page 15: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

Lots of space is Lots of space is wasted. wasted.

Most programs Most programs do not use up do not use up the exact amount the exact amount of the segmentof the segment

O/S

Drivers

Process 1

Process 2

Process 3

Page 16: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

- Sometimes the total of the Sometimes the total of the left over space is enough for left over space is enough for another process but it is another process but it is fragmented and processes fragmented and processes can not share partitions.can not share partitions.

Page 17: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

- Segmentation therefore Segmentation therefore imposes a fixed limit on the imposes a fixed limit on the maximum number of maximum number of processes which can run at processes which can run at any one time any one time

=> # of user segments=> # of user segments

Page 18: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Segmentation IISegmentation II

To counteract this the O/S can To counteract this the O/S can use use variable partitioningvariable partitioning

Do not predetermine the sizes Do not predetermine the sizes of the segments; give a of the segments; give a process just the memory it process just the memory it needs.needs.

Page 19: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Segmentation IISegmentation II

O/S

Drivers

Process 1

Process 2

Process 3VARIABLY PARTITIONING

Create the partition when it is needed, give just as much memory as will be required.

Page 20: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

In the long run this still results in holes in In the long run this still results in holes in the memory as when a process is the memory as when a process is finished, the next process will not need finished, the next process will not need the same amount as the previous one.the same amount as the previous one.

If only a part of the memory is used by If only a part of the memory is used by the next process, some is still left the next process, some is still left unused resulting in some unused resulting in some fragmentation over a period of timefragmentation over a period of time

Page 21: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

A Solution –A Solution –

The O/S can periodically pause The O/S can periodically pause all tasks and compact memory all tasks and compact memory so that all the free space falls in so that all the free space falls in one continuous area which can one continuous area which can be used by other processes.be used by other processes.

Page 22: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation

The major disadvantage of thisThe major disadvantage of thisapproach is the time it takes to approach is the time it takes to compact memory. compact memory.

Remember that this is not a user Remember that this is not a user task so it takes up valuable time task so it takes up valuable time which could be used in which could be used in constructive processing.constructive processing.

Page 23: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

For best use of the For best use of the resource (memory) we resource (memory) we therefore need another therefore need another approach to managing approach to managing RAMRAM

Page 24: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

PAGINGPAGING

Page 25: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

PagingPaging

This is an alternate approach to This is an alternate approach to partitioning. Here memory is divided into partitioning. Here memory is divided into very small frames as compared with very small frames as compared with segments. A single process would find that segments. A single process would find that all its data cannot fit into one frame.all its data cannot fit into one frame.

Frames are in the order of 2Frames are in the order of 299 to 2 to 21313 bytes in bytes in size. They are fixed in size for a particular size. They are fixed in size for a particular system.system.

Page 26: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Paging Paging

The program and data therefore would The program and data therefore would also have to be partitioned so that also have to be partitioned so that portions of them can fit into the portions of them can fit into the individual individual framesframes..

The programs (and data) are said to be The programs (and data) are said to be divided into divided into pagespages. The page size . The page size would be the same as the size of the would be the same as the size of the memory frames.memory frames.

Page 27: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Program & data pages

Main m

emory fram

es

Page 28: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

PAGING has proven to be PAGING has proven to be quite effectivequite effective

Page 29: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Questions ?Questions ?

Page 30: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

Despite the best efforts of the Despite the best efforts of the operating system though, it operating system though, it sometimes finds that it needs sometimes finds that it needs more memory than is available more memory than is available because of the number and because of the number and size of the processes being run.size of the processes being run.

Page 31: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Memory ManagementMemory Management

One solution is to add more memory to the One solution is to add more memory to the machinemachine

This could work BUT …This could work BUT …- memory is expensivememory is expensive- only a little part of the data in memory is only a little part of the data in memory is

actually being used by the CPU at any one actually being used by the CPU at any one point in time so spending more money on point in time so spending more money on memory could be unnecessarymemory could be unnecessary

Page 32: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

BUT …BUT …Because memory is finite,Because memory is finite,

AND because the user code is AND because the user code is broken up into pages,broken up into pages,

AND because the CPU can only AND because the CPU can only operate on one page of data at a operate on one page of data at a

time anyway…time anyway…

DO WE REALLY NEED TO HAVE DO WE REALLY NEED TO HAVE ALL OF A PROGRAM IN ALL OF A PROGRAM IN

MEMORY AT ONCE?MEMORY AT ONCE?

Page 33: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

VIRTUAL VIRTUAL

MEMORYMEMORY

Page 34: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

Only the pages presently being Only the pages presently being used, last used or about to be used, last used or about to be used need to be in memory.used need to be in memory.

The other pages can rest in a The other pages can rest in a section of the hard drive section of the hard drive awaiting their turn.awaiting their turn.

Page 35: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

To the user it appears that the To the user it appears that the entire program is loaded into entire program is loaded into memory but memory but

it is not.. it is not..

This is This is VIRTUAL MEMORYVIRTUAL MEMORY

Page 36: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

Disk space is relatively Disk space is relatively inexpensive compared to inexpensive compared to

RAM.RAM.

This is a better approach than adding more memory because ….

Page 37: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

Virtual memory therefore Virtual memory therefore

involves using a portion of the involves using a portion of the

disk to extend the size of RAM.disk to extend the size of RAM.

Page 38: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

When the disk is full the O/S has When the disk is full the O/S has less space to utilize for virtual less space to utilize for virtual memory.memory.

This explains why a system moves This explains why a system moves so very slowly when the hard disk so very slowly when the hard disk is fullis full

Page 39: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

QuestionQuestion

A computer uses a virtual memory A computer uses a virtual memory

management scheme with frames of 512management scheme with frames of 512

bytes. It has a physical memory of 16 MBbytes. It has a physical memory of 16 MB..

1.1. How many frames does main memory How many frames does main memory have?have?

2.2. What is the size of each page?What is the size of each page?

3.3. If memory is fully utilized how many pages If memory is fully utilized how many pages are mapped to memory?are mapped to memory?

Page 40: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

AnswersAnswers

A computer uses a virtual memory A computer uses a virtual memory management scheme with frames of 512 management scheme with frames of 512 bytes. It has a physical memory of 16 MB.bytes. It has a physical memory of 16 MB.

1.1. How many frames does main memory How many frames does main memory have? have? 32 32

2.2. What is the size of each page? What is the size of each page? 2 29 9 BytesBytes

3.3. If memory is fully utilized how many pages If memory is fully utilized how many pages are mapped to memory? are mapped to memory? 3232

Page 41: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

In a virtual memory paging In a virtual memory paging system, because we have system, because we have some pages in RAM and some some pages in RAM and some on the disk we need what is on the disk we need what is called a called a page tablepage table to keep to keep track of where each page is track of where each page is being stored.being stored.

Page 42: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

Remember that in this system, Remember that in this system, the program could be split the program could be split two ways:two ways:

1.1. Some pages are on the diskSome pages are on the disk

2.2. Other pages are in scattered Other pages are in scattered frames in memoryframes in memory

Page 43: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual MemoryVirtual Memory

When the CPU needs a particular When the CPU needs a particular page of data the O/S must page of data the O/S must know where to locate it know where to locate it (Hopefully it is in memory)(Hopefully it is in memory)

The page table is used in the The page table is used in the searchsearch

Page 44: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Page Table Page Table

Page #Page # LocLoc

11 22

22 66

33 11

44 020105020105

Loc = location

Page 45: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Page #Page # LocLoc

11 22

22 66

33 11

44 020105020105

11

22

33

44

Program

Program divided into 4 Pages

Page Table

33

11

22

Main memory

1

2

3

4

5

6

Page 46: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

The page table is therefore The page table is therefore searched for the particular searched for the particular

page of interest; page of interest; its location is notedits location is noted

and that address in main and that address in main memory is accessed.memory is accessed.

Page 47: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Page Page ##

LocLoc

11 22

22 66

33 11

44 020105020105

11

22

33

44

Program

4 Pages

Page Table

33

11

22

Main memory

1

2

3

4

5

6

Page 48: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

The page table sometimes includes a The page table sometimes includes a column which indicates whether or column which indicates whether or

not the page is in memory.not the page is in memory.

If a page is not in memory it is If a page is not in memory it is accessed on the hard disk and accessed on the hard disk and

brought into a free framebrought into a free frame

Page 49: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Note that in our example one page Note that in our example one page is on the hard disk.is on the hard disk.

Before the CPU can use that data Before the CPU can use that data it has to be brought into main it has to be brought into main

memorymemory

Page 50: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Page Page ##

LocLoc

11 22

22 66

33 11

44 020105020105

11

22

33

44

Program

Program divided into 4 Pages

Page Table

33

11

22

Main memory

1

2

3

4

5

6

Page 51: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

If main memory is full then the If main memory is full then the O/S has to begin swapping.O/S has to begin swapping.

It removes one page, stores it on It removes one page, stores it on the hard drive and then puts the hard drive and then puts

the needed page into that the needed page into that frameframe..

SWAPPING

Page 52: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

When the O/S has to spend a lot When the O/S has to spend a lot of time swapping pages from of time swapping pages from

main memory to virtual memory main memory to virtual memory THRASHINGTHRASHING is said to be is said to be

taking place.taking place.This reduces the efficiency of This reduces the efficiency of

processing by slowing down processing by slowing down execution timeexecution time

THRASHING

Page 53: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

Virtual memoryVirtual memory therefore therefore

- allows more programs to be allows more programs to be running at a time andrunning at a time and

- Enables the execution of very Enables the execution of very large programs which can not large programs which can not hold in memory at one timehold in memory at one time

Page 54: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

SegmentationSegmentation Fixed partitioningFixed partitioning

Variable partitioningVariable partitioning

PagingPaging (pages & frames) (pages & frames)Virtual memory Virtual memory

page tablespage tablesswappingswappingthrashingthrashing

SUMMARYT

opic

s co

vere

d

Page 55: MEMORY MANAGEMENT Y. Colette Lemard. MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY =

THE ENDTHE END