What is Virtual Memory And Demand Paging?

What is Virtual Memory And Demand Paging?

Virtual memory and demand paging are memory management techniques used in Linux. In this article, we are going to see what is the memory management and what are virtual memory and demand paging.

Memory Management

Memory management is an important activity done effectively in the kernel. Memory management is the process of managing the computer memory. ie, This includes assigning memory to various running programs to keep the performance of the system stable. The memory should be allocated dynamically according to the requirement and it should be freed up when no longer used so that it can be reallocated when needed. Memory management depends on the effective configuration in hardware, operating system, and programs or applications. In hardware, memory management involves physical devices that store the data. The Random-Access Memory is an example of this. This also includes memory caches and flash-based Solid-State Drives. In the case of OS, memory management involves the allocation of specific memory blocks to individual programs as user demand changes. At the application level, memory management ensures the memory demanded by the objects and data structures of each running program is available always. Modern computers manage memory at two levels; at the system levels and at the application level. The application level memory management is categorized as either automatic or manual memory management. In this article, we are going to see the memory management based on virtual memory and demand paging.

Virtual Memory

Virtual memory is a memory management technique that can be implemented using both hardware and software. As the name indicates, it adds virtual memory to available memory, so that your system will appear to have more memory than what actually exists. Virtual memory is a layer of memory addresses (virtual addresses) that map to physical addresses. The memory addresses used by a program is the virtual addresses. These virtual address spaces and the assignment of real memory to the virtual memory are managed by the operating system. The working of virtual memory is as follows. The computer system has a limited amount of Static RAM. When a program gets executed, an instance of the program is loaded into the RAM. This is the process of allocating the memory for the instructions to execute. When the program demands more RAM than available, it will be allocated to the virtual memory. This prevents the program from lacking the necessary RAM to execute. This virtual memory is actually the memory of the hard disk and it is then mapped into the physical memory.

Demand Paging

Demand paging is a type of swapping done in virtual memory systems. In demand paging, the data is not copied from the disk to the RAM until they are needed or being demanded by some program. The data will not be copied when the data is already available on the memory. This is otherwise called a lazy evaluation because only the demanded pages of memory are being swapped from the secondary storage (disk space) to the main memory. In contrast during pure swapping, all the memory for a process is swapped from secondary storage to main memory during the process startup.

Anticipatory Paging

The anticipatory paging is another type of swapping in virtual memory systems. Here, the operating system attempts to anticipate the data that will be needed next and copies it to RAM before it is actually required.

Demand Paging Working

The demand paging working is based on a page table implementation. The page table maps logical memory to physical memory. The page table uses a bitwise operator to mark if a page is valid or invalid. A valid page is one that currently resides in main memory. An invalid page can be defined as the one that currently resides in secondary memory. When a process tries to access a page, the following will happen.

1) Attempt to access the page

2) The page is valid. Page processing instruction continues as normal.

3) If the page is an invalid one, then a page-fault trap occurs.

4) The memory reference is then checked to determine if it is a valid reference to a location on secondary memory or not. If not, the process is terminated (illegal memory access). Otherwise, the required page is paged in.

5) Now the disk operation to read the desired page into main memory is scheduled.

6) Finally, the instruction that was interrupted by the operating system trap is restarted.

If you need any further assistance please contact our support department.

  • 0

Install Wine on Linux Distribution

Install Wine on Linux Distribution In this tutorial, we can check how to Install Wine on Linux...

Install Apache Tomcat on Ubuntu 18.04

Install Apache Tomcat on Ubuntu 18.04 The Apache Tomcat is a free, open-source Java-based web...

How to Install and Setup Angular CLI

How to Install and Setup Angular CLIAngular is an open-source framework for your web...

How to Install Jenkins on CentOS and Ubuntu Server?

How to Install Jenkins on CentOS and Ubuntu Server? Jenkins is a free and open-source automation...

Setup ILIAS LMS on Ubuntu 18.04/16.04 with Nginx

ILIAS is an Open-Source Learning Management System. ILIAS LMS offers to develop and realizing...