Professional Documents
Culture Documents
Unit-4 Memory Management
Unit-4 Memory Management
MEMORY MANAGEMENT
BY:
Dr. R. C. Tripathi
Professor, FOECS, TMU &
Chairman CSI-NOIDA CHAPTER
Mobile: +91-9868257510,
Email: tripathi.computers@tmu.ac.in
visit us at: http://tmu.ac.in/college-of-computing-sciences-and-it/about/our-faculty/
http://www.csi-india.org/web/noida-chapter/management-committee
Operating
system P1 -Swap
out Process
p1
P2 -
Swap in Process
User
p2
space
https://www.youtube.com/watch?v=AJwONVSOAeE
Thrashing
If a process does not have “enough” pages, the
page-fault rate is very high. This leads to:
low CPU utilization.
operating system thinks that it needs to increase the
degree of multiprogramming.
another process added to the system.
Adds to the problem as even less page frames are
available for each process.
Thrashing a process is busy swapping pages in
and out
https://www.youtube.com/watch?v=IyWaK8pbN6A
Thrashing
Thrashing in computing is an issue caused when virtual
memory is in use. It occurs when the virtual memory of a
computer is rapidly exchanging data for data on hard disk,
to the exclusion of most application-level processing.
P1 4 2 1
P2 2 6 3
P3 6 4 2
P4 8 4 2
P5 2 2 1
P6 10 4 2
P7 2 2 1
Memory Management
An Example – Time Slot 1
Before: After:
Time Slot 1
P1 (4ms) P1 (2ms)
P2 (2ms) P2 (2ms)
P3 (6ms) P3 (6ms)
• P1 Executes
P4 (8ms) P4 (8ms)
• P2 Done
P4 (8ms) P4 (8ms)
• P2 spooled
P2 (0ms) out in 2ms
P2 (0ms)
P3 (6ms) P3 (4ms)
• P3 Executes
P4 (8ms) P4 (8ms)
P3 (4ms) P3 (4ms)
• P4 Executes
P4 (8ms) P4 (6ms)
• P5 Done
P4 (6ms) P4 (6ms)
OS OS OS
400K 400K 400K
P1 P1 P1
1000K 1000K 1000K
P2 P2 P4
terminates allocate P4
1700K
2000K 2000K 2000K
P3 P3 P3
2300K 2300K 2300K
https://www.youtube.com/watch?v=pJ6qrCB8pDw
Paging: A Better Solution
Allows processes to use logical
memory/physical as and when needed.
Allows Swapping in & swapping out of
processes as and when needed.
Allows multiple processes to reside in
memory at the same time.
Segmentation
Memory-management scheme that supports
user view of memory.
A program is a collection of segments. A
segment can be any logical unit.
code, global variables, heap, stack,…
Segment sizes may be different.
https://www.youtube.com/watch?v=p9yZNLeOj4s
Virtual Memory That is Larger
Than Physical Memory
Page Table
One entry for each page in the logical address
space.
Contains the base address of the page frame
where the page is stored.
Also contains a valid bit
If set, logical address is valid and has physical
memory allocated to it
If not set, logical address is invalid
https://www.youtube.com/watch?v=7VshrpZM-DA
Demand Paging
Bring a page into memory only when it is
needed (on demand)
Less I/O needed to start a process
Less memory needed
Faster response
More users
Page is needed reference to it
invalid reference abort
not-in-memory bring to memory
https://www.youtube.com/watch?v=dOVrEbZVeoU
Page Replacement Algorithm
Page replacement algorithms decides which
memory pages to page out, sometimes called swap
out, or write to disk, when a page of memory
needs to be allocated.
Page replacement happens when a requested page
is not in memory.
http://embed.wistia.com/deliveries/766783aab52a5d2
dc0a46339c11f132c08743ab8.bin
Types of Page Replacement
Algorithms
There are four types of page replacement algorithms.
First-fit: Allocate the first hole that is
big enough.
Next-fit: Similar to first-fit, but start from last
hole allocated.
Best-fit: Allocate the smallest hole that is big
enough; must search entire list, unless ordered by
size. Produces the smallest leftover hole.
Worst-fit: Allocate the largest hole; must also
search entire list. Produces the largest
leftover hole.
https://www.youtube.com/watch?v=EXDWHjnrIYk
Page Fault