Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory management.

Similar presentations


Presentation on theme: "Memory management."— Presentation transcript:

1 Memory management

2 Memory Management - explain how memory is managed in a typical modern computer system, (virtual memory, paging and segmentation should be described along with some of the problems which could occur such as disk thrashing)

3 Memory Management – Virtual Memory
Primary memory has a limit i.e. how many RAM chips you have in the computer. But there is a trick that the memory manager can use to fool the operating system into thinking that there is more primary memory than is actually physically present. This trick is called virtual memory. As has been mentioned, all executing software needs to run in primary memory and is temporarily stored in segments. When the computer is running short of physical primary memory e.g. too many applications open, the memory manager has a choice. It can either shut down applications (very inconvenient) or it can try and scrounge some more memory from somewhere else. This is where virtual memory comes in. The memory manager will begin to use parts of secondary memory such as the hard disk or a Flash USB drive as primary memory.

4 Memory Management – Virtual Memory
Pages that have not been used for a while will be stored on the hard disk as virtual memory. This means that the pages are still available but will take some time to restore into primary memory. The benefit of doing this is to allow more applications to run than would be physically possible if you were only using RAM. While virtual memory will allow more applications to be open, it should be appreciated that a physical hard disk is being used and so applications will run far slower than if they were stored completely in RAM. In an examination question it is essential to remember the following: Virtual memory is making use of secondary memory (backing store) as if it were main memory. Virtual memory acts as an extended form of primary memory.

5 Memory Management - Paging
Paging is where relatively inactive pages are temporarily removed from physical memory and placed into virtual memory. In Windows 8, paging and virtual memory is still a controlled feature, although adjustment is now six layers deep within the relevant option menus. The screen capture below is for Windows XP, but the principle remains just the same even with the latest operating system versions. Paging happens when main memory is getting a bit full. The memory manager will look at the pages in main memory and identify those which haven't been used for a while. They will be moved into virtual memory. When an application needs data held on a page in virtual memory it will be swapped back into main memory and another inactive page may take its place. In order to manage these pages a 'page table' is created by the memory manager which stores the starting address of each page. The starting address is where the first byte of each page is physically located in memory.

6 Memory Management - Paging
Paging is possible because the memory manager divides primary memory into sections of equal size - called pages. The pages are efficiently set to be the same size as the sectors on the hard disk. To demonstrate why setting the page size to be the same size as a hard disk sector is efficient, consider a hard disk with a sector size of 4kb, but the memory manager has been set to have a page size of 6kb. When a page of data needs to be stored, it will have to occupy 2 sectors, and wastes the 2kb left over. So it is much more efficient for pages and hard disk sectors to be the same size. A page can be as little as 512 bytes or as large as 64kb or more.

7 Memory Management - Segmentation
Hard disks can be partitioned into different drives. However, primary (main) memory can also be split up. This is done in a completely different way to partitioning a hard disk. Make sure that you don't get confused between disk partitioning and memory partitioning. The memory manager is the part of the operating system that deals with memory. All applications need to be loaded into main memory before they can be executed. In order to do so, a temporary 'segment' is created by the memory manager. Every loaded application will have some instructions or program code for the CPU to execute. The loaded application will need a data area to hold its variables. It will also need a special area called 'the stack' to handle sub-routines and interrupts. It will also need some free memory within the segment to allow the stack to grow and shrink. A typical segment is shown here: The example segment above is 64kb in overall size but by no means is this a fixed size. You could have a segment smaller or larger than this.

8 Memory Management - Segmentation
Code segment, where the program code is stored Data segment, where variables defined by the code are stored whilst the application is running. Stack segment, starts from the top of the segment and grows downwards. The stack is used by sub-routines and interrupt service routines to hold temporary data and addresses. There can be many segments in memory at the same time. Each one is a separate process or application and each may be a different size. As shown here.

9 Memory Management - Threshing
Disk Thrashing is a problem that may occur when virtual memory is being used. As main memory fills up, then more and more pages need to be swapped in and out of virtual memory. This swapping leads to a very high rate of hard disk access. Compared to RAM, moving a hard disk head takes thousands of times longer. And so eventually more time is spent swapping the pages than on processing the data. If disk thrashing continues then most likely program will lock-up or not run.

10 Memory Management - Threshing
It doesn't do the hard disk any good either as it is being accessed rapidly (thousands of times per second) by the memory manager. Sometimes you can hear the disk whirring away when disk thrashing occurs. Usually the operating system will warn the user of 'Low virtual memory' to encourage them to shut down a few applications before everything grinds to a halt.

11 Task… Page sizes are traditionally 4Kb, but modern systems offer the option of significantly larger page sizes. Discuss what the advantages and disadvantages might be of larger page sizes. Describe what is meant by disk thrashing Explain why adding RAM to a computer system can improve its performance. Create a 20 question exam paper on Memory Management. Include 1,2 and 3 marks questions and remember the answers!!


Download ppt "Memory management."

Similar presentations


Ads by Google