0% found this document useful (0 votes)
70 views27 pages

Operating Systems: Syed Mansoor Sarwar

Uploaded by

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

Operating Systems: Syed Mansoor Sarwar

Uploaded by

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

Operating

Systems
Lecture 38
Syed Mansoor Sarwar
Agenda for Today
 Review of previous lecture
 Performance of Demand
Paging
 Process Creation
 Memory Mapped Files
14 September 2019 © Copyright Virtual University of
Pakistan
Review of Lecture 37
 Memory Management in Intel
80386
 Virtual Memory Concept
 Hardware Support
 Demand Paging
 Page Fault
 Performance of Demand
Paging
14 September 2019 © Copyright Virtual University of
Pakistan
Intel 80386 Example
16-bit
Selector 32-bit Offset

13-bit Segment #
s g p 2-bit field for
1-bit field to specifying the
specify GDT or privilege level
LDT
14 September 2019 © Copyright Virtual University of
Pakistan
Intel 80386 Example

14 September 2019 © Copyright Virtual University of


Pakistan
Demand Paging

14 September 2019 © Copyright Virtual University of


Pakistan
Servicing a Page Fault

14 September 2019 © Copyright Virtual University of


Pakistan
Block/String Move
0

1
Destination Source
String String
2
3

14 September 2019 © Copyright Virtual University of


Pakistan
Performance of
Demand Paging
 Effective Access Time (EAT)
EAT = (1 – p) x memory access time
+ p (page fault service time)

14 September 2019 © Copyright Virtual University of


Pakistan
Example
 Memory access time = 100 nanosec
 Page fault service time = 25 millisec
 Teffective = (1 - p) x 100 + p (25 milli)
= (1 - p) x 100 + p (25000000)
= 100 + 24999900 x p
 If one access out of 1000 causes a
page fault, effective access time is
25 microseconds, a slowdown by a
factor of 250.
14 September 2019 © Copyright Virtual University of
Pakistan
Example
 If we want less than 10 percentage
degradation in effective memory
access time then we have the
following inequality
110 > 100 + 25000000 x p
10 > 25000000 x p
p < 0.0000004
 This means we can allow only one
page fault every 2,500,000.
14 September 2019 © Copyright Virtual University of
Pakistan
Page Fault and No
Free Frame
 Page Replacement
 Replacement algorithm
(minimize number of page faults)
 Performance with replacement
 Victim selection
Criteria
Local vs. global
14 September 2019 © Copyright Virtual University of
Pakistan
Another Example
 Effective memory access is 100 ns
 Page fault overhead is 100
microseconds = 105 ns
 Page swap time is10 milliseconds =
107 ns
 50% of the time the page to be
replaced is “dirty”
 Restart overhead is 20 microseconds
= 2 x 104 ns
14 September 2019 © Copyright Virtual University of
Pakistan
Another Example
Effective access time =
100 x (1-p) + (105 + 2 x 104
7 7
+ 0.5 x 10 + 0.5 x 2 x 10 ) x p
= 100 x (1-p) + 15,120,000 x p

14 September 2019 © Copyright Virtual University of


Pakistan
What is a Good Page
Fault Rate?
 For the previous example
suppose p is 1%, then EAT is
= 100 x (1-p) + 15,120,000 x p
= 151299 ns
 a slowdown of 151299 / 100 =
1513
14 September 2019 © Copyright Virtual University of
Pakistan
What is a Good Page
Fault Rate?
 For the luxury of virtual memory to
cost only 20% overhead, we need
120 > 100 x (1-p) + 15,120,000 x p
120 > 100 -100 p + 15,120,000 p
p < 0.00000132
 Less than one page fault for
every 755995 memory accesses!
14 September 2019 © Copyright Virtual University of
Pakistan
Process Creation
 fork()
Exact copy of parent’s memory
image
Copying parent’s pages
(address space)
 Child may call exec()
immediately  copying parent’s
address space is not needed
14 September 2019 © Copyright Virtual University of
Pakistan
Process Creation
 “Copy-on-write”  child share’s
parent’s address space and
pages which may change are
marked “copy-on-write”
 When a process tries to modify a
page, it is copied and inserted in
the page table for the process
 Used in Windows 2000, Solaris
2, and Linux
14 September 2019 © Copyright Virtual University of
Pakistan
Process Creation
 vfork()
 Parent is suspended and child
uses parent’s address space
 Pages altered by the child
process are visible to parent
 Intended to be used when child
process calls exec()
immediately after its creation
14 September 2019 © Copyright Virtual University of
Pakistan
Linux Implementation
 Shared pages are marked
readonly after fork()
 If either process tries to modify a
shared page, a page fault occurs
and the page is copied.
 The other process (who later
faults on write) discovers it is the
only owner; so no copying takes
place.
14 September 2019 © Copyright Virtual University of
Pakistan
Memory-Mapped Files
 Memory-mapped file I/O 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 from/to the file are
treated as ordinary memory
accesses.
14 September 2019 © Copyright Virtual University of
Pakistan
Memory-Mapped Files
 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.
 Some operating systems only provide
memory-mapping through a system call
(mmap()). Others treat all file I/O as
memory mapped files.
14 September 2019 © Copyright Virtual University of
Pakistan
Memory-Mapped Files

14 September 2019 © Copyright Virtual University of


Pakistan
mmap() System Call
 “Normal” File I/O
fildes = open(...);
lseek(...);
read(fildes, buf, len);
/* use data in buf */
 File I/O with mmap()
fildes = open(...)
address = mmap((caddr_t) 0, len,(PROT_READ |
PROT_WRITE), MAP_PRIVATE, fildes, offset);
/* use data at address */
14 September 2019 © Copyright Virtual University of
Pakistan
Memory-Mapped Files
in Solaris 2
 If file is opened as memory
mapped: it maps the file to the
address space of the process.
 If the file is opened non memory-
mapped, Solaris 2 opens it as a
memory-mapped file, mapping it
to the kernel address space
14 September 2019 © Copyright Virtual University of
Pakistan
Recap of Lecture
 Performance of Demand
Paging
 Process Creation
 Memory Mapped Files

14 September 2019 © Copyright Virtual University of


Pakistan
Operating
Systems
Lecture 38
Syed Mansoor Sarwar

14 September 2019 © Copyright Virtual University of


Pakistan

You might also like