memory management y. colette lemard. memory management the management of memory is one of the...
TRANSCRIPT
MEMORY MEMORY MANAGEMENTMANAGEMENT
Y. Colette LemardY. Colette Lemard
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
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
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
Memory ManagementMemory Management
How is memory How is memory organized organized
to facilitate these to facilitate these
objectives?objectives?
SEGMENTATIONSEGMENTATION
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.
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
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
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
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
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
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.
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.
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
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.
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
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.
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.
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
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.
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.
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
PAGINGPAGING
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.
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.
Memory ManagementMemory Management
Program & data pages
Main m
emory fram
es
Memory ManagementMemory Management
PAGING has proven to be PAGING has proven to be quite effectivequite effective
Memory ManagementMemory Management
Questions ?Questions ?
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.
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
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?
VIRTUAL VIRTUAL
MEMORYMEMORY
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.
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
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 ….
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.
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
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?
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
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.
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
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 Table Page Table
Page #Page # LocLoc
11 22
22 66
33 11
44 020105020105
Loc = location
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
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 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
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
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 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
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
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
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
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
THE ENDTHE END