SlideShare a Scribd company logo
1 of 83
Memory Management

SATHISH.V
VELAMMAL INSTITUTE OF TECHNOLOGY
ECE

2010-2014
Memory Hierarchy
Memory
Cache
Registers

Question: What if we want to support programs that
require more memory than what’s available in the
system?
Computer Science, Rutgers

2

CS 519: Operating System Theory
Memory Hierarchy
Virtual Memory
Memory
Cache
Registers

Answer: Pretend we had something bigger: Virtual
Memory
Computer Science, Rutgers

3

CS 519: Operating System Theory
Virtual Memory: Paging
A page is a cacheable unit of virtual memory
The OS controls the mapping between pages of VM and
memory
page
frame

More flexible (at a cost)

Cache

Memory
Memory

Computer Science, Rutgers

4

VM

CS 519: Operating System Theory
Two Views of Memory
View from the hardware – shared physical memory
View from the software – what a process “sees”: private
virtual address space
Memory management in the OS coordinates these two
views
Consistency: all address space can look “basically the same”
Relocation: processes can be loaded at any physical address
Protection: a process cannot maliciously access memory
belonging to another process
Sharing: may allow sharing of physical memory (must implement
control)

Computer Science, Rutgers

5

CS 519: Operating System Theory
Paging From Fragmentation
Could have been motivated by fragmentation problem
under multi-programming environment

New Job

Memory
Computer Science, Rutgers

Memory
6

CS 519: Operating System Theory
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free
holes.
First-fit: Allocate the first hole that is big enough.
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 entier
list. Produces the largest leftover hole.

First-fit and best-fit better than worst-fit in terms of
speed and storage utilization.

Computer Science, Rutgers

7

CS 519: Operating System Theory
Virtual Memory: Segmentation

Job 0

Job 1

Memory

Computer Science, Rutgers

8

CS 519: Operating System Theory
Virtual Memory
Virtual memory is the OS abstraction that gives the programmer
the illusion of an address space that may be larger than the
physical address space
Virtual memory can be implemented using either paging or
segmentation but paging is presently most common
Actually, a combination is usually used but the segmentation scheme is
typically very simple (e.g., a fixed number of fixed-size segments)

Virtual memory is motivated by both
Convenience: the programmer does not have to deal with the fact that
individual machines may have very different amount of physical
memory
Fragmentation in multi-programming environments

Computer Science, Rutgers

9

CS 519: Operating System Theory
Basic Concepts: Pure Paging and
Segmentation
Paging: memory divided into equal-sized frames. All
process pages loaded into non-necessarily contiguous
frames
Segmentation: each process divided into variable-sized
segments. All process segments loaded into dynamic
partitions that are not necessarily contiguous

Computer Science, Rutgers

10

CS 519: Operating System Theory
Hardware Translation

Processor

translation
box (MMU)

Physical
memory

Translation from logical to physical can be done in
software but without protection
Why “without” protection?

Hardware support is needed to ensure protection
Simplest solution with two registers: base and size
Computer Science, Rutgers

11

CS 519: Operating System Theory
Segmentation Hardware

virtual address

offset

+

physical address

segment
segment table

Computer Science, Rutgers

12

CS 519: Operating System Theory
Segmentation
Segments are of variable size
Translation done through a set of (base, size, state)
registers - segment table
State: valid/invalid, access permission, reference bit,
modified bit
Segments may be visible to the programmer and can be
used as a convenience for organizing the programs and
data (i.e code segment or data segments)

Computer Science, Rutgers

13

CS 519: Operating System Theory
Paging hardware

virtual address
page #

+

offset

physical address

page table

Computer Science, Rutgers

14

CS 519: Operating System Theory
Paging
Pages are of fixed size
The physical memory corresponding to a page is called
page frame
Translation done through a page table indexed by page
number
Each entry in a page table contains the physical frame
number that the virtual page is mapped to and the state
of the page in memory
State: valid/invalid, access permission, reference bit,
modified bit, caching
Paging is transparent to the programmer
Computer Science, Rutgers

15

CS 519: Operating System Theory
Combined Paging and Segmentation
Some MMU combine paging with segmentation
Segmentation translation is performed first
The segment entry points to a page table for that
segment
The page number portion of the virtual address is used
to index the page table and look up the corresponding
page frame number
Segmentation not used much anymore so we’ll
concentrate on paging
UNIX has simple form of segmentation but does not require
any hardware support
Computer Science, Rutgers

16

CS 519: Operating System Theory
Address Translation

virtual address
CPU

p

d

f
physical address
f

d
d

p
f

page table
Computer Science, Rutgers

17

Memory

CS 519: Operating System Theory
Translation Lookaside Buffers
Translation on every memory access ⇒ must be fast
What to do?
Caching, of course …
Why does caching work? That is, we still have to lookup the page table
entry and use it to do translation, right?
Same as normal memory cache – cache is smaller so can spend more $$
to make it faster

Computer Science, Rutgers

18

CS 519: Operating System Theory
Translation Lookaside Buffer
Cache for page table entries is called the Translation
Lookaside Buffer (TLB)
Typically fully associative
No more than 64 entries

Each TLB entry contains a page number and the
corresponding PT entry
On each memory access, we look for the page ⇒ frame
mapping in the TLB

Computer Science, Rutgers

19

CS 519: Operating System Theory
Translation Lookaside Buffer

Computer Science, Rutgers

20

CS 519: Operating System Theory
Address Translation

virtual address
CPU

p

d

f
physical address
f

d
d

TLB
p/f
f
Computer Science, Rutgers

21

Memory

CS 519: Operating System Theory
TLB Miss
What if the TLB does not contain the appropriate PT
entry?
TLB miss
Evict an existing entry if does not have any free ones
Replacement policy?

Bring in the missing entry from the PT

TLB misses can be handled in hardware or software
Software allows application to assist in replacement decisions

Computer Science, Rutgers

22

CS 519: Operating System Theory
Where to Store Address Space?
Address space may be larger than physical memory
Where do we keep it?
Where do we keep the page table?

Computer Science, Rutgers

23

CS 519: Operating System Theory
Where to Store Address Space?
On the next device down our storage hierarchy, of course …

Memory

Disk
VM

Computer Science, Rutgers

24

CS 519: Operating System Theory
Where to Store Page Table?
Interestingly, use memory to
“enlarge” view of memory,
leaving LESS physical memory

In memory, of course …

This kind of overhead is common
For example, OS uses CPU
cycles to implement abstraction
of threads

OS

Gotta know what the right
trade-off is

Code
Globals

P0 Page Table

Stack
P1 Page Table
Heap
Computer Science, Rutgers

25

Have to understand common
application characteristics
Have to be common enough!
Page tables can get large. What
to do?

CS 519: Operating System Theory
Two-Level Page-Table Scheme

Computer Science, Rutgers

26

CS 519: Operating System Theory
Two-Level Paging Example
A logical address (on 32-bit machine with 4K page size)
is divided into:
a page number consisting of 20 bits.
a page offset consisting of 12 bits.

Since the page table is paged, the page number is
further divided into:
a 10-bit page number.
a 10-bit page offset.

