What is the 'virtual memory' mechanism that manages the memory of a computer?



When choosing a computer, you may have heard the opinion that 'more

RAM is better'. RAM is a high-speed memory that is used as the main memory of the computer and is directly accessed by the CPU. The ' Internal Pointers ' blog dealing with mathematics, IT, finance, etc. explains ' virtual memory, ' which is an important mechanism for handling RAM.

An introduction to virtual memory-Internal Pointers
https://www.internalpointers.com/post/introduction-virtual-memory

Modern computers are generally equipped with RAM, which is the main memory, and HDDs and SSDs, which are the auxiliary storage devices, as storage media. HDDs and SSDs are suitable for storing large amounts of data, but they have the disadvantage that the read / write speed is too slow for the CPU to access them directly. RAM is a high-speed memory that mediates the exchange of data between the CPU and auxiliary storage device and resolves the speed difference.

RAM holds programs and data in units called memory addresses, and each memory address is given a number. The range of memory addresses where programs and data are stored is called address space, and it is explained that the CPU relies on memory addresses to read and write programs and data.



According to a

paper (PDF) by Peter J. Denning of George Mason University , programmers in the days when computers soon appeared were running programs by directly specifying the memory address of RAM. However, with the advent of multitasking that allows multiple programs to run simultaneously on a single computer, memory management has become complicated. In order to simplify the memory management for programmers, it is explained that 'virtual memory' was created as a mechanism to automatically perform memory management.

'Virtual memory' is a mechanism that allows users to program without worrying about the actual RAM address space by associating a virtual address with a physical address that is the actual RAM address. University of Illinois at Chicago of explanation according to, because the program has a separate virtual address space, that of that there is no need to worry about the arrangement of the physical address space for each program. Another advantage of virtual memory is that it solves the limitation of physical memory capacity.



In virtual memory, memory is linked in block units that are delimited by certain memory addresses. A block with a virtual address is called a page and a block with a physical address is called a frame. This page and frame are linked to each other in the form of a table, which is a page table. The CPU's

memory management unit (MMU) refers to the page table and translates virtual addresses to physical addresses.



The MMU translates a virtual address to a physical address by referring to the information of the page to which the virtual address belongs and the in-page offset indicating where the target physical address is in the corresponding frame. A

page fault occurs when the physical address is not linked to the virtual address accessed by the program, such as when a new frame cannot be allocated due to lack of RAM capacity, and the MMU is a mechanism that notifies the OS of the occurrence of the page fault.

Paging is the idea to secure RAM capacity by linking virtual addresses and physical addresses with not only RAM but also HDD and SSD. It is explained that the paging allows the OS to secure a larger virtual address space than the physical address space, and temporarily save programs and data to the auxiliary storage device when a page fault occurs.

However, when paging is used to hold programs and data in the auxiliary storage device, the program must be read from the auxiliary storage device, which has a slow read / write speed, into RAM, which reduces the OS read / write speed. Thrashing refers to the inability of an application to operate as a result of the computer's processing power being exhausted by the inability to allocate new frames due to lack of RAM, etc., and the constant page faults. According to the IT media 'IT Pro Today ', thrashing can be dealt with by increasing the RAM capacity and optimizing the page file size.



Virtual memory also protects memory between programs. Memory protection is typically done by the MMU, which causes invalid page faults such as segmentation and access violations when accessing virtual memory that the program does not own. The OS is said to protect the memory by receiving an invalid page fault notification from the MMU and exiting the program.

It is said that there are many things to consider when measuring the memory consumption of a computer, whether it is virtual or physical, and whether it is paged to auxiliary storage.

in Software,   Hardware, Posted by darkhorse_log