Memory Management Part2
Memory Management Part2
1
Overview
• Paging
• Page Tables
• TLB
• Hierarchical Pages
• Hashed Pages
• Inverted Pages
• Segmentation
2
Address Translation
Scheme
■ Address generated by CPU is divided into:
0
▪ Page size = 4 bytes
Pag Fram
e
▪ Process address 1 e
space 21
011
= 4 pages
3
▪ Physical address
space
= 8 frames
▪ Logical address:
(1,3)
1101
= 0111 1
▪ Physical address:
(6,3)
Addressing in Paging
▪ |d| = 12 bits
▪ |p| = 32 – 12 = 20
▪ bits
No. of = 512 M / 4 K
frames = 128
▪ |f| = 17 bits K
Frame Number – It gives the frame number in which the current page
you are looking for is present.
The number of bits required depends on the number of frames. Frame bit
is also known as address translation bit.
Number of bits for frame = Size of physical memory/frame size
Other Optional bits
1.Present/Absent bit – Present or absent bit says whether a particular
page you are looking for is present or absent. In case if it is not present,
that is called Page Fault. It is set to 0 if the corresponding page is not in
memory. Used to control page fault by the operating system to support
virtual memory. Sometimes this bit is also known as valid/invalid bits.
2.Protection bit – Protection bit says that what kind of protection you
want on that page. So, these bit for the protection of the page frame
(read, write etc).
3.Referenced bit – Referenced bit will say whether this page has been
referred in the last clock cycle or not. It is set to 1 by hardware when the
page is accessed.
Page Table Entries in Page Table
4.Caching enabled/disabled – Sometimes we need the fresh data.
this bit enables or disable caching of the page.
5.Modified bit – Modified bit says whether the page has been modified
or not. Modified means sometimes you might try to write something on
to the page. If a page is modified, then whenever you should replace that
page with some other page, then the modified information should be
kept on the hard disk or it has to be written back or it has to be saved
back. It is set to 1 by hardware on write-access to page which is used to
avoid writing when swapped out. Sometimes this modified bit is also
called as the Dirty bit.
Implementation of Page
Table
• Page table is kept in main memory
• Page-table base register (PTBR) points to the page table
• Page-table length register (PTLR) indicates size of the
page table
• In this scheme every data/instruction access requires two
memory accesses
– One for the page table and one for the data / instruction
• The two memory access problem can be solved
– by the use of a special fast-lookup hardware cache
– called associative memory or translation look-aside buffers
(TLBs)
Implementation of Page Table
▪ Teffective = 2Tmem
▪ Teffective is not acceptable
▪ Use a special, small, fast lookup hardware, called
translation look-aside buffer (TLB)
▪ Typically 64–1024 entries
▪ An entry is (key, value)
▪ Parallel search for key; on a hit, value is returned
Implementation of Page Table
Logical
address: (p, d)
p
Implementation of Page Table
▪ T on a hit = T +T
effective mem TLB
▪
T on a miss = 2T +T
effective mem TLB
T = HR (T +T ) + MR (T + 2T )
effective TLB mem TLB mem
Example
▪ Tmem = 100
nsec
▪ TTLB = 20 nsec
▪ Hit ratio is
80%
▪T Teffective
==
effective
?
0.8 (20 + 100) + 0.2 (20 + 2x100)
= 140 nanoseconds
Example
▪ Tmem = 100
nsec
▪ TTLB = 20 nsec
▪ Hit ratio is
98%
▪ Teffective = ?
Teffective = 0.98 (20 + 100) + 0.02 (20 + 2x100)
= 122 nanoseconds
Segmentation
3
4
5
Segmentation
11
1 44
2
5
3
4
22
5 33
Segmentation
11
44
1
2 5
3 22
4
segme
nt 33
5
table
Segmentation
CPU
Segmentation Architecture
▪ Dynamic Storage
Allocation
▪ First fit
▪ Best fit
▪ Worst fit
▪ External
fragmentation
Example
Address Translation
▪ Logical and Physical Addresses
▪ (2, 399) – PA: 4300+399 = 4699
=
4700