Computer Science, Rutgers

27

CS 519: Operating System Theory
Two-Level Paging Example
Thus, a logical address is as follows:
page number page offset
pi

p2

d

10

10

12

where pi is an index into the outer page table, and p2 is
the displacement within the page of the outer page
table.

Computer Science, Rutgers

28

CS 519: Operating System Theory
Address-Translation Scheme
Address-translation scheme for a two-level 32-bit
paging architecture

Computer Science, Rutgers

29

CS 519: Operating System Theory
Multilevel Paging and Performance
Since each level is stored as a separate table in memory, covering a
logical address to a physical one may take four memory accesses.
Even though time needed for one memory access is quintupled,
caching permits performance to remain reasonable.
Cache hit rate of 98 percent yields:
effective access time = 0.98 x 120 + 0.02 x 520
= 128 nanoseconds.
which is only a 28 percent slowdown in memory access time.

Computer Science, Rutgers

30

CS 519: Operating System Theory
Paging the Page Table
Page tables can still get large
What to do?

Non-page-able

Page the page table!

Kernel PT

P0 PT
Page-able
P1 PT
OS Segment

Computer Science, Rutgers

31

CS 519: Operating System Theory
Inverted Page Table
One entry for each real page of memory.
Entry consists of the virtual address of the page
stored in that real memory location, with information
about the process that owns that page.
Decreases memory needed to store each page table,
but increases time needed to search the table when a
page reference occurs.
Use hash table to limit the search to one — or at most
a few — page-table entries.

Computer Science, Rutgers

32

CS 519: Operating System Theory
Inverted Page Table Architecture

Computer Science, Rutgers

33

CS 519: Operating System Theory
How to Deal with VM > Size of Physical
Memory?
If address space of each process is ≤ size of physical
memory, then no problem
Still useful to deal with fragmentation

When VM larger than physical memory
Part stored in memory
Part stored on disk

How do we make this work?

Computer Science, Rutgers

34

CS 519: Operating System Theory
Demand Paging
To start a process (program), just load the code page
where the process will start executing
As process references memory (instruction or data)
outside of loaded page, bring in as necessary
How to represent fact that a page of VM is not yet in
memory?
Paging Table
0
1

B

2

0
1
2
3

A
C

1

v
i
i

Memory
0
1
2

A

Disk
B
C

VM
Computer Science, Rutgers

35

CS 519: Operating System Theory
Vs. Swapping

Computer Science, Rutgers

36

CS 519: Operating System Theory
Page Fault
What happens when process references a page marked
as invalid in the page table?
Page fault trap
Check that reference is valid
Find a free memory frame
Read desired page from disk
Change valid bit of page to v
Restart instruction that was interrupted by the trap

Is it easy to restart an instruction?
What happens if there is no free frame?
Computer Science, Rutgers

37

CS 519: Operating System Theory
Page Fault (Cont’d)
So, what can happen on a memory access?
TLB miss ⇒ read page table entry
TLB miss ⇒ read kernel page table entry
Page fault for necessary page of process page table
All frames are used ⇒ need to evict a page ⇒ modify a process
page table entry
TLB miss ⇒ read kernel page table entry
Page fault for necessary page of process page table
Uh oh, how deep can this go?

Read in needed page, modify page table entry, fill TLB

Computer Science, Rutgers

38

CS 519: Operating System Theory
Cost of Handling a Page Fault
Trap, check page table, find free memory frame (or find victim) …
about 200 - 600 µs
Disk seek and read … about 10 ms
Memory access … about 100 ns
Page fault degrades performance by ~100000!!!!!
And this doesn’t even count all the additional things that can happen
along the way

Better not have too many page faults!
If want no more than 10% degradation, can only have 1 page fault
for every 1,000,000 memory accesses
OS had better do a great job of managing the movement of data
between secondary storage and main memory

Computer Science, Rutgers

39

CS 519: Operating System Theory
Page Replacement
What if there’s no free frame left on a page fault?
Free a frame that’s currently being used
Select the frame to be replaced (victim)
Write victim back to disk
Change page table to reflect that victim is now invalid
Read the desired page into the newly freed frame
Change page table to reflect that new page is now valid
Restart faulting instructions

Optimization: do not need to write victim back if it has
not been modified (need dirty bit per page).

Computer Science, Rutgers

40

CS 519: Operating System Theory
Page Replacement
Highly motivated to find a good replacement policy
That is, when evicting a page, how do we choose the best victim
in order to minimize the page fault rate?

Is there an optimal replacement algorithm?
If yes, what is the optimal page replacement algorithm?
Let’s look at an example:
Suppose we have 3 memory frames and are running a program
that has the following reference pattern
7, 0, 1, 2, 0, 3, 0, 4, 2, 3

Suppose we know the reference pattern in advance ...
Computer Science, Rutgers

41

CS 519: Operating System Theory
Page Replacement
Suppose we know the access pattern in advance
7, 0, 1, 2, 0, 3, 0, 4, 2, 3

Optimal algorithm is to replace the page that will not be
used for the longest period of time
What’s the problem with this algorithm?
Realistic policies try to predict future behavior on the
basis of past behavior
Works because of locality

Computer Science, Rutgers

42

CS 519: Operating System Theory
FIFO
First-in, First-out
Be fair, let every page live in memory for the about the same
amount of time, then toss it.

What’s the problem?
Is this compatible with what we know about behavior of
programs?

How does it do on our example?
7, 0, 1, 2, 0, 3, 0, 4, 2, 3

Computer Science, Rutgers

43

CS 519: Operating System Theory
LRU
Least Recently Used
On access to a page, timestamp it
When need to evict a page, choose the one with the oldest
timestamp
What’s the motivation here?

Is LRU optimal?
In practice, LRU is quite good for most programs

Is it easy to implement?

Computer Science, Rutgers

44

CS 519: Operating System Theory
Not Frequently Used Replacement
Have a reference bit and software counter for each page frame
At each clock interrupt, the OS adds the reference bit of each
frame to its counter and then clears the reference bit
When need to evict a page, choose frame with lowest counter
What’s the problem?
Doesn’t forget anything, no sense of time – hard to evict a page that
was reference a lot sometime in the past but is no longer relevant to
the computation
Updating counters is expensive, especially since memory is getting
rather large these days

Can be improved with an aging scheme: counters are shifted right
before adding the reference bit and the reference bit is added to
the leftmost bit (rather than to the rightmost one)
Computer Science, Rutgers

45

CS 519: Operating System Theory
Clock (Second-Chance)
Arrange physical pages in a circle, with a clock hand
Hardware keeps 1 use bit per frame. Sets use bit on
memory reference to a frame.
If bit is not set, hasn’t been used for a while

On page fault:
Advance clock hand
Check use bit
If 1, has been used recently, clear and go on
If 0, this is our victim

Can we always find a victim?
Computer Science, Rutgers

46

CS 519: Operating System Theory
Nth-Chance
Similar to Clock except
Maintain a counter as well as a use bit
On page fault:
Advance clock hand
Check use bit
If 1, clear and set counter to 0
If 0, increment counter, if counter < N, go on, otherwise, this is our victim

