1 / 23

T111

T111. Memory Management. Computer Registers. very fast, very expensive, small capacity. Executable memory. Requires constant power hence short term. CPU Cache Memory. very fast, expensive, small capacity. RAM. fast, affordable, medium capacity. Flash memory.

Télécharger la présentation

T111

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. T111 Memory Management

  2. Computer Registers very fast, very expensive, small capacity Executable memory. Requires constant power hence short term. CPU Cache Memory very fast, expensive, small capacity RAM fast, affordable, medium capacity Flash memory slower, cheaper, medium capacity Hard disk drive slow, very cheap, very large capacity Non-Executable memory. No power required for retention hence long term. Optical memory very slow, cheap, medium capacity Tape drive very slow, affordable, very large capacity Re-cap

  3. Address bus CPU RAM Data bus Re-cap • Available RAM = 2 to the power of memory bus bits • Eg. 20 bit bus = 1048576 Bytes /1024 = 1024KB

  4. Re-cap • Address bus determines the amount of memory that can be addressed • CPU and OS can be factors • Other devices such as video cards can reduce the memory that can be used in 32 OS’s • Addresses in Hex

  5. Why do we need Memory Management? • Can you think of a reason to need memory management? Process A RAM Process B

  6. i 0700006b 5 Memory Management • When a programmer writes an instruction i=5 • The compiler will allocate an area of RAM (an address) for the variable i and then put the number 5 in this location • Suppose that the compiler decides that the variable i is to be stored at address 0700006b, the situation looks like this:

  7. Memory Management • How does the compiler know where to put the variables (which addresses to use)? • How can it be sure that the location is not already in use? • How can it be sure that there is actually some RAM at this address? • In a multi-tasking operating system, how can it be sure that there aren’t two copies of the same program running and both using the same location to store the value of i?

  8. Reducing the Address Space • Artificially reducing the address space available to a process • 32 bit addressing allows for addressing:00000000-FFFFFFFF 00000000 RAM 20000000 FFFFFFFF

  9. 01000000 RAM Process A 01ffffff 02000000 RAM Process B 02ffffff Memory Management • The operating system allocates a small portion of the address space for each process to use • For example – Process A will start at address 01000000h • Process B uses 02000000h as its’ starting address

  10. 01000000 RAM 000000 Process A ffffff 01ffffff 02000000 000000 RAM Process B ffffff 02ffffff Memory Management • Now with the processes separated in RAM, they can operate in their own section of RAM • Each process operates in an offset address so the situation looks like this:

  11. Benefits of reducing the address space • Makes life easier for the programmer / compiler • Programs don’t clash with each other (provided they stay in their allocated space) • The operating system will only allocate addresses that actually have RAM assigned to them • Eg. If there was no RAM between 0a000000 and ffffffff then the operating system would not put a process at these addresses

  12. Exercise 1

  13. Problem! • Multi-tasking operating systems run more than one program at a time • Example 1: • You have 16MB of RAM • You want to have ten processes loaded into memory • Each process requires 2MB of RAM • What will happen?

  14. Problem! • Example 2: • A programmer is writing a program that requires a large amount of memory • The programmer doesn’t know how much RAM is in your computer • How do they know how much memory is available for the program to use?

  15. Program A Program A’s memory area Program B Program B’s memory area Problem! • Example 3: • Program A has a fault and it changes another part of the memory that is used by Program B • This is likely to cause problems for Program B and Program A • This is a problem of protection

  16. 00000000 Virtual memory Process A 00000000 Actual memory (RAM) Operating system 7fffffff 00000000 Virtual memory Process B afffffff Virtual Memory • Each process “believes” that it is accessing the real RAM.

  17. Virtual Memory Benefits… • The programmer’s life is much easier because they can now address any part of the virtual RAM without fear of conflicting with another program • Each process is running in isolation • Each process OR thread can address exactly the same virtual memory addresses whilst actually addressing different physical RAM

  18. Problem! • You have 3 GB of RAM • Two processes each use 2 GB of RAM(with virtual memory this is possible) • How does the operating system manage to trick the processes into thinking that they each have enough RAM?

  19. Memory Pages Wikipedia.org

  20. Memory Pages • Memory is allocated in pages not bytes • Typical page size = 4,096 Bytes • Simplifies memory management

  21. Memory Pages • When a process accesses a page of virtual memory, the operating system allocates a page of real memory to that virtual space • If a process does not address a page of virtual memory, then the operating system does not allocate any physical RAM at all to this virtual page • The virtual memory has holes in it! …but the process does not realise

  22. Memory Pages • How big is the virtual address space? •  How big is the physical RAM?

  23. 00000000 Virtual memory Process A 00000000 Actual memory (RAM) Operating system 7fffffff 00000000 Virtual memory Process B afffffff Review • Reducing memory space • Address offset • Virtual Memory • Memory Pages

More Related