Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of the main memory. The addresses a program may use to tát reference memory are distinguished from the addresses the memory system uses to tát identify physical storage sites and program-generated addresses are translated automatically to tát the corresponding machine addresses.
What is Virtual Memory?
Virtual memory is a memory management technique used by operating systems to tát give the appearance of a large, continuous block of memory to tát applications, even if the physical memory (RAM) is limited. It allows the system to tát compensate for physical memory shortages, enabling larger applications to tát run rẩy on systems with less RAM.
A memory hierarchy, consisting of a computer system’s memory and a disk, enables a process to tát operate with only some portions of its address space in memory. A virtual memory is what its name indicates- it is an illusion of a memory that is larger phàn nàn the real memory. We refer to tát the software component of virtual memory as a virtual memory manager. The basis of virtual memory is the noncontiguous memory allocation model. The virtual memory manager removes some components from memory to tát make room for other components.
The size of virtual storage is limited by the addressing scheme of the computer system and the amount of secondary memory available not by the actual number of main storage locations.
The History of Virtual Memory
Before virtual memory, computers used RAM and secondary memory for data storage. Early computers used magnetic core in place of main memory and magnetic drums in place of secondary memory. In the 1940s and 1950s, computer memory was very expensive and limited in size. As programs became larger and more complex, developers had to tát worry that their programs might use up all the available memory and cause the computer to tát run rẩy out of space to tát work.
In those early days, if program was larger phàn nàn available space then programmers use the concept of overlaying. If some portion of the code that is not currently used move to tát overlying if needed it back overwritten to tát memory this cause extensive programming. This is the reason for developing virtual memory.
In 1956, German physicist Fritz-Rudolf Güntsch develop virtual memory. The first real example of a virtual memory system was created at the University of Manchester in England while developing the Atlas computer. This system used a method called paging, which allowed virtual addresses (used by programs) to tát be mapped to tát the computer’s main memory. The Atlas computer was built in 1959 and started working in 1962.
The first computer with virtual memory was released by Burroughs Corp in 1961. This version of virtual memory bởi not using paging it oppose paging but tư vấn segmentation.
How Virtual Memory Works?
Virtual Memory is a technique that is implemented using both hardware and software. It maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory.
- All memory references within a process are logical addresses that are dynamically translated into physical addresses at run rẩy time. This means that a process can be swapped in and out of the main memory such that it occupies different places in the main memory at different times during the course of execution.
- A process may be broken into a number of pieces and these pieces need not be continuously located in the main memory during execution. The combination of dynamic run-time address translation and the use of a page or segment table permits this.
If these characteristics are present then, it is not necessary that all the pages or segments are present in the main memory during execution. This means that the required pages need to tát be loaded into memory whenever required. Virtual memory is implemented using Demand Paging or Demand Segmentation.
Types of Virtual Memory
In a computer, virtual memory is managed by the Memory Management Unit (MMU), which is often built into the CPU. The CPU generates virtual addresses that the MMU translates into physical addresses.
There are two main types of virtual memory:
- Paging
- Segmentation
Paging
Paging divides memory into small fixed-size blocks called pages. When the computer runs out of RAM, pages that aren’t currently in use are moved to tát the hard drive, into an area called a swap tệp tin. The swap tệp tin acts as an extension of RAM. When a page is needed again, it is swapped back into RAM, a process known as page swapping. This ensures that the operating system (OS) and applications have enough memory to tát run rẩy.
Demand Paging: The process of loading the page into memory on demand (whenever a page fault occurs) is known as demand paging. The process includes the following steps are as follows:
Demand Paging
- If the CPU tries to tát refer to tát a page that is currently not available in the main memory, it generates an interrupt indicating a memory access fault.
- The OS puts the interrupted process in a blocking state. For the execution to tát proceed the OS must bring the required page into the memory.
- The OS will tìm kiếm for the required page in the logical address space.
- The required page will be brought from logical address space to tát physical address space. The page replacement algorithms are used for the decision-making of replacing the page in physical address space.
- The page table will be updated accordingly.
- The signal will be sent to tát the CPU to tát continue the program execution and it will place the process back into the ready state.
Hence whenever a page fault occurs these steps are followed by the operating system and the required page is brought into memory.
What is Page Fault Service Time?
The time taken to tát service the page fault is called page fault service time. The page fault service time includes the time taken to tát perform all the above six steps.
Let Main memory access time is: m
Page fault service time is: s
Page fault rate is : p
Then, Effective memory access time = (p*s) + (1-p)*m
Segmentation
Segmentation divides virtual memory into segments of different sizes. Segments that aren’t currently needed can be moved to tát the hard drive. The system uses a segment table to tát keep track of each segment’s status, including whether it’s in memory, if it’s been modified, and its physical address. Segments are mapped into a process’s address space only when needed.
Combining Paging and Segmentation
Sometimes, both paging and segmentation are used together. In this case, memory is divided into pages, and segments are made up of multiple pages. The virtual address includes both a segment number and a page number.
Virtual Memory vs Physical Memory
Feature | Virtual Memory | Physical Memory (RAM) |
---|---|---|
Definition | An abstraction that extends the available memory by using disk storage | The actual hardware (RAM) that stores data and instructions currently being used by the CPU |
Location | On the hard drive or SSD | On the computer’s motherboard |
Speed | Slower (due to tát disk I/O operations) | Faster (accessed directly by the CPU) |
Capacity | Larger, limited by disk space | Smaller, limited by the amount of RAM installed |
Cost | Lower (cost of additional disk storage) | Higher (cost of RAM modules) |
Data Access | Indirect (via paging and swapping) | Direct (CPU can access data directly) |
Volatility | Non-volatile (data persists on disk) | Volatile (data is lost when power is off) |
What is Swapping?
Swapping is a process out means removing all of its pages from memory, or marking them so sánh that they will be removed by the normal page replacement process. Suspending a process ensures that it is not runnable while it is swapped out. At some later time, the system swaps back the process from the secondary storage to tát the main memory. When a process is busy swapping pages in and out then this situation is called thrashing.
Swappinghierar
What is Thrashing?
At any given time, only a few pages of any process are in the main memory, and therefore more processes can be maintained in memory. Furthermore, time is saved because unused pages are not swapped in and out of memory. However, the OS must be clever about how it manages this scheme. In the steady state practically, all of the main memory will be occupied with process pages, so sánh that the processor and OS have direct access to tát as many processes as possible. Thus when the OS brings one page in, it must throw another out. If it throws out a page just before it is used, then it will just have to tát get that page again almost immediately. Too much of this leads to tát a condition called Thrashing. The system spends most of its time swapping pages rather phàn nàn executing instructions. So a good page replacement algorithm is required.
In the given diagram, the initial degree of multiprogramming up to tát some extent of point(lambda), the CPU utilization is very high and the system resources are utilized 100%. But if we further increase the degree of multiprogramming the CPU utilization will drastically fall down and the system will spend more time only on the page replacement and the time taken to tát complete the execution of the process will increase. This situation in the system is called thrashing.
Causes of Thrashing
Thrashing occurs in a computer system when the CPU spends more time swapping pages in and out of memory phàn nàn executing actual processes. This happens when there is insufficient physical memory, causing frequent page faults and excessive paging activity. Thrashing reduces system performance and makes processes run rẩy very slowly. There are many cause of thrashing as discussed below.
1. High Degree of Multiprogramming: If the number of processes keeps on increasing in the memory then the number of frames allocated to tát each process will be decreased. So, fewer frames will be available for each process. Due to tát this, a page fault will occur more frequently and more CPU time will be wasted in just swapping in and out of pages and the utilization will keep on decreasing.
For example:
Let miễn phí frames = 400
Case 1: Number of processes = 100
Then, each process will get 4 frames.
Case 2: Number of processes = 400
Each process will get 1 frame.
Case 2 is a condition of thrashing, as the number of processes is increased, frames per process are decreased. Hence CPU time will be consumed just by swapping pages.
2. Lacks of Frames: If a process has fewer frames then fewer pages of that process will be able to tát reside in memory and hence more frequent swapping in and out will be required. This may lead to tát thrashing. Hence a sufficient amount of frames must be allocated to tát each process in order to tát prevent thrashing.
Recovery of Thrashing
- Do not allow the system to tát go into thrashing by instructing the long-term scheduler not to tát bring the processes into memory after the threshold.
- If the system is already thrashing then instruct themid-term scheduler to tát suspend some of the processes so sánh that we can recover the system from thrashing.
Performance in Virtual Memory
- Let p be the page fault rate( 0 <= p <= 1).
- if p = 0 no page faults
- if p =1, every reference is a fault.
Effective access time (EAT) = (1-p)* Memory Access Time + p * Page fault time.
Page fault time = page fault overhead + swap out + swap in +restart overhead
The performance of a virtual memory management system depends on the total number of page faults, which depend on “paging policies” and “frame allocation“
Frame Allocation
A number of frames allocated to tát each process in either static or dynamic.
- Static Allocation: The number of frame allocations to tát a process is fixed.
- Dynamic Allocation: The number of frames allocated to tát a process changes.
Paging Policies
- Fetch Policy: It decides when a page should be loaded into memory.
- Replacement Policy: It decides which page in memory should be replaced.
- Placement Policy: It decides where in memory should a page be loaded.
What are the Applications of Virtual memory?
Virtual memory has the following important characteristics that increase the capabilities of the computer system. The following are five significant characteristics of Lean.
- Increased Effective Memory: One major practical application of virtual memory is, virtual memory enables a computer to tát have more memory phàn nàn the physical memory using the disk space. This allows for the running of larger applications and numerous programs at one time while not necessarily needing an equivalent amount of DRAM.
- Memory Isolation: Virtual memory allocates a unique address space to tát each process and that also plays a role in process segmentation. Such separation increases safety and reliability based on the fact that one process cannot interact with and or modify another’s memory space through a mistake, or even a deliberate act of vandalism.
- Efficient Memory Management: Virtual memory also helps in better utilization of the physical memories through methods that include paging and segmentation. It can transfer some of the memory pages that are not frequently used to tát disk allowing RAM to tát be used by active processes when required in a way that assists in efficient use of memory as well as system performance.
- Simplified Program Development: For case of programmers, they don’t have to tát consider physical memory available in a system in case of having virtual memory. They can program ‘as if’ there is one big block of memory and this makes the programming easier and more efficient in delivering more complex applications.
How to tát Manage Virtual Memory?
Here are 5 key points on how to tát manage virtual memory:
1. Adjust the Page File Size
- Automatic Management: All contemporary operating systems including Windows contain the auto-configuration option for the size of the empirical page tệp tin. But depending on the size of the RAM, they are mix automatically, although the user can manually adjust the page tệp tin size if required.
- Manual Configuration: For tuned up users, the setting of the custom size can sometimes boost up the performance of the system. The initial size is usually advised to tát be mix to tát the minimum value of 1. To mix the size of the swap space equal to tát 5 times the amount of physical RAM and the maximum size 3 times the physical RAM.
2. Place the Page File on a Fast Drive
- SSD Placement: If this is feasible, the page tệp tin should be stored in the SSD instead of the HDD as a storage device. It has better read and write times, and the virtual memory may prove benefecial in an SSD.
- Separate Drive: Regarding systems having multiple drives involved, the page tệp tin needs to tát be placed on a different drive phàn nàn the os and that shall in turn improve its performance.
3. Monitor and Optimize Usage
- Performance Monitoring: Employ the software tools used in monitoring the performance of the system in tracking the amounts of virtual memory. High page tệp tin usage may signify that there is a lack of physical RAM or that virtual memory needs a change of settings or addition in physical RAM.
- Regular Maintenance: Make sure there is no toolbar or other application running in the background, take time and uninstall all the tool bars to tát miễn phí virtual memory.
4. Disable Virtual Memory for SSD
- Sufficient RAM: If for instance your system has a big physical memory, for example 16GB and above then it would be advised to tát freeze the page tệp tin in order to tát minimize SSD usage. But it should be done, in my opinion, carefully and only if the additional signals that one decides to tát feed into his applications should not likely use all the available RAM.
5. Optimize System Settings
- System Configuration: Change some general properties of the system concerning virtual memory efficiency. This also involves enabling additional control options in Windows such as adjusting additional system setting option on the operating system, or using other options in different operating systems such as Linux that provides different tools and commands to tát help in adjusting how virtual memory is utilized.
- Regular Updates: Ensure that your drivers are run rẩy in their newest version because new releases contain some enhancements and issues regarding memory management.
What are the Benifits of Using Virtual Memory?
- Many processes maintained in the main memory.
- A process larger phàn nàn the main memory can be executed because of demand paging. The OS itself loads pages of a process in the main memory as required.
- It allows greater multiprogramming levels by using less of the available (primary) memory for each process.
- It has twice the capacity for addresses as main memory.
- It makes it possible to tát run rẩy more applications at once.
- Users are spared from having to tát add memory modules when RAM space runs out, and applications are liberated from shared memory management.
- When only a portion of a program is required for execution, tốc độ has increased.
- Memory isolation has increased security.
- It makes it possible for several larger applications to tát run rẩy at once.
- Memory allocation is comparatively cheap.
- It doesn’t require outside fragmentation.
- It is efficient to tát manage logical partition workloads using the CPU.
- Automatic data movement is possible.
What are the Limitation of Virtual Memory?
- It can slow down the system performance, as data needs to tát be constantly transferred between the physical memory and the hard disk.
- It can increase the risk of data loss or corruption, as data can be lost if the hard disk fails or if there is a power outage while data is being transferred to tát or from the hard disk.
- It can increase the complexity of the memory management system, as the operating system needs to tát manage both physical and virtual memory.
Conclusion
In conclusion, virtual memory is a crucial feature in operating systems that allows computers to tát run rẩy larger applications and handle more processes phàn nàn the physical RAM alone can tư vấn. By using techniques lượt thích paging and segmentation, the system extends the available memory onto the hard drive, ensuring that the operating system and applications can operate smoothly. Although virtual memory can introduce some performance overhead due to tát the slower tốc độ of hard drives compared to tát RAM, it provides significant benefits in terms of memory management, efficiency, and multitasking capabilities.
Frequently Asked Questions on Virtual Memory – FAQs
Why is virtual memory important?
Virtual memory is important because it allows the system to tát handle larger applications and multiple applications simultaneously without running out of physical memory. It helps in optimizing the use of available RAM and provides a buffer against memory shortages.
What is a page tệp tin or swap space in virtual memory?
Page tệp tin is also known as Virtual memory tệp tin in windows while Swap space is known as page tệp tin in Unix/Linux It is a disk area assigned by the operating system to tát act as extension of physical memory. If RAM is saturated, then finally inactive page of memory is swapped to tát this area, to tát provide the occupied RAM for more active processes. This process is known as paging or swapping.
Can virtual memory affect system performance?
Virtual memory may affect the efficiency of the operation of the computer. Too much usage of the virtual memory will result in what is referred to tát as a thrashing where the system spends most of its time swapping data between the RAM and the disk with less time executing applications thus, slows down the system. This can be solved by having enough physical RAM and to tát correctly setup the page tệp tin or swap space.
Improve