Why?
N larger ⇒ better approximation of LRU

What’s the problem if N is too large?

Computer Science, Rutgers

47

CS 519: Operating System Theory
A Different Implementation of 2ndChance
Always keep a free list of some size n > 0
On page fault, if free list has more than n frames, get a frame
from the free list
If free list has only n frames, get a frame from the list, then
choose a victim from the frames currently being used and put
on the free list

On page fault, if page is on a frame on the free list,
don’t have to read page back in.
Implemented on VAX … works well, gets performance
close to true LRU

Computer Science, Rutgers

48

CS 519: Operating System Theory
Virtual Memory and Cache Conflicts
Assume an architecture with direct-mapped caches
First-level caches are often direct-mapped

The VM page size partitions a direct-mapped cache into
a set of cache-pages
Page frames are colored (partitioned into equivalence
classes) where pages with the same color map to the
same cache-page
Cache conflicts can occur only between pages with the
same color, and no conflicts can occur within a single
page
Computer Science, Rutgers

49

CS 519: Operating System Theory
VM Mapping to Avoid Cache Misses
Goal: to assign active virtual pages to different cachepages
A mapping is optimal if it avoids conflict misses
A mapping that assigns two or more active pages to the
same cache-page can induce cache conflict misses
Example:
a program with 4 active virtual pages
16 KB direct-mapped cache
a 4 KB page size partitions the cache into four cache-pages
there are 256 mappings of virtual pages into cache-pages but
only 4!= 24 are optimal
Computer Science, Rutgers

50

CS 519: Operating System Theory
Page Re-coloring
With a bit of hardware, can detect conflict at runtime
Count cache misses on a per-page basis

Can solve conflicts by re-mapping one or more of the
conflicting virtual pages into new page frames of
different color
Re-coloring

For the limited applications that have been studied,
only small performance gain (~10-15%)

Computer Science, Rutgers

51

CS 519: Operating System Theory
Multi-Programming Environment
Why?
Better utilization of resources (CPU, disks, memory, etc.)

Problems?
Mechanism – TLB?
Fairness?
Over commitment of memory

What’s the potential problem?
Each process needs it working set in order to perform well
If too many processes running, can thrash

Computer Science, Rutgers

52

CS 519: Operating System Theory
Thrashing Diagram

Why does paging work?
Locality model
Process migrates from one locality (working set) to another

Why does thrashing occur?
Σ size of working sets > total memory size
Computer Science, Rutgers

53

CS 519: Operating System Theory
Support for Multiple Processes
More than one address space can be loaded in memory
A register points to the current page table
OS updates the register when context switching
between threads from different processes
Most TLBs can cache more than one PT
Store the process id to distinguish between virtual addresses
belonging to different processes

If TLB caches only one PT then it must be flushed at
the process switch time

Computer Science, Rutgers

54

CS 519: Operating System Theory
Sharing

virtual address spaces
p1
p2
processes:
v-to-p memory mappings
physical memory:

Computer Science, Rutgers

55

CS 519: Operating System Theory
Copy-on-Write

p1

Computer Science, Rutgers

p1

p2

56

p2

CS 519: Operating System Theory
Resident Set Management
How many pages of a process should be brought in ?
Resident set size can be fixed or variable
Replacement scope can be local or global
Most common schemes implemented in the OS:
Variable allocation with global scope: simple - resident set size
is modified at the replacement time
Variable allocation with local scope: more complicated resident set size is modified to approximate the working set
size

Computer Science, Rutgers

57

CS 519: Operating System Theory
Working Set
The set of pages that have been referenced in the last
window of time
The size of the working set varies during the execution
of the process depending on the locality of accesses
If the number of pages allocated to a process covers
its working set then the number of page faults is small
Schedule a process only if enough free memory to load
its working set
How can we determine/approximate the working set
size?
Computer Science, Rutgers

58

CS 519: Operating System Theory
Working-Set Model
∆ ≡ working-set window ≡ a fixed number of page references
Example: 10,000 instruction

WSSi (working set of Process Pi) =
total number of pages referenced in the most recent ∆ (varies in
time)
if ∆ too small will not encompass entire locality.
if ∆ too large will encompass several localities.
if ∆ = ∞ ⇒ will encompass entire program.

D = Σ WSSi ≡ total demand frames
if D > m ⇒ Thrashing
Policy if D > m, then suspend one of the processes.
Computer Science, Rutgers

59

CS 519: Operating System Theory
Keeping Track of the Working Set
Approximate with interval timer + a reference bit
Example: ∆ = 10,000
Timer interrupts after every 5000 time units.
Keep in memory 2 bits for each page.
Whenever a timer interrupts copy and sets the values of all
reference bits to 0.
If one of the bits in memory = 1 ⇒ page in working set.

Why is this not completely accurate?
Improvement = 10 bits and interrupt every 1000 time
units.
Computer Science, Rutgers

60

CS 519: Operating System Theory
Page-Fault Frequency Scheme

Establish “acceptable” page-fault rate.
If actual rate too low, process loses frame.
If actual rate too high, process gains frame.
Computer Science, Rutgers

61

CS 519: Operating System Theory
Page-Fault Frequency
A counter per page stores the virtual time between
page faults (could be the number of page references)
An upper threshold for the virtual time is defined
If the amount of time since the last page fault is less
than the threshold, then the page is added to the
resident set
A lower threshold can be used to discard pages from
the resident set

Computer Science, Rutgers

62

CS 519: Operating System Theory
Resident Set Management
What’s the problem with the management policies that
we have just discussed?

Computer Science, Rutgers

63

CS 519: Operating System Theory
Other Considerations
Prepaging
Page size selection
fragmentation
table size
I/O overhead
locality

Computer Science, Rutgers

64

CS 519: Operating System Theory
Other Consideration (Cont.)
Program structure
Array A[1024, 1024] of integer
Each row is stored in one page
One frame
Program 1
1024 x 1024 page faults
Program 2
1024 page faults

for j := 1 to 1024 do
for i := 1 to 1024 do
A[i,j] := 0;
for i := 1 to 1024 do
for j := 1 to 1024 do
A[i,j] := 0;

I/O interlock and addressing
Computer Science, Rutgers

65

CS 519: Operating System Theory
Segmentation
Memory-management scheme that supports user view of memory.
A program is a collection of segments. A segment is a logical unit
such as:
main program,
procedure,
function,
local variables, global variables,
common block,
stack,
symbol table, arrays

Computer Science, Rutgers

66

CS 519: Operating System Theory
Logical View of Segmentation
1
4

1
2

3

2

4

3

user space
Computer Science, Rutgers

physical memory space
67

CS 519: Operating System Theory
Segmentation Architecture
Logical address consists of a two tuple: <segment-number, offset>
Segment table – maps two-dimensional physical addresses; each
table entry has:
base – contains the starting physical address where the segments
reside in memory.
limit – specifies the length of the segment.

Segment-table base register (STBR) points to the segment table’s
location in memory.
Segment-table length register (STLR) indicates number of
segments used by a program; segment number s is legal if s < STLR.

