0% found this document useful (0 votes)
122 views7 pages

Adama Science and Technology University: Operating Systems

This document discusses demand paging in operating systems. It explains that demand paging loads pages of a process into memory only when they are accessed, rather than preemptively loading all pages. This avoids loading unnecessary pages and improves memory efficiency. The document outlines the steps taken during a page fault, including finding a free frame, loading the missing page, and updating page tables. It also discusses hardware and software support needed for demand paging and analyzes its performance based on page fault rates.

Uploaded by

DEABELA GAMING 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views7 pages

Adama Science and Technology University: Operating Systems

This document discusses demand paging in operating systems. It explains that demand paging loads pages of a process into memory only when they are accessed, rather than preemptively loading all pages. This avoids loading unnecessary pages and improves memory efficiency. The document outlines the steps taken during a page fault, including finding a free frame, loading the missing page, and updating page tables. It also discusses hardware and software support needed for demand paging and analyzes its performance based on page fault rates.

Uploaded by

DEABELA GAMING 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ADAMA SCIENCE AND TECHNOLOGY

UNIVERSITY

SCHOOL OF ELECTRICAL ENGINEERING


AND COMPUTNG

DEPARTMENT OF COMPUTER SCIENCE


AND ENGINEERING
OPERATING SYSTEMS(CSE 3204)
Section -2
Name ID

1. Flagot Mulugeta…………………….ugr/19655/12
2. Dawde Seifu…………………………ugr/19673/12
3. Dagim Debebe……………………….ugr/19904/12
4. Dagmawi Habtamu………………….ugr/19611/12
5. Bemnet Adinew………………………ugr/19973/12
6. Nathnael kumsa………………………………..ugr/19887/12

Submitted to - Genet Shanko


Submission Date - June 11, 2022
DEMAND PAGING
According to the concept of Virtual Memory, in order to execute some
process, only a part of the process needs to be present in the main memory
which means that only a few pages will only be present in the main memory at
any time.

However, deciding, which pages need to be kept in the main memory and
which need to be kept in the secondary memory, is going to be difficult
because we cannot say in advance that a process will require a particular page
at particular time.

Therefore, to overcome this problem, there is a concept called Demand Paging


is introduced. It suggests keeping all pages of the frames in the secondary
memory until they are required. In other words, it says that do not load any
page in the main memory until it is required.

In computer operating systems, demand paging is a method of virtual memory


management. In a system that uses demand paging, the operating system
copies a disk page into physical memory only if an attempt is made to access it
and that page is not already in memory.

The demand paging system is somehow similar to the paging system with
swapping where processes mainly reside in the main memory(usually in the
hard disk). Thus demand paging is the process that solves the above problem
only by swapping the pages on Demand. This is also known as lazy swapper
( It never swaps the page into the memory unless it is needed).

Whenever a page is needed make a reference to it:


 if it’s invalid abort it
 if the page is not in memory then bring it to memory
Valid-Invalid Bit
With each page table entry, a valid-invalid bit is associated
where 1 indicates in the memory and 0 indicates not in the memory) Initially,
the valid-invalid bit is set to 0 for all table entries.

 If the bit is set to "valid", then the associated page is both legal and is in memory.
 If the bit is set to "invalid" then it indicates that the page is either not valid or the
page is valid but is currently not on the disk.
Page fault
If the referred page is not present in the main memory then there will be a miss and
the concept is called Page miss or page fault.

The CPU has to access the missed page from the secondary memory. If the number of
page fault is very high then the effective access time of the system will become very
high.

Steps in Handling a Page Fault


1.Check the internal table, to determine whether this reference is valid or invalid.

2.If the reference is invalid, then terminate.

3.Find free frame.

4.Schedule disk operation.

5.Modify the internal table to indicate that page is in main memory.

6.Restart the instruction.

What happens if there is no free frame?


If there is a free frame, use it. If there is no free frame, use a page-replacement
algorithm to select an existing frame to be replaced, known as the victim frame. Write
the victim frame to disk. Change all related page tables to indicate that this page is no
longer in memory.

Hardware support to demand paging


Demand paging requires several types of hardware support: A TB and an address
translation mechanism. Page table entries with disk addresses (can be calculated from
offset) The ability to detect a page fault.

Software support to demand paging


 Restarting of instruction after page fault
 Page fault could occur any time during execution
 difficulty occurs if instruction modifies several different location
 source and destination may overlap,we can’t redo so the solutions are
1. Use micro code to access both ends of blocks
2. Use temporary registers to hold the values of temporary register

Advantages of Demand Paging


The benefits of using the Demand Paging technique are as follows:

1.With the help of Demand Paging, memory is utilized efficiently.

2.Demand paging avoids External Fragmentation.

3.Less Input/Output is needed for Demand Paging.

4.This process is not constrained by the size of physical memory.

5.With Demand Paging it becomes easier to share the pages.

6.With this technique, portions of the process that are never called are never
loaded.

7.No compaction is required in demand Paging.

Disadvantages of Demand paging


Drawbacks of Demand Paging are as follows:

1.There is an increase in overheads due to interrupts and page tables.

2.Memory access time in demand paging is longer

3.Individual programs face extra latency when they access a page for
the first time.
Performance of Demand Paging
The performance of demand paging is often measured in terms of the effective access
time. Effective access time is the amount of time it takes to access memory, if the cost
of page faults are amortized over all memory accesses. In some sense it is an average
or expected access time.

Let p be the probability of page fault.

Page Fault Rate 0 <= p >= 1.0

if p = 0 no page faults , effective access time=memory access time.

if p = 1, every reference is a fault

Effective Access Time (EAT)

EAT = (1 – p) x memory access+ p (page fault overhead)

Major operations during page fault:

Trap to OS; save user registers and process state; issue a disk read; wait for interrupt
from disk; wait for the CPU; restore the process status;

Demand Paging Example

Memory access time = 100 nanoseconds, Page fault service time = 25milliseconds
Effective access time (EAT) = (1 – p) x 100 + p (25 msec)

=100+24,999,900 x p

EAT is directly proportional to page-fault rate.

It is important to keep the page-fault rate low.

Otherwise EAT increases and slowing the process execution dramatically.


Advantages of VM: Process Creation
Virtual memory allows other benefits during process creation:

A.Copy-on-Write(COW):- allows both parent and child processes to initially share


the same pages in memory.
If either process modifies a shared page, only then the page copied.

COW allows more efficient process creation as only modified pages are copied.

Free pages are allocated from a pool of zeroed-out pages.

B.Memory-Mapped Files:- allows file I/O to be treated as routine memory access by


mapping a disk block to a page in memory.

A file is initially read using demand paging. A page-sized portion of the file is read
from the file system into a physical page. Subsequent reads/writes to/from the file are
treated as ordinary memory accesses.

Simplifies file access by treating file I/O through memory rather than read() write()
system calls.

Also allows several processes to map the same file allowing the pages in memory to
be shared.

You might also like