OS Unit 4 Virtual Memory
OS Unit 4 Virtual Memory
7.1 Background
Virtual memory is a memory management functionality of an operating system (OS)
that utilize hardware and software to enable a computer to make up for physical
memory deficiencies by incidentally moving data from random access memory
(RAM) to disk storage.
Virtual address space is expanded utilizing active memory in RAM and inactive
memory in hard disk drives (HDDs) to frame contiguous addresses that hold both the
application and its data.
Virtual Memory is a storage allocation plot in which secondary memory can be
tended to just as it were a piece of main memory.
The addresses a program may use to reference memory are recognized from the
addresses the memory system uses to distinguish physical storage locales, and
program created addresses are made an interpretation of consequently to the relating
machine addresses.
The size of virtual storage is constrained by the addressing plan of the computer
system and measure of secondary memory is accessible not by the genuine number of
the main storage locations.
Virtual memory was created when physical memory - the installed RAM - was costly.
Computers have a limited measure of RAM, so memory can run out, particularly
when numerous programs keep running simultaneously.
A system utilizing virtual memory utilizes a segment of the hard drive to copy RAM.
With virtual memory, a system can stack bigger programs or various programs
running simultaneously, enabling everyone to work as though it has vast memory and
without obtaining more RAM.
While duplicating virtual memory into physical memory, the OS partitions memory
into page files or swap files with a fixed number of addresses. Each page is put away
on a disk and when the page is required, the OS copies it from the disk to fundamental
memory and makes an interpretation of the virtual addresses into real addresses.
Current microprocessors expected for universally useful use, a memory management
unit, or MMU, is incorporated with the hardware.
The MMU's main responsibility is to make an interpretation of virtual address into
physical address. A fundamental model is given underneath −
It is a procedure that is actualized utilizing both hardware and software. It maps
memory addressed utilized by a program, called virtual addresses computers, into
physical addresses in c memory.
1. All memory references inside a process are logical addresses that are
powerfully converted into physical addresses at run time. This implies a
process can be swapped all through fundamental memory with the end goal
that it involves better places in primary memory at various times over the span
of execution.
2. A process might be broken into number of pieces and these pieces need not be
constantly situated in the main memory during execution. The blend of
dynamic run-time address interpretation and utilization of page or portion
table allows this.
On the off chance that these attributes are available, at that point, it isn't essential that
every one of the pages or portions are available in the main memory during execution.
This implies the required pages should be stacked into memory at whatever point
required.
Virtual memory is designed utilizing Demand Paging or Demand Segmentation.
7.2 Demand Paging
As per the idea of Virtual Memory, to execute some process, just a piece of the
process should be available in the main memory which implies that a couple of pages
may be available in the main memory whenever.
The difficult task is to decide which pages should be kept in the main memory and
which should be kept in the secondary memory, because of the fact that we can't state
ahead of time that a process will require a specific page at specific time.
Subsequently, to beat this issue, there is an idea called Demand Paging is presented. It
proposes keeping all pages of the frames in the secondary memory until they are
required. That means, it says that don't stack any page in the main memory until it is
required.
Demand paging says that pages should possibly be brought into memory if the
executing process requests them. This is frequently known as lazy evaluation as just
those pages requested by the process are swapped from secondary storage to main
memory.
On the other hand in pure swapping, where all memory for a process is swapped from
secondary storage to main memory during the process start execution.
To implement this process needs a page table is utilized. The page table maps logical
memory to physical memory.
The page table uses a bitwise administrator to stamp if a page is valid or invalid. A
valid page is one that is present in main memory. An invalid page is one that is
present in secondary memory.
At the point when a process attempts to get to a page, following steps are followed as
shown in figure below:
1. In the event that CPU attempt to call a page that is as of now not accessible in
the main memory, it creates an interrupt showing memory access fault.
2. The OS places the interrupted process in a blocking state. For the execution to
continue the OS must call the required page into the memory.
3. The OS will scan for the required page in the logical address space.
4. The required page will be brought from logical address space to physical
address space. The page replacement algorithms are utilized for deciding
which page is to be replace with the new page in physical address space.
5. Updation will be made to the page table accordingly.
6. The sign will be sent to the CPU to proceed with the program execution and it
will put the process again into ready state.
Henceforth at whatever point a page fault happens these steps are performed by the
operating system and the required page is brought into memory.
Advantages
Demand paging, instead of loading all pages right away:
Just loads pages that are requested by the executing process.
As there is more space in main memory, more processes can be stacked, decreasing
the context switching time, which uses a lot of resources.
Less loading latency happens at program startup, as less data is gotten to from
secondary storage and less data is brought into main memory.
As main memory is costly contrasted with secondary memory, this method helps
altogether decrease the bill of material (BOM) cost in advanced cells for instance.
Symbian OS had this element.
Disadvantage
Individual programs face additional latency when they access page at first time.
Minimal effort, low-control implanted systems might not have a memory
management unit that supports page replacement.
Memory management with page replacement algorithms turns out to be somewhat
increasingly intricate.
Conceivable security dangers, including weakness to timing attacks.
Thrashing which may happen because of repeated page faults.
Page Replacement
Presently for the further page reference string — > 0 Page fault since they are as of
now accessible in the memory.
Optimal page replacement is flawless, yet unrealistic by and by as the operating
system can't know future requests. The utilization of Optimal Page replacement is to
set up a benchmark with the goal that other replacement calculations can be examined
against it.
7.6 Thrashing
Thrashing is computer action that allows little or no progress, as memory or different
resources have turned out to be depleted or too limited to even perform required
functions.
At this point, a pattern normally creates in which a request made to the operating
system by a process or program, then the operating system attempts to find resources
by taking them from some different process, which in turn makes new demands that
can't be fulfilled.
In a virtual storage system (an operating system that deals with its local storage or
memory in units called pages), thrashing is a condition wherein extreme paging
operations are occurring.
A system that is thrashing can be seen as either an exceptionally moderate system or
one that has stopped.
Thrashing is a condition or a circumstance when the system is spending a noteworthy
segment of its time in adjusting the page faults; however the genuine processing done
is truly insignificant.
The fundamental idea included is that in the event that a process is assigned too few
frames, at that point there will be an excess of and too successive page faults.
Thus, no work would be finished by the CPU and the CPU use would fall definitely.
The long term scheduler would then attempt to improve the CPU usage by loading
some more processes into the memory in this way expanding the level of
multiprogramming.
This would bring about a further decline in the CPU usage setting off a chained
response of higher page faults followed by an expansion in the level of
multiprogramming, called Thrashing.