Virtual Memory: Difference between revisions
No edit summary |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
==Virtual Memory== | ==Virtual Memory== | ||
Virtual mermory is system memory which is simulated by the hard drive. In the case that all of the RAM is used up, the computer can simulate extra memory by swapping data to the hard drive and back, giving an impression that there is more memory. Extending memory can be done by other ways including overlays and swapping. | Virtual mermory is system memory which is simulated by the hard drive. In the case that all of the RAM is used up, the computer can simulate extra memory by swapping data to the hard drive and back, giving an impression that there is more memory. Extending memory can be done by other ways including overlays and swapping.[3] | ||
==Swapping== | ==Swapping== | ||
A technique that enables computer to execute programs and manipulate data files larger than main memory. An operating system copies as much data as possible into main memory leaving the rest on disk. When it needs data from disk , thsi data exchanges a portion of data (page or segment) in main memory with a portion of data on disk [1] | |||
A memory management technique where a process may periodically have its primary memory space deallocated. This forces the swapped-out process to compete for memory before it can once again compete for the processor | A memory management technique where a process may periodically have its primary memory space deallocated. This forces the swapped-out process to compete for memory before it can once again compete for the processor | ||
Line 13: | Line 14: | ||
==Overlays== | ==Overlays== | ||
This technique allows programs to be larger than the CPU's main memory. In this method a program is divided into self-contained object code blocks called overlays where the size of the overlay is limited according to memory constraints. The place where overlays are loaded are refered to as 'regions' ( | This technique allows programs to be larger than the CPU's main memory. In this method a program is divided into self-contained object code blocks called overlays where the size of the overlay is limited according to memory constraints. The place where overlays are loaded are refered to as 'regions' (R1/R2 in the diagram). These regions can be of a different size. An overlay manager, such as an operating system loads the required overlay from external memory into this region. [3] | ||
[[Image:diagram2.jpg]] | [[Image:diagram2.jpg]] | ||
Line 40: | Line 41: | ||
;'''Data fragmentation''' | ;'''Data fragmentation''' | ||
Reduces the amount of fragmentation in file systems. Occurs when a piece of data in memory is broken up into many pieces. Two types of fragmentation which exist are internal fragmentation and external fragmentation | Reduces the amount of fragmentation in file systems. Occurs when a piece of data in memory is broken up into many pieces. Two types of fragmentation which exist are internal fragmentation and external fragmentation [2] | ||
;'''Internal Fragmentation''' | ;'''Internal Fragmentation''' | ||
Space is wasted in return for increased efficiency or simplicity. An example is that many file systems files always start at the beginning of a sector, which simplifies organization and makes it easier to grow files. Any space that is left over between the last byte of the file and the first byte of the next sector is internal fragmentation. Internal fragmentation occurs when the index pages are not being used to their maximum volume | Space is wasted in return for increased efficiency or simplicity. An example is that many file systems files always start at the beginning of a sector, which simplifies organization and makes it easier to grow files. Any space that is left over between the last byte of the file and the first byte of the next sector is internal fragmentation. Internal fragmentation occurs when the index pages are not being used to their maximum volume [2] | ||
;'''External Fragmentation''' | ;'''External Fragmentation''' | ||
Line 57: | Line 58: | ||
==Paging== | ==Paging== | ||
A memory allocation strategy using fixed-length pages as opposed to variable-length segments. Every process’s virtual address space is logically divided into pages. | |||
Main function of paging are performed when a program tries to access pages that do not currently reside in RAM, this is a situation which causes page fault. | |||
The main functions of paging are: | |||
1. Handles the page fault, in a manner invisible to the causing program, and takes control. | |||
2. Determines the location of the data in auxiliary storage. | |||
3. Determines the page frame in RAM to use as a container for the data. | |||
4. If a page currently residing in chosen frame has been modified since loading (if it is dirty), writes the page to auxiliary storage. | |||
5. Loads the requested data into the available page. | |||
6. Returns control to the program, transparently retrying the instruction that caused page fault. | |||
[3] | |||
[[Image:The_address_space_and_pages.JPG]] | [[Image:The_address_space_and_pages.JPG]] | ||
==Paging Algorithms== | ==Paging Algorithms== | ||
Line 92: | Line 104: | ||
''Edited by Dmitrii Miyusov '' | ''Edited by Dmitrii Miyusov '' | ||
Rerefeces: | |||
[1] http://www.ptdd.com/datarecovery/swap.htm | |||
[2] Nutt, Gary (2004). Operating systems. Boulder Colorado. | |||
[3] http://wikipedia.org/ |
Latest revision as of 23:22, 20 November 2007
Virtual Memory Lecture 10
Virtual Memory
Virtual mermory is system memory which is simulated by the hard drive. In the case that all of the RAM is used up, the computer can simulate extra memory by swapping data to the hard drive and back, giving an impression that there is more memory. Extending memory can be done by other ways including overlays and swapping.[3]
Swapping
A technique that enables computer to execute programs and manipulate data files larger than main memory. An operating system copies as much data as possible into main memory leaving the rest on disk. When it needs data from disk , thsi data exchanges a portion of data (page or segment) in main memory with a portion of data on disk [1] A memory management technique where a process may periodically have its primary memory space deallocated. This forces the swapped-out process to compete for memory before it can once again compete for the processor
Swapping is especially well suited to timesharing systems since such systems often have times when a user logs onto the machine but is inactive for relatively long periods ( and hence not using the CPU).
Overlays
This technique allows programs to be larger than the CPU's main memory. In this method a program is divided into self-contained object code blocks called overlays where the size of the overlay is limited according to memory constraints. The place where overlays are loaded are refered to as 'regions' (R1/R2 in the diagram). These regions can be of a different size. An overlay manager, such as an operating system loads the required overlay from external memory into this region. [3]
Significant problem with overlays is 'when exactly do you load x, y or z?'. Developers need to think carefully what they put in these modules. Another problem is that x, y, and z can’t talk to each other, they need some sort of cut / paste buffer. The problem is that x, y and z are different sizes and we need to fit the biggest one in the overlay area.
x,y and z are all desired to be loaded in the same area of RAM. In traditional overlay schemes this would be an index.
Classic problem of memory management: Fragmentation - difference between size of overlay area and size of the overlays
Instead of having one overlay area what if we had many?
This is primitive because programming manually has to manage memory in addition to being inefficient. How do you deal with the situation so that you don’t need to deal with it every again? First step is to change this and to add relocation. To do that we need to have some sort of indirection
Fragmentation
- Data fragmentation
Reduces the amount of fragmentation in file systems. Occurs when a piece of data in memory is broken up into many pieces. Two types of fragmentation which exist are internal fragmentation and external fragmentation [2]
- Internal Fragmentation
Space is wasted in return for increased efficiency or simplicity. An example is that many file systems files always start at the beginning of a sector, which simplifies organization and makes it easier to grow files. Any space that is left over between the last byte of the file and the first byte of the next sector is internal fragmentation. Internal fragmentation occurs when the index pages are not being used to their maximum volume [2]
- External Fragmentation
In such a fragmentation, the free space which is available for storage is divided into many small pieces. The storage space is of many different sizes.
- Page
fixed-length block of main memory, that is contiguous in both physical addressing and virtual memory addressing.
Memory Segmentation
Technique used to divide memory into smaller units. It is an extension of the ideas suggested by the use of relocation-limit registers for relocating and bound checking blocks of memory. Memory contents are referenced using a two-component virtual address <segmentNumber, offset> . Segment number identifies the particular logical block of memory and offset is a linear offset from the beginning of the segment. Segmentation provides more programmer control over the units of transfer in the memory system than paging does. Memory segments are distinct from memory pages because the segments are usually much larger than pages, and can be of a variable size.
Paging
A memory allocation strategy using fixed-length pages as opposed to variable-length segments. Every process’s virtual address space is logically divided into pages. Main function of paging are performed when a program tries to access pages that do not currently reside in RAM, this is a situation which causes page fault. The main functions of paging are:
1. Handles the page fault, in a manner invisible to the causing program, and takes control.
2. Determines the location of the data in auxiliary storage.
3. Determines the page frame in RAM to use as a container for the data.
4. If a page currently residing in chosen frame has been modified since loading (if it is dirty), writes the page to auxiliary storage.
5. Loads the requested data into the available page.
6. Returns control to the program, transparently retrying the instruction that caused page fault. [3]
Paging Algorithms
There are two basic types of pagig algorithms: static and dynamic allocation
Static Paging algorithms
allocates a fixed number of page frames to a process when it is created. The paging policy defines how these page frames will be loaded and unloaded by the virtual memory system.
Three basic policies in defining paging algorithm are
fetch policy: when a page should be loaded into memory
replacement policy: determines which page should be removed from primary memory if all page frames are full
placement policy: determines where the fetched page whould be loaded into primary memory
Dynamic Paging algorithms
Dynamic paging algorithms adjust the memory allocation to match the process's needs as they change.
Edited by Dmitrii Miyusov
Rerefeces:
[1] http://www.ptdd.com/datarecovery/swap.htm
[2] Nutt, Gary (2004). Operating systems. Boulder Colorado.