Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.3.1.4 Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described.

Similar presentations


Presentation on theme: "3.3.1.4 Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described."— Presentation transcript:

1 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 threshing. ICTessentials.com

2 Function of memory management:
Memory management is the process by which a computer allocates a limited amount of physical memory, among the various processes that need it, in a way that optimises performance. Function of memory management: allocate main memory to a process or to several processes that are to be executed concurrently; allocate memory to data; protect the memory used by the operating system itself; protect processes from each other when executing concurrently – i.e. to prevent two processes from using the same memory at the same time; allow shared access to some areas of memory; free up memory when processes are unloaded – and reallocate it to new processes. Memory management is performed by the part of the operating system known as the memory management sub-system. It also deals with virtual memory, segmentation and paging

3 Loading a program into main memory
This task is performed by a program called a loader. There are two basic types – an absolute loader and a relocating loader. Absolute loader This loads the program into a fixed area of memory. This occurs when all address references have been fixed at the time of assembly or compilation. A potential problem is that two programs may require loading into the same area of memory – this would mean that loading the second program would cause the first program to crash. An absolute loader is only effective with simple systems that run only one or two specially-written programs. Relocating loader This can load a program into any area of memory. This is possible when the program has been assembled or compiled in such a way that all addresses are relative to the start of the program. When loaded, the start address of the program is put into the a base register and all other addresses are calculated relative to this.

4 Virtual memory Virtual memory is the use of the backing store (i.e. hard disk), to simulate additional main memory, in order to overcome the limitations in the amount of main memory that is available. Virtual memory allows a computer to operate as if it had more memory than it actually does, but with some loss of performance. Virtual memory is necessary to: allow programs to run that need more memory than is available; allow multiple programs to run which have combined memory requirements more than the main memory available. Virtual memory will, in some way, split a program into blocks and load the blocks that are needed, when they are needed – constantly swapping blocks between main memory and the backing store. The two normal methods of splitting the programs into blocks are known as segmentation and paging.

5 Segmentation Segmentation is when main memory is divided into variable sized blocks called segments where each segment corresponds to a program routine (e.g. a subroutine or procedure) or a data structure/array. Each segment corresponds to a logical division of code or data, where all the code or data that is needed is contained within the segment. Each segment is protected so only routines that have the appropriate ‘permissions’ can access it. The segments may be placed anywhere in main memory, but the instructions or data in any one segment are contiguous. When a different program routine or data is needed, it is loaded as a segment and, if necessary one of the existing segments is replaced.

6 Segmentation

7 Segmentation When segments are replaced, a single segment can only be replaced by a segment of the same size or smaller. Each time a segment is replaced by one that is smaller, a small gap will be left. The accumulation of these small gaps eventually results in ‘memory fragmentation’. This makes it difficult to load large segments because there are not enough large contiguous memory locations. To overcome this fragmentation problem, segments are ‘pushed together’ occasionally to create large contiguous areas and allow large segments to be loaded. Apart from memory fragmentation, segmentation is usually very efficient because entire blocks of code are available to the processor. Also, it is easy for two processes to share the same code – if the same procedure is used by two processes concurrently, there need only be a single copy of the code segment in memory (however, each process would maintain its own, distinct data segment).

8 Paging Paging is when main memory is divided into fixed size blocks called page-frames and programs are divided into blocks of the same size, called pages – pages are swapped’ between the disk and the page-frames as necessary. Each frame is a physical division of memory – this can be any size, but 4 Kbytes is typical; The pages do not need to be loaded into contiguous areas of memory; A ‘Page Management Table’ stores details of which pages are loaded and where; Pages are ‘swapped’ between the disk and main memory as required – note that pages are not simply replaced, they are copied back to disk before being over-written in memory.

9 Paging When the OS needs a physical page frame to store a page, and there are none free, it selects one of the pages that is not currently being used and stores it back to disk. It can then use the freed page frame for the new page.

10 Page Management Table The Page Management Table (Page Table, PMT) maintains an index of the contents of the page frames. Each time a page is loaded, the page table is updated. As well as the page that a frame contains, some other attributes are also usually stored. For example, some pages may be characterized as read-only, read-write, etc. It is also common to include information about access privileges, to help ensure that one program does not inadvertently corrupt data for another program. It is also usual to have a bit (known as the ‘dirty’ bit) which indicates whether or not a page has been changed while in memory – if this ‘dirty’ bit is set, then the page must be written back to the disk before it is replaced by another page.

11 Virtual memory summary
Benefits Drawbacks it allows programs to run that need more memory than is available; it allows multiple programs to run which have combined memory requirements more than the main memory available. it takes time to swap segments/pages between main memory and the hard disk – this is much slower than if the whole program were loaded into memory; in segmentation, memory becomes fragmented and so large segments cannot be loaded; in paging, memory is used for storing the page table – if the page-frames are small, the page table may take up a significant portion of memory.

12 Segmentation vs. Paging
Similarities In practice, paging is a type of segmentation. They both: • allow programs to run when there is not enough physical (main) memory available; • provide a means by which only part of a program needs to be in memory; • split programs into blocks which are stored on disk; • split memory into blocks; • swap segments and pages between disk and memory when necessary. Differences Segmentation Paging Segments are variable in size Segments are logical divisions of code/data Segments are complete sections of programs – e.g. procedures or functions, or even complete data structures All page-frames/pages are of a fixed size Pages are physical divisions of memory Pages are made to fit sections of memory and will only contain part of the executing code/data Pages are usually smaller (4 Kbytes)

13 Disk threshing Disk threshing (also known as ‘thrashing) is when a high rate of disk access occurs while moving pages between memory and disk, so more time is spent on transferring pages than is spent on processing. Threshing occurs because disk access is relatively slow and pages need to be swapped regularly: when there are lots of jump routines; when there are lots of processes running – each process only has a few of its pages in memory at a time. Solutions to threshing: reduce the number of running applications; add more physical memory.


Download ppt "3.3.1.4 Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described."

Similar presentations


Ads by Google