Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)

Similar presentations


Presentation on theme: "CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)"— Presentation transcript:

1 CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)

2 © De Montfort University, 2004CSCI2413 - L52 Lecture Outline Background Memory Types Memory Management.. –Overlays –Swapping Allocation –First fit, Best fit, Worst fit

3 © De Montfort University, 2004CSCI2413 - L53 Background The process scheduling determines –when a process will run The memory manager determines –where a process will run

4 © De Montfort University, 2004CSCI2413 - L54 The problem ! No matter how much memory we install, some programmer will always want to use more!! How do we get a quart into a pint pot ?? Hence, MEMORY Management …

5 © De Montfort University, 2004CSCI2413 - L55 Memory Types –CPU registers –cache on board, or very close to, the microprocessor –Primary or main memory –Read And Write Memory (RAM) or Read Only Memory (ROM) –secondary hard disks or other offline storage devices

6 © De Montfort University, 2004CSCI2413 - L56 Memory Speeds The clock for a 500 MHz processor ticks at a rate of 500 million times per second –each tick takes 2 nanoseconds cache memory, built into the microprocessor, –access time typically a few nanoseconds (around 10 nsec.) Primary memory around 50 - 100 nanoseconds Hard disk, about 10 milliseconds or ten million nanoseconds!

7 © De Montfort University, 2004CSCI2413 - L57 Memory Management Requirements Relocation –Programmer does not know where the program will be placed in memory when it is executed –While the program is executing, it may be swapped to disk and returned to main memory at a different location (relocated) –Memory references in the code must be translated to actual physical memory addresses

8 © De Montfort University, 2004CSCI2413 - L58

9 © De Montfort University, 2004CSCI2413 - L59 A Simple Model In the simplest memory management model –one process is in memory at a time that process is allowed to use as much memory as available user program 1 user program 2 operating system 0x0000 0x1000 0xFFFF

10 © De Montfort University, 2004CSCI2413 - L510 Overlays Split the program into small blocks Keep in main only those blocks that are needed at any given time. Needed when process is larger than amount of memory allocated to it.

11 © De Montfort University, 2004CSCI2413 - L511 Overlays … it is possible to increase the amount of memory available through the use of overlays main:initialisation input processing output initialisation main:initialisation input processing output main:initialisation input processing output input main:initialisation input processing output processing main:initialisation input processing output operating system 0x0000 0x1000 0xFFFF

12 © De Montfort University, 2004CSCI2413 - L512 Swapping Moving processes to and fro between main memory and hard disk is called swapping Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher- priority process can be loaded and executed.

13 © De Montfort University, 2004CSCI2413 - L513 Schematic View of Swapping Main MemoryBacking store Operating Systems Process 1 User Space Process 2 Swap out Swap in

14 © De Montfort University, 2004CSCI2413 - L514 Fixed Partitioning Main memory is divided into equal- (or unequal-) sized partitions and these partitions are assigned to processes. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. Main memory use is inefficient. The operating system keeps a track of which partitions are being used and which are free –processes are allocated to partitions when free

15 © De Montfort University, 2004CSCI2413 - L515 Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as required Eventually get holes in the memory. This is called external fragmentation Must use compaction to shift processes so they are contiguous and all free memory is in one block

16 © De Montfort University, 2004CSCI2413 - L516 Memory Allocation Methods 1. Single Process Systems User Process Operating System Unused Space

17 © De Montfort University, 2004CSCI2413 - L517 Memory Allocation Methods 2. Fixed Partition Memory Operating System Process A 180K Process B 200K Process C 300K 200K 300K 400K 0K 1000K

18 © De Montfort University, 2004CSCI2413 - L518 Memory Allocation Methods 3. Variable Partition Memory Operating System Process A 180K Process B 200K Process C 300K

19 © De Montfort University, 2004CSCI2413 - L519 Contiguous Allocation Main memory usually into two partitions: –Resident operating system, usually held in low memory with interrupt vector. –User processes then held in high memory. contiguous storage –allocates memory only in a single block the memory is in a single, continuous block, with no ‘holes’ or ‘gaps’

20 © De Montfort University, 2004CSCI2413 - L520 Contiguous Allocation … Hole – blocks of memory; holes of various size scattered throughout memory. –When a process arrives, it is allocated memory from a hole large enough to accommodate it. –Operating system maintains information about: a) allocated partitions b) free partitions (hole) process 2 process 5 process 9 OS process 2 process 5 OS process 2 process 5 OS process 2 process 5 process 9 OS process 9 process 10

21 © De Montfort University, 2004CSCI2413 - L521 Non-contiguous … Allocate memory in multiple blocks, or segments, which may be placed anywhere in memory –the blocks are not necessarily next to each other –this is called non-contiguous storage allocation

22 © De Montfort University, 2004CSCI2413 - L522 Placement Algorithms Operating system must decide which free block to allocate to a process –First-fit: scan the list segment and choose the block that is closest to the request. –Best-fit: search the entire list and allocate the smallest hole that is big enough; –Worst-fit: allocate the largest hole; must also search entire list. Produces the largest leftover hole.

23 © De Montfort University, 2004CSCI2413 - L523 Example: A variable partition memory has the following hole sizes in memory order: 200K, 600K, 400K, 800K, 350K, 70K A new process of size 300K enters the system. Determine where it will go according to the best-fit, first-fit and worst-fit algorithms and update the hole size status of the memory after the process has been added.

24 © De Montfort University, 2004CSCI2413 - L524 Placement Policies Another Example Hole sizes are: 475K 425K 350K 2 processes of sizes 370K and 100K Best–fit ? First-fit ?

25 © De Montfort University, 2004CSCI2413 - L525 Dynamic relocation using a relocation register

26 © De Montfort University, 2004CSCI2413 - L526 Summary A number of processes can coexist in memory using a variety of allocation techniques and placement policies Main problem is the creation of unusable holes as processes terminate making it sometimes difficult to accommodate new processes Compaction can be used to shuffle processes and create larger more usable space but the large overheads involved make it not always feasible to carry out in real time.


Download ppt "CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)"

Similar presentations


Ads by Google