Download presentation
Presentation is loading. Please wait.
Published byJahiem Dobbs Modified over 10 years ago
1
MEMORY MANAGEMENT Y. Colette Lemard
2
MEMORY MANAGEMENT The management of memory is one of the functions of the Operating System MEMORY = MAIN MEMORY = RAM
3
Memory Management Each process must have enough memory in which to execute A process must not encroach on the memory space of other processes nor have its memory space encroached on by other processes The different types of memory must be used properly and effectively The AIMS of memory management
4
Memory Management Note that as processes execute the CPU either reads data from memory or writes data to memory
5
Memory Management How is memory organized to facilitate these objectives?
6
SEGMENTATION
7
Memory Management Memory is partitioned into large sections of fixed sizes called segments. The segments are separated by boundaries. The segments are used for the different types of software.
8
Segmentation Memory is like a fixed set of slots (segments) Each segment has a unique address RAMRAM
9
Memory Management When the system is booted the O/S is loaded into memory first. It occupies the lower level of memory. O/S
10
Memory Management The drivers needed to control the hardware are next loaded into memory O/S Drivers
11
Segmentation The rest of the space is normally used for application programs ( user processes ). One entire process is loaded into one segment O/S Drivers Process 1 Process 2 Process 3
12
Segments Partitions may all be of the same size or the sizes may vary. The size(s) is(are) fixed however. They must be large enough to hold all the data for an entire process
13
Memory Management The O/S is responsible for : -Keeping track of which parts of memory are currently being used and by what process -Knowing which parts of memory are free -Deciding which process is to be loaded into memory when space becomes available.
14
Segmentation The segmentation approach sometimes causes difficulties because of the inflexibility of the partition sizes.
15
Segmentation Lots of space is wasted. Lots of space is wasted. Most programs do not use up the exact amount of the segment O/S Drivers Process 1 Process 2 Process 3
16
Segmentation -Sometimes the total of the left over space is enough for another process but it is fragmented and processes can not share partitions.
17
Segmentation -Segmentation therefore imposes a fixed limit on the maximum number of processes which can run at any one time => # of user segments => # of user segments
18
Segmentation II To counteract this the O/S can use variable partitioning Do not predetermine the sizes of the segments; give a process just the memory it needs. Do not predetermine the sizes of the segments; give a process just the memory it needs.
19
Segmentation II O/S Drivers Process 1 Process 2 Process 3 VARIABLY PARTITIONING Create the partition when it is needed, give just as much memory as will be required.
20
Segmentation In the long run this still results in holes in the memory as when a process is finished, the next process will not need the same amount as the previous one. If only a part of the memory is used by the next process, some is still left unused resulting in some fragmentation over a period of time
21
Segmentation A Solution – The O/S can periodically pause all tasks and compact memory so that all the free space falls in one continuous area which can be used by other processes.
22
Segmentation The major disadvantage of this approach is the time it takes to compact memory. Remember that this is not a user task so it takes up valuable time which could be used in constructive processing.
23
Memory Management For best use of the resource (memory) we therefore need another approach to managing RAM
24
PAGING
25
Paging This is an alternate approach to partitioning. Here memory is divided into very small frames as compared with segments. A single process would find that all its data cannot fit into one frame. This is an alternate approach to partitioning. Here memory is divided into very small frames as compared with segments. A single process would find that all its data cannot fit into one frame. Frames are in the order of 2 9 to 2 13 bytes in size. They are fixed in size for a particular system.
26
Paging The program and data therefore would also have to be partitioned so that portions of them can fit into the individual frames. The program and data therefore would also have to be partitioned so that portions of them can fit into the individual frames. The programs (and data) are said to be divided into pages. The page size would be the same as the size of the memory frames.
27
Memory Management Program & data pages Main memory frames
28
Memory Management PAGING has proven to be quite effective
29
Memory Management Questions ?
30
Memory Management Despite the best efforts of the operating system though, it sometimes finds that it needs more memory than is available because of the number and size of the processes being run.
31
Memory Management One solution is to add more memory to the machine This could work BUT … - memory is expensive - only a little part of the data in memory is actually being used by the CPU at any one point in time so spending more money on memory could be unnecessary
32
BUT … Because memory is finite, AND because the user code is broken up into pages, AND because the CPU can only operate on one page of data at a time anyway… DO WE REALLY NEED TO HAVE ALL OF A PROGRAM IN MEMORY AT ONCE?
33
VIRTUALMEMORY
34
Virtual Memory Only the pages presently being used, last used or about to be used need to be in memory. The other pages can rest in a section of the hard drive awaiting their turn.
35
Virtual Memory To the user it appears that the entire program is loaded into memory but it is not.. This is VIRTUAL MEMORY This is VIRTUAL MEMORY
36
Virtual Memory Disk space is relatively inexpensive compared to RAM. This is a better approach than adding more memory because ….
37
Virtual Memory Virtual memory therefore involves using a portion of the disk to extend the size of RAM.
38
Virtual Memory When the disk is full the O/S has less space to utilize for virtual memory. When the disk is full the O/S has less space to utilize for virtual memory. This explains why a system moves so very slowly when the hard disk is full
39
Question A computer uses a virtual memory management scheme with frames of 512 bytes. It has a physical memory of 16 MB. 1.How many frames does main memory have? 2.What is the size of each page? 3.If memory is fully utilized how many pages are mapped to memory?
40
Answers A computer uses a virtual memory management scheme with frames of 512 bytes. It has a physical memory of 16 MB. 1.How many frames does main memory have? 32 2.What is the size of each page? 2 9 Bytes 3.If memory is fully utilized how many pages are mapped to memory? 32
41
Virtual Memory In a virtual memory paging system, because we have some pages in RAM and some on the disk we need what is called a page table to keep track of where each page is being stored.
42
Virtual Memory Remember that in this system, the program could be split two ways: 1.Some pages are on the disk 2.Other pages are in scattered frames in memory
43
Virtual Memory When the CPU needs a particular page of data the O/S must know where to locate it (Hopefully it is in memory) The page table is used in the search
44
Page Table Page # Loc 12 26 31 4020105 Loc = location
45
Page # Loc 12 26 31 4020105 12 3 4 Program Program divided into 4 Pages Page Table31 2 Main memory 123456123456
46
The page table is therefore searched for the particular page of interest; its location is noted and that address in main memory is accessed.
47
Page # Loc 12 26 31 4020105 12 3 4 Program 4 Pages Page Table31 2 Main memory 123456123456
48
The page table sometimes includes a column which indicates whether or not the page is in memory. If a page is not in memory it is accessed on the hard disk and brought into a free frame
49
Note that in our example one page is on the hard disk. Before the CPU can use that data it has to be brought into main memory
50
Page # Loc 12 26 31 4020105 12 3 4 Program Program divided into 4 Pages Page Table31 2 Main memory 123456123456
51
If main memory is full then the O/S has to begin swapping. It removes one page, stores it on the hard drive and then puts the needed page into that frame. SWAPPING
52
When the O/S has to spend a lot of time swapping pages from main memory to virtual memory THRASHING is said to be taking place. This reduces the efficiency of processing by slowing down execution time THRASHING
53
Virtual memory therefore -allows more programs to be running at a time and -Enables the execution of very large programs which can not hold in memory at one time
54
Segmentation Fixed partitioning Fixed partitioning Variable partitioning Paging (pages & frames) Virtual memory page tables swappingthrashing SUMMARY Topics covered
55
THE END
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.