Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Systems 2009-2010 Week 14: Memory Management Amanda Oddie.

Similar presentations


Presentation on theme: "Computer Systems 2009-2010 Week 14: Memory Management Amanda Oddie."— Presentation transcript:

1 Computer Systems 2009-2010 Week 14: Memory Management Amanda Oddie

2 2 Session Aims Understand how main memory (RAM) can be shared between programs running in time slices

3 3 Main Memory Programs can only execute efficiently if they are present in main memory during execution Only main memory is fast enough to feed the CPU with enough instructions and data to keep it usefully occupied. Thus main memory is a precious resource which must be managed carefully on a multiprogramming machine

4 4 Main Memory In addition to holding instructions RAM is also a workspace, a transient storage repository. Space must also be made available for: Operating System Code Operating System Data Video Storage Space etc

5 5 Imagine loading... Microsoft Windows Microsoft Internet Explorer An email Application Microsoft Word And listening to music using media player whilst you do all that multi-tasking! It doesn’t stop there. You need memory for your hardware. For example you require main memory to display images on your monitor

6 6 Not enough memory Each time a PROCESS starts it REQUESTS an amount of RAM The amount of total RAM requested is usually more than the amount of Physical RAM available in Multiprogramming Operating Systems such as Windows and Linux

7 7 Hard disk, Main memory and CPU CPU 0  ? Hard disk Fetch and execute Memory Load program into main memory Start executing the program

8 8 Single Process System Early method Operating system loaded first Just one user program loaded into locations above the operating system Inefficient use of memory – small programs leave much unused memory space UNUSED User Process Operating System Memory 0

9 9 Fixed Memory Partition Memory divided into fixed partitions Several programs could run simultaneously Space still wasted inside each partition Process C Process B Process A Operating System 100k 300k 600k Memory address Partition 1 200k Partition 2 300k Partition 3 400k 1000k Memory 0

10 10 Sharing by swapping Program and data copied into memory at beginning of each time slice copied back to disc at end of time slice All main memory available to program But, high overhead of swapping time

11 11 Solution Paging

12 12 Sharing by paging Divide program and data into pages normally resident on the hard disk Each page is typically 4kB in size Only swap in the pages needed during time slice Memory divided into pageframes Each pageframe can hold one page

13 13 Loading pages Pages can be loaded in any order Use a page table for each program to keep track of where in memory its pages are located

14 14 Translating addresses Given an instruction like JMP 314 314 means 314 locations from beginning of program This does not refer to a physical address in real memory but to a virtual address measured from the program start Assume each page 100 locations long JMP 314 means jump to page 3 offset 14 Where is the location in real memory ?

15 15 Virtual Memory The Operating System has a Memory Management Unit MMU that translates virtual addresses to physical addresses in RAM. This is known as Address Translation

16 16 Carrying out the translation JMP 314 Page number Real memory address: 2514 Page table

17 17 Page fault Interrupt generated when required page is not in main memory It causes: Required page to be fetched from disc into a spare pageframe If no pageframe is spare then an existing page must be freed up by copying its current contents back to the disk Page table updated Program continues

18 18 Thrashing Page faults are too frequent Most time spent swapping pages Caused by: Bad program design Too many programs attempting to run concurrently

19 19 Paging strategies Fetch strategy When to fetch a page Replacement strategy When to swap page out

20 20 Fetch strategies Demand fetch Anticipatory fetch

21 21 Replacement strategies Optimal page replacement Longest resident Least recently used Least frequently used

22 22 Page File The area of the hard disk that stores the RAM image is called a page file. It holds pages of RAM on the hard disk The Operating System moves data back and forth between the page file and RAM. Previous versions of Windows called this a swap file and had a.SWP extension.

23 23 Total Size of the Page File The size of the page file is based on how much RAM is installed in the computer. By default, Windows XP creates a page file which is 1.5 times the amount of installed RAM The page file is placed on the hard drive in the same folder as the Windows XP operating system

24 24 Question What is never paged out? The Kernel remains resident in RAM, This is never paged out.

25 25 Invalid Page Faults? The CPU trying to access an address out of range The CPU trying to access an address which is already occupied by a different process When the page that the CPU is trying to access does not exist in either RAM or VM

26 26 Invalid Page Faults Sometimes, through program or hardware error, the page is not there. The system then has an ‘Invalid Page Fault’ error. This will be a fatal error if detected in a program The Application is normally shut down by the Operating System

27 27 Improving Performance The page file is a reserved section of the hard drive where data may be written and retrieved as needed. Since the paging file and operating system files are by default located on the same drive, parallel access to both locations is impossible. One or the other has to wait, slowing down overall system performance. Moving the page file to another drive will improve performance.

28 28 Question How else could you improve performance? Installing more RAM

29 29 Memory Management in Windows Processes Memory Usage Virtual Memory Usage Performance Commit Charge Physical Memory Kernel Memory

30 30 Windows Task Manager Process Name Virtual Memory Usage Each Process has a Amount of Virtual Memory Limit of 4GB Physical Memory Usage

31 31 Commit Charge Physical Memory Kernel Memory

32 32 Question What is Fragmentation? The scattering of parts of a file throughout a disk, e.g. when the operating system breaks up the file and fits it into the spaces left vacant by previously deleted files.

33 33 Non-Contiguous Page Files Paging files are normally created when a drive is relatively empty finding a large contiguous block of space is not a problem. A page file is dynamic by default it can be expanded and contracted depending on the amount of extra virtual memory that's needed. If the initial block of drive space that was allocated at setup becomes surrounded by additional files that have been saved to the drive......a split page file can occur when the operating system expands it past the initial size.

34 34 Question How do you defragment files? Windows comes with a utility called Disk Defragmenter which will reorganise the files stored on disk

35 35 Question What creates the Page File? a) The CPU b) The RAM c) The Operating System d) It’s created by magic

36 36 Question What creates the Page File? a) The CPU b) The RAM c) The Operating System d) It’s created by magic Answer C: With help from the CPU

37 37 So What do we Know? Main memory (RAM) is a precious resource Every process and device requires RAM Virtual Memory through paging gives the impression that there is more RAM than physical RAM The Kernel is never Paged Out Paging is Managed by the Memory Management Unit (MMU) Page Faults are normal interrupts Invalid Page Faults are bad How to view Memory Allocation and Resources in Windows


Download ppt "Computer Systems 2009-2010 Week 14: Memory Management Amanda Oddie."

Similar presentations


Ads by Google