Computer Science, Rutgers

68

CS 519: Operating System Theory
Segmentation Architecture (Cont.)
Relocation.
dynamic
by segment table

Sharing.
shared segments
same segment number

Allocation.
first fit/best fit
external fragmentation

Computer Science, Rutgers

69

CS 519: Operating System Theory
Segmentation Architecture (Cont.)
Protection. With each entry in segment table
associate:
validation bit = 0 ⇒ illegal segment
read/write/execute privileges

Protection bits associated with segments; code sharing
occurs at segment level.
Since segments vary in length, memory allocation is a
dynamic storage-allocation problem.
A segmentation example is shown in the following
diagram
Computer Science, Rutgers

70

CS 519: Operating System Theory
Sharing of segments

Computer Science, Rutgers

71

CS 519: Operating System Theory
Segmentation with Paging – MULTICS
The MULTICS system solved problems of external
fragmentation and lengthy search times by paging the
segments.
Solution differs from pure segmentation in that the
segment-table entry contains not the base address of
the segment, but rather the base address of a page
table for this segment.

Computer Science, Rutgers

72

CS 519: Operating System Theory
MULTICS Address Translation Scheme

Computer Science, Rutgers

73

CS 519: Operating System Theory
Segmentation with Paging – Intel 386
As shown in the following diagram, the Intel 386 uses
segmentation with paging for memory management with
a two-level paging scheme.

Computer Science, Rutgers

74

CS 519: Operating System Theory
Intel 30386 address translation

Computer Science, Rutgers

75

CS 519: Operating System Theory
Summary
Virtual memory is a way of introducing another level in our memory
hierarchy in order to abstract away the amount of memory actually
available on a particular system
This is incredibly important for “ease-of-programming”
Imagine having to explicitly check for size of physical memory and
manage it in each and every one of your programs

It’s also useful to prevent fragmentation in multi-programming
environments
Can be implemented using paging (sometime segmentation or both)
Page fault is expensive so can’t have too many of them
Important to implement good page replacement policy

Have to watch out for thrashing!!
Computer Science, Rutgers

76

CS 519: Operating System Theory
Single Address Space
What’s the point?
Virtual address space is currently used for three purposes
Provide the illusion of a (possibly) larger address space than physical
memory
Provide the illusion of a contiguous address space while allowing for
non-contiguous storage in physical memory
Protection

Protection, provided through private address spaces, makes
sharing difficult
There is no inherent reason why protection should be provided
by private address spaces

Computer Science, Rutgers

77

CS 519: Operating System Theory
Private Address Spaces vs. Sharing
virtual address spaces
p1

p2

processes:
v-to-p memory mappings
physical memory:

Shared physical page may be mapped to different virtual pages
when shared
BTW, what happens if we want to page red page out?

This variable mapping makes sharing of pointer-based data
structures difficult
Storing these data structures on disk is also difficult
Computer Science, Rutgers

78

CS 519: Operating System Theory
Private Address Space vs. Sharing
(Cont’d)
Most complex data structures are pointer-based
Various techniques have been developed to deal with
this
Linearization
Pointer swizzling: translation of pointers
OS support for multiple processes mapping the same physical
page to the same virtual page

All above techniques are either expensive (linearization
and swizzling) or have shortcomings (mapping to same
virtual page requires previous agreement)
Computer Science, Rutgers

79

CS 519: Operating System Theory
Opal: The Basic Idea
Provide a single virtual address space to all processes in
the system …
Can be used on a single machine or set of machines on a LAN

… but … but … won’t we run out of address space?
Enough for 500 years if allocated at 1 Gigabyte per second

A virtual address means the same thing to all processes
Share and save to secondary storage data structures as is

Computer Science, Rutgers

80

CS 519: Operating System Theory
Opal: The Basic Idea

Code

P0

OS

Data

Code
Globals

Data

Stack
Code
Data

Heap

Computer Science, Rutgers

P1

81

CS 519: Operating System Theory
Opal: Basic Mechanisms
Protection domain ≡ process
Container for all resources allocated to a running instantiation of a
program
Contains identity of “user”, which can be used for access control
(protection)

Virtual address space is allocated in chunks – segments
Segments can be persistent, meaning they might be stored on
secondary storage, and so cannot be garbage collected

Segments (and other resources) are named by capabilities
Capability is an “un-forgeable” set of rights to access a resource
(we’ll learn more about this later)
Access control + identity

capabilities

Can attach to a segment once have a capability for it

Portals: protection domain entry points (RPC)
Computer Science, Rutgers

82

CS 519: Operating System Theory
Opal: Issues
Naming of segments: capabilities
Recycling of addresses: reference counting
Non-contiguity of address space: segments cannot
grow, so must request segments that are large enough
for data structures that assume contiguity

Private static data: must use register-relative
addressing

Computer Science, Rutgers

83

CS 519: Operating System Theory

More Related Content

What's hot

Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Computer architecture memory system
Computer architecture memory systemComputer architecture memory system
Computer architecture memory systemMazin Alwaaly
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Memory management ppt
Memory management pptMemory management ppt
Memory management pptManishaJha43
 
Virtual memory presentation
Virtual memory presentationVirtual memory presentation
Virtual memory presentationRanjeet Kumar
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt Arpita Naik
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management Maitree Patel
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Parallel computing
Parallel computingParallel computing
Parallel computingVinay Gupta
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)Sohaib Danish
 
Memory management based on MCA
Memory management  based on MCAMemory management  based on MCA
Memory management based on MCAAbhiSaxena16
 

What's hot (20)

Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Computer architecture memory system
Computer architecture memory systemComputer architecture memory system
Computer architecture memory system
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Memory management ppt
Memory management pptMemory management ppt
Memory management ppt
 
Cache coherence ppt
Cache coherence pptCache coherence ppt
Cache coherence ppt
 
Virtual memory presentation
Virtual memory presentationVirtual memory presentation
Virtual memory presentation
 
Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt
 
Memory management
Memory managementMemory management
Memory management
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Parallel computing
Parallel computingParallel computing
Parallel computing
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Cache memory
Cache memoryCache memory
Cache memory
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)
 
Memory management based on MCA
Memory management  based on MCAMemory management  based on MCA
Memory management based on MCA
 

Viewers also liked

Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Operating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management ConceptsOperating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management ConceptsPeter Tröger
 
37 segmentation
37 segmentation37 segmentation
37 segmentationmyrajendra
 
Combined paging and segmentation
Combined paging and segmentationCombined paging and segmentation
Combined paging and segmentationTech_MX
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategiesDr. Loganathan R
 
COMPUTER MEMORY : TYPES & FUNCTIONS
COMPUTER MEMORY : TYPES & FUNCTIONSCOMPUTER MEMORY : TYPES & FUNCTIONS
COMPUTER MEMORY : TYPES & FUNCTIONSAngel Mary George
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and SolutionsColin058
 

Viewers also liked (9)

Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Operating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management ConceptsOperating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management Concepts
 
Computer Memory Systems
Computer Memory SystemsComputer Memory Systems
Computer Memory Systems
 
37 segmentation
37 segmentation37 segmentation
37 segmentation
 
