Presentation is loading. Please wait.

Presentation is loading. Please wait.

CY2003 Computer Systems Lecture 09 Memory Management.

Similar presentations


Presentation on theme: "CY2003 Computer Systems Lecture 09 Memory Management."— Presentation transcript:

1 CY2003 Computer Systems Lecture 09 Memory Management

2 © LJMU, 2004CY2003- Week 092 Overview Memory management concepts –memory types cache, primary and secondary –contiguous v. non-contiguous memory allocation –single user memory allocation Fixed partition multiprogramming –concepts Variable partition multiprogramming Allocation strategies

3 © LJMU, 2004CY2003- Week 093 Background The process manager determines –when a process will run The memory manager determines –where a process will run The ‘first law’ of computing –however much memory a computer has, a program will be written that needs more! The functions of the memory manager include –allocating memory to processes –protecting memory areas from interference –overcoming the ‘first law’ by simulating extra memory

4 © LJMU, 2004CY2003- Week 094 Memory Types There are three main types of computer memory –cache on board, or very close to, the microprocessor –primary the main memory of the computer –Random Access Memory (RAM) or Read Only Memory (ROM) –secondary hard disks or other offline storage devices cache primary secondary

5 © LJMU, 2004CY2003- Week 095 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

6 © LJMU, 2004CY2003- Week 096 Overlays Even with this very simple model 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

7 © LJMU, 2004CY2003- Week 097 Contiguous and Non-contiguous The simple system presented so far allocates memory only in a single block –this is called contiguous storage allocation –the memory is in a single, continuous block, with no ‘holes’ or ‘gaps’ More complex memory management models have the capability to allocate memory in multiple blocks, or segments, which may be placed anywhere in primary memory –the blocks are not necessarily next to each other –this is called non-contiguous storage allocation

8 Fixed Partition Multiprogramming

9 © LJMU, 2004CY2003- Week 099 Concepts The first stage in extending the simple one- process model is to allow multiprogramming –this can improve processor utilisation if the average process only uses the processor 50% of the time and is performing I/O (waiting) for the other 50% then we can fully utilise the processor with two jobs Multiple jobs can be run if there is space in main memory, for example –the computer has 1Mb main memory the operating system occupies 200Kb each process fits into 400Kb –the computer has enough memory to run both jobs

10 © LJMU, 2004CY2003- Week 0910 Fixed Partitions The simplest multiprogramming scheme is the fixed partition multiprogramming model Memory is divided up into N partitions of fixed size –the partitions do not have to be the same size –the size of each may be determined by operators e.g. the IBM OS/360: partitions determined each morning –the maximum size of each process must be known The operating system keeps a track of which partitions are being used and which are free –processes are allocated to partitions when free

11 © LJMU, 2004CY2003- Week 0911 Multiple Partition Queues 0 100K 200K 400K 700K process E process F process G process D process C process A process B process A process C process D process E process F process G process B process F process B process G operating system

12 © LJMU, 2004CY2003- Week 0912 Single Partition Queue 0 100K 200K 400K 700K process A process B process C process D process B process C process Dprocess E process F process G process A operating system process E process F process G

13 Variable Partition Multiprogramming

14 © LJMU, 2004CY2003- Week 0914 What is Swapping? In a batch oriented operating system, fixed partition multiprogramming is simple and effective –as long as enough jobs can be kept in memory to keep the processor busy there is no real reason to use a more complicated memory allocation scheme In timesharing systems the situation is different –there are usually more users than there is main memory to hold all their processes –excess processes must be kept on hard disk Moving processes to and from between main memory and hard disk is called swapping

15 © LJMU, 2004CY2003- Week 0915 Fixed Partition Swapping In principle, a swapping system could be based on the fixed partition allocation scheme –whenever a process blocked it could be moved out to hard disk and the partition freed for use by another process to be swapped in However, this is likely to waste a lot of memory –if a large process is swapped out of a large partition, there may only be small processes ready to run If we are going to the trouble of implementing the ability to swap, then it is better to allow the partition sizes to change size (dynamically)

16 © LJMU, 2004CY2003- Week 0916 The Problem of Fixed Partitions process A process B process C process D process E process D (blocked) process E process A process D although process D is now ready to run again, there is no partition free that is big enough to hold it there is now a lot of wasted memory 0 100K 200K 400K 700K operating system

17 © LJMU, 2004CY2003- Week 0917 Variable Partitions When using variable partitions, the number, location and size of each partition is governed by the processes actually being run –when a process is to be swapped in (by being newly created or recently unblocked) a new partition big enough to hold the process is created –when a process is to be swapped out the partition is freed This flexibility improves memory usage buts also complicates allocation and deallocation –as well as keeping track of the memory used

18 © LJMU, 2004CY2003- Week 0918 How Variable Partitions Work process A process B process C process D process E operating system 0 1 Mb

19 Allocation Strategies

20 © LJMU, 2004CY2003- Week 0920 Allocation with Linked Lists A more sophisticated allocation data structure is required to deal with a variable number of free and used partitions –there are various data structures and associated algorithms available A linked list is one such possible data structure –a linked list consists of a number of entries (‘links’!) –each link contains data items –each link also contains a pointer to the next in the chain start free?nextstartsizefree?nextstartsizefree?endstartsize

21 © LJMU, 2004CY2003- Week 0921 First Fit The linked list is initialised to a single link of the entire memory size, flagged as ‘free’ Whenever a block of memory is requested the linked list is scanned in order until a link is found which represents free space of sufficient size –if requested space is exactly the size of the free space all the space is allocated –else, the free link is split into two the first entry is set to the size requested and marked ‘used’ the second entry is set to remaining size and marked ‘free’ When a block is freed the link is marked ‘free’

22 © LJMU, 2004CY2003- Week 0922 Next Fit The first fit algorithm starts scanning at the start of the linked list whenever a block is requested As a minor variation, the next fit algorithm maintains a record of where it got to, in scanning through the list, each time an allocation is made –the next time a block is requested the algorithms restarts its scan from where ever it left off last time –the idea is to give an even chance to all of memory to getting allocated, rather than concentrating at the start However, simulations have shown that next fit actually gives worse performance than first fit!

23 © LJMU, 2004CY2003- Week 0923 Best Fit First fit just looks for the first available hole –it doesn’t take into account that there may be a hole later in the list that exactly fits the requested size –first fit may break up a big hole when the right size hole exists later on The best fit algorithm always searches the entire linked list to find the smallest hole big enough to satisfy the memory request –however, it is slower than first fit because of searching –surprisingly, it also results in more wasted memory! because it tends to fill up memory with tiny, useless holes

24 © LJMU, 2004CY2003- Week 0924 Summary Memory management concepts –memory types cache, primary and secondary –contiguous v. non-contiguous memory allocation –single user memory allocation Fixed partition multiprogramming –concepts Variable partition multiprogramming Allocation strategies


Download ppt "CY2003 Computer Systems Lecture 09 Memory Management."

Similar presentations


Ads by Google