Está en la página 1de 5

Icvncn o{ (onvc .icn.

c 1ninccin (1^
Tcvcv , ninc ) Iv.

Virtual memory Management

All the methods we have discussed so far use real memory management systems,
where the entire process image (all chunks) has to reside in the main memory before
execution commence.
If the method can work with only some chunks in the main memory and the
remaining on the disk, which can be brought into the main memory as, and when
required, the system is called virtual memory management system.
Virtual memory system can be implemented using paging, segmentation or
combined schemes.
In this scheme, the program consists of a number of logical or virtual pages which
are loaded into specific page frames. The process can start executing with only part of the
pages in the memory. When a page not currently in the memory is referenced, only that
page can be brought from the disk into the memory.
The idea in this scheme is to bring in only minimum required pages of a process
to begin with, and continue as long as these pages were sufficient. As soon as a reference
is made outside these pages, the required page is located from the disk and brought into
the memory.
Page replacement policy
As the number process and number of pages in the main memory for each process
increases, at some point of time, all the page frames become occupied. At this time, if a
new page is to be brought in, the operating system has to overwrite some existing page in
the main memory. The page to be chosen is selected by the page replacement policy.
Page fault
In many virtual memory management system, when a process is executing with only a
few pages in memory, and when an instruction is encountered which refers to any
instruction or data in some other page, which on the disk, a page fault occurs.
At this point, the operating system must bring the required page into the memory before
the execution of the instruction can restart. In this fashion, the number pages in the
physical memory for that process gradually increases with the page faults. After a while,
when a sufficient number of required pages build up, the pages are normally found in the
memory and then the frequency of page fault reduces.
Icvncn o{ (onvc .icn.c 1ninccin (1^
Tcvcv , ninc ) Iv.

Dirty Page/ Dirty Bit
Before overwriting a page in the memory, the operating system has to check if that page
has been modified after it was loaded from the disk. For instance, there may be a page
containing the I/O area where an employee record is to be read. Initially that page will be
loaded with the I/O area as blank. After reading the record that page gets modified. Such
a modified page is called Dirty page.
The Operating system maintain one bit for each physical page frame to denote whether a
page has become dirty or not. This bit is called dirty bit. The H/W is normally designed
in such a way that corresponding page frame is set to 1; otherwise it is 0.
Demand paging
In demand paging a page is brought in only when demanded. Let us imagine that
a process is created, but there are no pages for it in the main memory at that time. When
the process is dispatched initially, the program counter (PC) will have been loaded with
address of the first instruction from where the address of the first instruction should
commence. This address obviously belongs to a page which is not present in the memory
at that time. Hence a page fault is generated while fetching the first instruction itself. The
operating system will now bring that page in. after a while am instruction will be
encountered which has an address of a page not currently in the main memory. Another
page fault will occur and a page will be brought in. in this fashion the no of pages in the
memory will increase on demand. It is called demand paging.
Working set
A working set is a set of most recently referenced pages in a process. In the
beginning, this working set is very small. With the passage of time, the number of pages
often referented and therefore the size of the working set increases steeply as shown in
figure.










Number of references growing with time
S
i
z
e

o
f

w
o
r
k
i
n
g

s
e
t

Icvncn o{ (onvc .icn.c 1ninccin (1^
Tcvcv , ninc ) Iv.

After a certain number of page references, the size of the working set remains more or
less constant, ie, slop of the curve becomes almost 0. at that point of time we have more
or less stable working set and most often referenced pages are already in the main
memory and the page faults have dropped almost to 0.

Page Replacement Polices
If all the page frames are occupied, when a new page has to be brought in due to
page fault, the OS has to choose a candidate page frame to be over written. If the page
frame is choosen from the same process, it is called local replacement policy. If it can
be from any process, it is called global replacement policy.
It is better to throw a less frequency used page from a high priority processthan
throwing out a more frequency used page from a low priority process. Choosing a page
frame only that process for replacement is simpler.
There are several algorithms
Optimal (Opt)
First in First Out (FIFO)
Not Recently Used (NRU)
Least Recently Used (LRU)
Not Frequently used (NFU)

First In First Out (FIFO)
In order to explain FIFO page replacement algorithm, let us take a random page
reference string in a program: 0,1,2,3,1,4,1,5,3,4,1,4,3,2,3,1,2,8,1,2. let us also assume
that there are only three page frames 0,1 and 2 in our system. Also assume that they are
empty to begin with

Page reference 8 1 2 3 1 4 1 5 3 4 1 4 3 2 3 1 2 8 1 2
Page frame 0 8 8 8 3 3 3 5 5 5 1 1 1 1 1 1 1 1 8 8 8
Page frame 1 1 1 1 1 4 4 4 3 3 3 3 3 2 2 2 2 2 1 1
Page frame 2 2 2 2 2 1 1 1 4 4 4 4 4 3 3 3 3 3 2
Page fault (*=yes) * * * * * * * * * * * * * * *




Icvncn o{ (onvc .icn.c 1ninccin (1^
Tcvcv , ninc ) Iv.
For instance, initially all the page frames are empty. When page 8 is referenced, a
page fault will occur (indicated by *). This page now will be brought into the memory
(frame 0). The next two columns are similar
The forth page reference is for page 3. this page is not in the memory hence a
page fault results. In the FIFO algorithm throw the page 8 because it was the first one to
be brought in. the fifth page reference does not cause a page fault in FIFO as the page 1 is
already in the memory. The 6
th
page reference is for page 4. Here FIFO will throw out
page 1, because it cause in earlier than the remaining two pages.

2) Optimal Page Replacement (OPT) or Beladys Algorithm.
An Optimal page replacement algorithm was the lowest page fault rate of all
algorithms. It simply replaces the page that will not be used for the longest period of
time.
Let us assume that the reference string is
8,1,2,3,1,4,1,5,3,4,1,4,3,2,3,1,2,8,1,2
Page reference 8 1 2 3 1 4 1 5 3 4 1 4 3 2 3 1 2 8 1 2
Page frame 0 8 8 8 3 3 3 3 3 3 3 3 3 3 3 3 3 3 8 8 8
Page frame 1 1 1 1 1 1 1 5 5 5 1 1 1 1 1 1 1 1 1 1
Page frame 2 2 2 2 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2
Page Fault * * * * * * * * *



The forth page refrence is for page 3. this is not in the memory, but no page frame
is also free. Thus a page replacement is necessary. The OS has the choice of throwing out
page 8, page1 or page 2. here you can notice that it will throw out page no 8 residing in
frame 0, because page 8 is going to be used for later than page 1 or page 2. there are only
9 page faults in this algorithm. This is obviously than best scheme, but it is requires
future knowledge of the reference string. As a result optimal algorithm is not used at all.
3. LRU Page Replacement
LRU replacement associates with each page the time of that pages last use. When
a page msut be replaced, LRU chooses that page that has not been used for the longest
period of time. This strategy is like optimal page replacement algorithm looking
backward in time, rather than forward.


Icvncn o{ (onvc .icn.c 1ninccin (1^
Tcvcv , ninc ) Iv.

Page Reference 8 1 2 3 1 4 1 5 3 4 1 4 3 2 3 1 2 8 1 2
Page Frame 0 8 8 8 3 3 3 3 5 5 5 1 1 1 2 2 2 2 2 2 2
Page Frame 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 1 1 1 1 1
Page Frame 2 2 2 2 4 4 4 3 3 3 3 3 3 3 3 8 8 8 8
Page Fault * * * * * * * * * * * *



In this scheme, when page 5 is referenced there are already 3 frames in the
memory, viz 3,1 and 4. Studying the reference string, it is found that page 3 is last
reprenced in the 4
th
reference, page 1 is last referenced in the 7
th
reference and page 4 is
last reference in the 6
th
reference. The OS wants to bring in page 5, but it needs to throw
out a page because there is no free page frames available. As page 3 was used least
recently, it is thrown out. Page 1 used most recently and thus, it is obviously retained.

También podría gustarte