Combined paging and segmentation
Combined paging and segmentationCombined paging and segmentation
Combined paging and segmentation
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
COMPUTER MEMORY : TYPES & FUNCTIONS
COMPUTER MEMORY : TYPES & FUNCTIONSCOMPUTER MEMORY : TYPES & FUNCTIONS
COMPUTER MEMORY : TYPES & FUNCTIONS
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and Solutions
 

Similar to Memory management

Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptxSourabhRaj29
 
Main memory os - prashant odhavani- 160920107003
Main memory   os - prashant odhavani- 160920107003Main memory   os - prashant odhavani- 160920107003
Main memory os - prashant odhavani- 160920107003Prashant odhavani
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OSC.U
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Paging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementkazim Hussain
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementAjit Nayak
 
Memory Managment(OS).pptx
Memory Managment(OS).pptxMemory Managment(OS).pptx
Memory Managment(OS).pptxRohitPaul71
 
Bab 4
Bab 4Bab 4
Bab 4n k
 

Similar to Memory management (20)

Unit 5Memory management.pptx
Unit 5Memory management.pptxUnit 5Memory management.pptx
Unit 5Memory management.pptx
 
Main memory os - prashant odhavani- 160920107003
Main memory   os - prashant odhavani- 160920107003Main memory   os - prashant odhavani- 160920107003
Main memory os - prashant odhavani- 160920107003
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
OSCh9
OSCh9OSCh9
OSCh9
 
Ch9 OS
Ch9 OSCh9 OS
Ch9 OS
 
OS_Ch9
OS_Ch9OS_Ch9
OS_Ch9
 
Memory management
Memory managementMemory management
Memory management
 
Memory+management
Memory+managementMemory+management
Memory+management
 
Ch8
Ch8Ch8
Ch8
 
Memory management
Memory managementMemory management
Memory management
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
Paging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory management
 
Memory comp
Memory compMemory comp
Memory comp
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Operating Systems Part III-Memory Management
Operating Systems Part III-Memory ManagementOperating Systems Part III-Memory Management
Operating Systems Part III-Memory Management
 
Memory Managment(OS).pptx
Memory Managment(OS).pptxMemory Managment(OS).pptx
Memory Managment(OS).pptx
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Ch07
Ch07Ch07
Ch07
 
Bab 4
Bab 4Bab 4
Bab 4
 
Unit 5-lecture-2
Unit 5-lecture-2Unit 5-lecture-2
Unit 5-lecture-2
 

More from VELAMMAL INSTITUTE OF TECHNOLOGY (7)

cache memory management
cache memory managementcache memory management
cache memory management
 
cache memory
 cache memory cache memory
cache memory
 
cache
cachecache
cache
 
Zigbee technology
Zigbee technology Zigbee technology
Zigbee technology
 
VIBRATIONAL ENERGY HARVESTING POWER FROM ROAD SPEED BRAKER
VIBRATIONAL ENERGY HARVESTING POWER FROM ROAD SPEED BRAKERVIBRATIONAL ENERGY HARVESTING POWER FROM ROAD SPEED BRAKER
VIBRATIONAL ENERGY HARVESTING POWER FROM ROAD SPEED BRAKER
 
Eigg mod23.1
Eigg mod23.1Eigg mod23.1
Eigg mod23.1
 
wireless traffic density control using sensor
wireless traffic density control using sensorwireless traffic density control using sensor
wireless traffic density control using sensor
 

Recently uploaded

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Memory management

  • 2. Memory Hierarchy Memory Cache Registers Question: What if we want to support programs that require more memory than what’s available in the system? Computer Science, Rutgers 2 CS 519: Operating System Theory
  • 3. Memory Hierarchy Virtual Memory Memory Cache Registers Answer: Pretend we had something bigger: Virtual Memory Computer Science, Rutgers 3 CS 519: Operating System Theory
  • 4. Virtual Memory: Paging A page is a cacheable unit of virtual memory The OS controls the mapping between pages of VM and memory page frame More flexible (at a cost) Cache Memory Memory Computer Science, Rutgers 4 VM CS 519: Operating System Theory
  • 5. Two Views of Memory View from the hardware – shared physical memory View from the software – what a process “sees”: private virtual address space Memory management in the OS coordinates these two views Consistency: all address space can look “basically the same” Relocation: processes can be loaded at any physical address Protection: a process cannot maliciously access memory belonging to another process Sharing: may allow sharing of physical memory (must implement control) Computer Science, Rutgers 5 CS 519: Operating System Theory
  • 6. Paging From Fragmentation Could have been motivated by fragmentation problem under multi-programming environment New Job Memory Computer Science, Rutgers Memory 6 CS 519: Operating System Theory
  • 7. Dynamic Storage-Allocation Problem How to satisfy a request of size n from a list of free holes. First-fit: Allocate the first hole that is big enough. 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 entier list. Produces the largest leftover hole. First-fit and best-fit better than worst-fit in terms of speed and storage utilization. Computer Science, Rutgers 7 CS 519: Operating System Theory
  • 8. Virtual Memory: Segmentation Job 0 Job 1 Memory Computer Science, Rutgers 8 CS 519: Operating System Theory
  • 9. Virtual Memory Virtual memory is the OS abstraction that gives the programmer the illusion of an address space that may be larger than the physical address space Virtual memory can be implemented using either paging or segmentation but paging is presently most common Actually, a combination is usually used but the segmentation scheme is typically very simple (e.g., a fixed number of fixed-size segments) Virtual memory is motivated by both Convenience: the programmer does not have to deal with the fact that individual machines may have very different amount of physical memory Fragmentation in multi-programming environments Computer Science, Rutgers 9 CS 519: Operating System Theory
  • 10. Basic Concepts: Pure Paging and Segmentation Paging: memory divided into equal-sized frames. All process pages loaded into non-necessarily contiguous frames Segmentation: each process divided into variable-sized segments. All process segments loaded into dynamic partitions that are not necessarily contiguous Computer Science, Rutgers 10 CS 519: Operating System Theory
  • 11. Hardware Translation Processor translation box (MMU) Physical memory Translation from logical to physical can be done in software but without protection Why “without” protection? Hardware support is needed to ensure protection Simplest solution with two registers: base and size Computer Science, Rutgers 11 CS 519: Operating System Theory
  • 12. Segmentation Hardware virtual address offset + physical address segment segment table Computer Science, Rutgers 12 CS 519: Operating System Theory
  • 13. Segmentation Segments are of variable size Translation done through a set of (base, size, state) registers - segment table State: valid/invalid, access permission, reference bit, modified bit Segments may be visible to the programmer and can be used as a convenience for organizing the programs and data (i.e code segment or data segments) Computer Science, Rutgers 13 CS 519: Operating System Theory
  • 14. Paging hardware virtual address page # + offset physical address page table Computer Science, Rutgers 14 CS 519: Operating System Theory
  • 15. Paging Pages are of fixed size The physical memory corresponding to a page is called page frame Translation done through a page table indexed by page number Each entry in a page table contains the physical frame number that the virtual page is mapped to and the state of the page in memory State: valid/invalid, access permission, reference bit, modified bit, caching Paging is transparent to the programmer Computer Science, Rutgers 15 CS 519: Operating System Theory
  • 16. Combined Paging and Segmentation Some MMU combine paging with segmentation Segmentation translation is performed first The segment entry points to a page table for that segment The page number portion of the virtual address is used to index the page table and look up the corresponding page frame number Segmentation not used much anymore so we’ll concentrate on paging UNIX has simple form of segmentation but does not require any hardware support Computer Science, Rutgers 16 CS 519: Operating System Theory
  • 17. Address Translation virtual address CPU p d f physical address f d d p f page table Computer Science, Rutgers 17 Memory CS 519: Operating System Theory
  • 18. Translation Lookaside Buffers Translation on every memory access ⇒ must be fast What to do? Caching, of course … Why does caching work? That is, we still have to lookup the page table entry and use it to do translation, right? Same as normal memory cache – cache is smaller so can spend more $$ to make it faster Computer Science, Rutgers 18 CS 519: Operating System Theory
  • 19. Translation Lookaside Buffer Cache for page table entries is called the Translation Lookaside Buffer (TLB) Typically fully associative No more than 64 entries Each TLB entry contains a page number and the corresponding PT entry On each memory access, we look for the page ⇒ frame mapping in the TLB Computer Science, Rutgers 19 CS 519: Operating System Theory
  • 20. Translation Lookaside Buffer Computer Science, Rutgers 20 CS 519: Operating System Theory
  • 21. Address Translation virtual address CPU p d f physical address f d d TLB p/f f Computer Science, Rutgers 21 Memory CS 519: Operating System Theory
  • 22. TLB Miss What if the TLB does not contain the appropriate PT entry? TLB miss Evict an existing entry if does not have any free ones Replacement policy? Bring in the missing entry from the PT TLB misses can be handled in hardware or software Software allows application to assist in replacement decisions Computer Science, Rutgers 22 CS 519: Operating System Theory
  • 23. Where to Store Address Space? Address space may be larger than physical memory Where do we keep it? Where do we keep the page table? Computer Science, Rutgers 23 CS 519: Operating System Theory
  • 24. Where to Store Address Space? On the next device down our storage hierarchy, of course … Memory Disk VM Computer Science, Rutgers 24 CS 519: Operating System Theory
  • 25. Where to Store Page Table? Interestingly, use memory to “enlarge” view of memory, leaving LESS physical memory In memory, of course … This kind of overhead is common For example, OS uses CPU cycles to implement abstraction of threads OS Gotta know what the right trade-off is Code Globals P0 Page Table Stack P1 Page Table Heap Computer Science, Rutgers 25 Have to understand common application characteristics Have to be common enough! Page tables can get large. What to do? CS 519: Operating System Theory
  • 26. Two-Level Page-Table Scheme Computer Science, Rutgers 26 CS 519: Operating System Theory
  • 27. Two-Level Paging Example A logical address (on 32-bit machine with 4K page size) is divided into: a page number consisting of 20 bits. a page offset consisting of 12 bits. Since the page table is paged, the page number is further divided into: a 10-bit page number. a 10-bit page offset. Computer Science, Rutgers 27 CS 519: Operating System Theory
  • 28. Two-Level Paging Example Thus, a logical address is as follows: page number page offset pi p2 d 10 10 12 where pi is an index into the outer page table, and p2 is the displacement within the page of the outer page table. Computer Science, Rutgers 28 CS 519: Operating System Theory
  • 29. Address-Translation Scheme Address-translation scheme for a two-level 32-bit paging architecture Computer Science, Rutgers 29 CS 519: Operating System Theory
  • 30. Multilevel Paging and Performance Since each level is stored as a separate table in memory, covering a logical address to a physical one may take four memory accesses. Even though time needed for one memory access is quintupled, caching permits performance to remain reasonable. Cache hit rate of 98 percent yields: effective access time = 0.98 x 120 + 0.02 x 520 = 128 nanoseconds. which is only a 28 percent slowdown in memory access time. Computer Science, Rutgers 30 CS 519: Operating System Theory
  • 31. Paging the Page Table Page tables can still get large What to do? Non-page-able Page the page table! Kernel PT P0 PT Page-able P1 PT OS Segment Computer Science, Rutgers 31 CS 519: Operating System Theory
  • 32. Inverted Page Table One entry for each real page of memory. Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page. Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs. Use hash table to limit the search to one — or at most a few — page-table entries. Computer Science, Rutgers 32 CS 519: Operating System Theory
  • 33. Inverted Page Table Architecture Computer Science, Rutgers 33 CS 519: Operating System Theory
  • 34. How to Deal with VM > Size of Physical Memory? If address space of each process is ≤ size of physical memory, then no problem Still useful to deal with fragmentation When VM larger than physical memory Part stored in memory Part stored on disk How do we make this work? Computer Science, Rutgers 34 CS 519: Operating System Theory
  • 35. Demand Paging To start a process (program), just load the code page where the process will start executing As process references memory (instruction or data) outside of loaded page, bring in as necessary How to represent fact that a page of VM is not yet in memory? Paging Table 0 1 B 2 0 1 2 3 A C 1 v i i Memory 0 1 2 A Disk B C VM Computer Science, Rutgers 35 CS 519: Operating System Theory
  • 36. Vs. Swapping Computer Science, Rutgers 36 CS 519: Operating System Theory
  • 37. Page Fault What happens when process references a page marked as invalid in the page table? Page fault trap Check that reference is valid Find a free memory frame Read desired page from disk Change valid bit of page to v Restart instruction that was interrupted by the trap Is it easy to restart an instruction? What happens if there is no free frame? Computer Science, Rutgers 37 CS 519: Operating System Theory
  • 38. Page Fault (Cont’d) So, what can happen on a memory access? TLB miss ⇒ read page table entry TLB miss ⇒ read kernel page table entry Page fault for necessary page of process page table All frames are used ⇒ need to evict a page ⇒ modify a process page table entry TLB miss ⇒ read kernel page table entry Page fault for necessary page of process page table Uh oh, how deep can this go? Read in needed page, modify page table entry, fill TLB Computer Science, Rutgers 38 CS 519: Operating System Theory
  • 39. Cost of Handling a Page Fault Trap, check page table, find free memory frame (or find victim) … about 200 - 600 µs Disk seek and read … about 10 ms Memory access … about 100 ns Page fault degrades performance by ~100000!!!!! And this doesn’t even count all the additional things that can happen along the way Better not have too many page faults! If want no more than 10% degradation, can only have 1 page fault for every 1,000,000 memory accesses OS had better do a great job of managing the movement of data between secondary storage and main memory Computer Science, Rutgers 39 CS 519: Operating System Theory
  • 40. Page Replacement What if there’s no free frame left on a page fault? Free a frame that’s currently being used Select the frame to be replaced (victim) Write victim back to disk Change page table to reflect that victim is now invalid Read the desired page into the newly freed frame Change page table to reflect that new page is now valid Restart faulting instructions Optimization: do not need to write victim back if it has not been modified (need dirty bit per page). Computer Science, Rutgers 40 CS 519: Operating System Theory
  • 41. Page Replacement Highly motivated to find a good replacement policy That is, when evicting a page, how do we choose the best victim in order to minimize the page fault rate? Is there an optimal replacement algorithm? If yes, what is the optimal page replacement algorithm? Let’s look at an example: Suppose we have 3 memory frames and are running a program that has the following reference pattern 7, 0, 1, 2, 0, 3, 0, 4, 2, 3 Suppose we know the reference pattern in advance ... Computer Science, Rutgers 41 CS 519: Operating System Theory
  • 42. Page Replacement Suppose we know the access pattern in advance 7, 0, 1, 2, 0, 3, 0, 4, 2, 3 Optimal algorithm is to replace the page that will not be used for the longest period of time What’s the problem with this algorithm? Realistic policies try to predict future behavior on the basis of past behavior Works because of locality Computer Science, Rutgers 42 CS 519: Operating System Theory
  • 43. FIFO First-in, First-out Be fair, let every page live in memory for the about the same amount of time, then toss it. What’s the problem? Is this compatible with what we know about behavior of programs? How does it do on our example? 7, 0, 1, 2, 0, 3, 0, 4, 2, 3 Computer Science, Rutgers 43 CS 519: Operating System Theory
  • 44. LRU Least Recently Used On access to a page, timestamp it When need to evict a page, choose the one with the oldest timestamp What’s the motivation here? Is LRU optimal? In practice, LRU is quite good for most programs Is it easy to implement? Computer Science, Rutgers 44 CS 519: Operating System Theory
  • 45. Not Frequently Used Replacement Have a reference bit and software counter for each page frame At each clock interrupt, the OS adds the reference bit of each frame to its counter and then clears the reference bit When need to evict a page, choose frame with lowest counter What’s the problem? Doesn’t forget anything, no sense of time – hard to evict a page that was reference a lot sometime in the past but is no longer relevant to the computation Updating counters is expensive, especially since memory is getting rather large these days Can be improved with an aging scheme: counters are shifted right before adding the reference bit and the reference bit is added to the leftmost bit (rather than to the rightmost one) Computer Science, Rutgers 45 CS 519: Operating System Theory
  • 46. Clock (Second-Chance) Arrange physical pages in a circle, with a clock hand Hardware keeps 1 use bit per frame. Sets use bit on memory reference to a frame. If bit is not set, hasn’t been used for a while On page fault: Advance clock hand Check use bit If 1, has been used recently, clear and go on If 0, this is our victim Can we always find a victim? Computer Science, Rutgers 46 CS 519: Operating System Theory
  • 47. Nth-Chance Similar to Clock except Maintain a counter as well as a use bit On page fault: Advance clock hand Check use bit If 1, clear and set counter to 0 If 0, increment counter, if counter < N, go on, otherwise, this is our victim Why? N larger ⇒ better approximation of LRU What’s the problem if N is too large? Computer Science, Rutgers 47 CS 519: Operating System Theory
  • 48. A Different Implementation of 2ndChance Always keep a free list of some size n > 0 On page fault, if free list has more than n frames, get a frame from the free list If free list has only n frames, get a frame from the list, then choose a victim from the frames currently being used and put on the free list On page fault, if page is on a frame on the free list, don’t have to read page back in. Implemented on VAX … works well, gets performance close to true LRU Computer Science, Rutgers 48 CS 519: Operating System Theory
  • 49. Virtual Memory and Cache Conflicts Assume an architecture with direct-mapped caches First-level caches are often direct-mapped The VM page size partitions a direct-mapped cache into a set of cache-pages Page frames are colored (partitioned into equivalence classes) where pages with the same color map to the same cache-page Cache conflicts can occur only between pages with the same color, and no conflicts can occur within a single page Computer Science, Rutgers 49 CS 519: Operating System Theory
  • 50. VM Mapping to Avoid Cache Misses Goal: to assign active virtual pages to different cachepages A mapping is optimal if it avoids conflict misses A mapping that assigns two or more active pages to the same cache-page can induce cache conflict misses Example: a program with 4 active virtual pages 16 KB direct-mapped cache a 4 KB page size partitions the cache into four cache-pages there are 256 mappings of virtual pages into cache-pages but only 4!= 24 are optimal Computer Science, Rutgers 50 CS 519: Operating System Theory
  • 51. Page Re-coloring With a bit of hardware, can detect conflict at runtime Count cache misses on a per-page basis Can solve conflicts by re-mapping one or more of the conflicting virtual pages into new page frames of different color Re-coloring For the limited applications that have been studied, only small performance gain (~10-15%) Computer Science, Rutgers 51 CS 519: Operating System Theory
  • 52. Multi-Programming Environment Why? Better utilization of resources (CPU, disks, memory, etc.) Problems? Mechanism – TLB? Fairness? Over commitment of memory What’s the potential problem? Each process needs it working set in order to perform well If too many processes running, can thrash Computer Science, Rutgers 52 CS 519: Operating System Theory
  • 53. Thrashing Diagram Why does paging work? Locality model Process migrates from one locality (working set) to another Why does thrashing occur? Σ size of working sets > total memory size Computer Science, Rutgers 53 CS 519: Operating System Theory
  • 54. Support for Multiple Processes More than one address space can be loaded in memory A register points to the current page table OS updates the register when context switching between threads from different processes Most TLBs can cache more than one PT Store the process id to distinguish between virtual addresses belonging to different processes If TLB caches only one PT then it must be flushed at the process switch time Computer Science, Rutgers 54 CS 519: Operating System Theory
  • 55. Sharing virtual address spaces p1 p2 processes: v-to-p memory mappings physical memory: Computer Science, Rutgers 55 CS 519: Operating System Theory
  • 57. Resident Set Management How many pages of a process should be brought in ? Resident set size can be fixed or variable Replacement scope can be local or global Most common schemes implemented in the OS: Variable allocation with global scope: simple - resident set size is modified at the replacement time Variable allocation with local scope: more complicated resident set size is modified to approximate the working set size Computer Science, Rutgers 57 CS 519: Operating System Theory
  • 58. Working Set The set of pages that have been referenced in the last window of time The size of the working set varies during the execution of the process depending on the locality of accesses If the number of pages allocated to a process covers its working set then the number of page faults is small Schedule a process only if enough free memory to load its working set How can we determine/approximate the working set size? Computer Science, Rutgers 58 CS 519: Operating System Theory
  • 59. Working-Set Model ∆ ≡ working-set window ≡ a fixed number of page references Example: 10,000 instruction WSSi (working set of Process Pi) = total number of pages referenced in the most recent ∆ (varies in time) if ∆ too small will not encompass entire locality. if ∆ too large will encompass several localities. if ∆ = ∞ ⇒ will encompass entire program. D = Σ WSSi ≡ total demand frames if D > m ⇒ Thrashing Policy if D > m, then suspend one of the processes. Computer Science, Rutgers 59 CS 519: Operating System Theory
  • 60. Keeping Track of the Working Set Approximate with interval timer + a reference bit Example: ∆ = 10,000 Timer interrupts after every 5000 time units. Keep in memory 2 bits for each page. Whenever a timer interrupts copy and sets the values of all reference bits to 0. If one of the bits in memory = 1 ⇒ page in working set. Why is this not completely accurate? Improvement = 10 bits and interrupt every 1000 time units. Computer Science, Rutgers 60 CS 519: Operating System Theory
  • 61. Page-Fault Frequency Scheme Establish “acceptable” page-fault rate. If actual rate too low, process loses frame. If actual rate too high, process gains frame. Computer Science, Rutgers 61 CS 519: Operating System Theory
  • 62. Page-Fault Frequency A counter per page stores the virtual time between page faults (could be the number of page references) An upper threshold for the virtual time is defined If the amount of time since the last page fault is less than the threshold, then the page is added to the resident set A lower threshold can be used to discard pages from the resident set Computer Science, Rutgers 62 CS 519: Operating System Theory
  • 63. Resident Set Management What’s the problem with the management policies that we have just discussed? Computer Science, Rutgers 63 CS 519: Operating System Theory
  • 64. Other Considerations Prepaging Page size selection fragmentation table size I/O overhead locality Computer Science, Rutgers 64 CS 519: Operating System Theory
  • 65. Other Consideration (Cont.) Program structure Array A[1024, 1024] of integer Each row is stored in one page One frame Program 1 1024 x 1024 page faults Program 2 1024 page faults for j := 1 to 1024 do for i := 1 to 1024 do A[i,j] := 0; for i := 1 to 1024 do for j := 1 to 1024 do A[i,j] := 0; I/O interlock and addressing Computer Science, Rutgers 65 CS 519: Operating System Theory
  • 66. Segmentation Memory-management scheme that supports user view of memory. A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, local variables, global variables, common block, stack, symbol table, arrays Computer Science, Rutgers 66 CS 519: Operating System Theory
  • 67. Logical View of Segmentation 1 4 1 2 3 2 4 3 user space Computer Science, Rutgers physical memory space 67 CS 519: Operating System Theory
  • 68. Segmentation Architecture Logical address consists of a two tuple: <segment-number, offset> Segment table – maps two-dimensional physical addresses; each table entry has: base – contains the starting physical address where the segments reside in memory. limit – specifies the length of the segment. Segment-table base register (STBR) points to the segment table’s location in memory. Segment-table length register (STLR) indicates number of segments used by a program; segment number s is legal if s < STLR. Computer Science, Rutgers 68 CS 519: Operating System Theory
  • 69. Segmentation Architecture (Cont.) Relocation. dynamic by segment table Sharing. shared segments same segment number Allocation. first fit/best fit external fragmentation Computer Science, Rutgers 69 CS 519: Operating System Theory
  • 70. Segmentation Architecture (Cont.) Protection. With each entry in segment table associate: validation bit = 0 ⇒ illegal segment read/write/execute privileges Protection bits associated with segments; code sharing occurs at segment level. Since segments vary in length, memory allocation is a dynamic storage-allocation problem. A segmentation example is shown in the following diagram Computer Science, Rutgers 70 CS 519: Operating System Theory
  • 71. Sharing of segments Computer Science, Rutgers 71 CS 519: Operating System Theory
  • 72. Segmentation with Paging – MULTICS The MULTICS system solved problems of external fragmentation and lengthy search times by paging the segments. Solution differs from pure segmentation in that the segment-table entry contains not the base address of the segment, but rather the base address of a page table for this segment. Computer Science, Rutgers 72 CS 519: Operating System Theory
  • 73. MULTICS Address Translation Scheme Computer Science, Rutgers 73 CS 519: Operating System Theory
  • 74. Segmentation with Paging – Intel 386 As shown in the following diagram, the Intel 386 uses segmentation with paging for memory management with a two-level paging scheme. Computer Science, Rutgers 74 CS 519: Operating System Theory
  • 75. Intel 30386 address translation Computer Science, Rutgers 75 CS 519: Operating System Theory
  • 76. Summary Virtual memory is a way of introducing another level in our memory hierarchy in order to abstract away the amount of memory actually available on a particular system This is incredibly important for “ease-of-programming” Imagine having to explicitly check for size of physical memory and manage it in each and every one of your programs It’s also useful to prevent fragmentation in multi-programming environments Can be implemented using paging (sometime segmentation or both) Page fault is expensive so can’t have too many of them Important to implement good page replacement policy Have to watch out for thrashing!! Computer Science, Rutgers 76 CS 519: Operating System Theory
  • 77. Single Address Space What’s the point? Virtual address space is currently used for three purposes Provide the illusion of a (possibly) larger address space than physical memory Provide the illusion of a contiguous address space while allowing for non-contiguous storage in physical memory Protection Protection, provided through private address spaces, makes sharing difficult There is no inherent reason why protection should be provided by private address spaces Computer Science, Rutgers 77 CS 519: Operating System Theory
  • 78. Private Address Spaces vs. Sharing virtual address spaces p1 p2 processes: v-to-p memory mappings physical memory: Shared physical page may be mapped to different virtual pages when shared BTW, what happens if we want to page red page out? This variable mapping makes sharing of pointer-based data structures difficult Storing these data structures on disk is also difficult Computer Science, Rutgers 78 CS 519: Operating System Theory
  • 79. Private Address Space vs. Sharing (Cont’d) Most complex data structures are pointer-based Various techniques have been developed to deal with this Linearization Pointer swizzling: translation of pointers OS support for multiple processes mapping the same physical page to the same virtual page All above techniques are either expensive (linearization and swizzling) or have shortcomings (mapping to same virtual page requires previous agreement) Computer Science, Rutgers 79 CS 519: Operating System Theory
  • 80. Opal: The Basic Idea Provide a single virtual address space to all processes in the system … Can be used on a single machine or set of machines on a LAN … but … but … won’t we run out of address space? Enough for 500 years if allocated at 1 Gigabyte per second A virtual address means the same thing to all processes Share and save to secondary storage data structures as is Computer Science, Rutgers 80 CS 519: Operating System Theory
  • 81. Opal: The Basic Idea Code P0 OS Data Code Globals Data Stack Code Data Heap Computer Science, Rutgers P1 81 CS 519: Operating System Theory
  • 82. Opal: Basic Mechanisms Protection domain ≡ process Container for all resources allocated to a running instantiation of a program Contains identity of “user”, which can be used for access control (protection) Virtual address space is allocated in chunks – segments Segments can be persistent, meaning they might be stored on secondary storage, and so cannot be garbage collected Segments (and other resources) are named by capabilities Capability is an “un-forgeable” set of rights to access a resource (we’ll learn more about this later) Access control + identity capabilities Can attach to a segment once have a capability for it Portals: protection domain entry points (RPC) Computer Science, Rutgers 82 CS 519: Operating System Theory
  • 83. Opal: Issues Naming of segments: capabilities Recycling of addresses: reference counting Non-contiguity of address space: segments cannot grow, so must request segments that are large enough for data structures that assume contiguity Private static data: must use register-relative addressing Computer Science, Rutgers 83 CS 519: Operating System Theory