UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 4.8 Free with a free account
Paging
Introduction to Operating Systems · Chapter 4: Memory ManagementSection 4.8 · lesson 32 of 839 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Cache memory →← Virtual MemoryNext lesson: Cache memory →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
How page tables and the TLB map logical pages to physical frames.
- Explain how paging places fixed-size pages into any free frames
- Split a logical address into a page number and offset and translate it to a physical address
- Calculate effective access time from a TLB hit ratio
- Describe what a page table entry holds besides the frame number
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,275 words). Read along, or search it.
Opening Analogy
A Library Catalog for Book Parts
A library doesn't keep a big book's parts in one long row. Part one might sit on shelf five, part two on shelf nine, and part three on shelf two. A card in the catalog tells you where each one is. Computers do the same with programs. They chop memory into equal pieces, put the pieces wherever there's room, and keep a catalog. The trick is how fast that catalog can be read.
The Problem
Enough Free Space, No Single Block
Sam, who runs a small online bakery, has a program that needs twenty thousand bytes. RAM has enough free space in total, but only in small, scattered gaps between other programs. If the program had to sit in one unbroken block, it wouldn't fit anywhere. Paging fixes that, by cutting everything into equal pieces.
Pages and Frames
Any Page Fits Any Free Frame
The program's logical memory is cut into pages. Physical RAM is cut into frames, and each frame is exactly the size of a page. Any page can go into any free frame, in any order. Sam's five pages land in frames five, nine, three, seven and one, between other programs' pages. Nobody had to find five free frames side by side.
Page Table
One Entry per Page
The OS keeps one page table for each program. It's a list with one entry per page, and each entry holds the frame where that page lives. The program sees a tidy row of pages, zero to four. The hardware quietly looks each one up. So paging ends the hunt for one hole big enough. Lesson four point eleven shows that trouble.
Leftover Space
Unused Bytes in the Last Page
Paging doesn't remove all waste. A program that needs ten thousand bytes still gets whole pages. With pages of four kibibytes, that's three pages: twelve thousand two hundred eighty-eight bytes. So two thousand two hundred eighty-eight bytes of the last page go unused. On this Mac, with its sixteen kibibyte pages, it's one page, and six thousand three hundred eighty-four bytes go unused. Bigger pages mean smaller page tables, but more waste in the last page.
Address Split
Page Number and Offset
So how does the hardware find one byte? The CPU sends a logical address: a single number. Think of a hotel room number, like three twelve. The three is the floor, and twelve is the room on that floor. A logical address splits the same way: into a page number, which page, and an offset, how far into that page. With four kibibyte pages, divide the address by four thousand ninety-six. The quotient is the page number, and the remainder is the offset. Take thirteen thousand. It's three times four thousand ninety-six, with seven hundred twelve left over. So page three, offset seven hundred twelve.
Binary Shortcut
The Low Twelve Bits Are the Offset
In binary, it's even easier, because four thousand ninety-six is two to the power twelve. The low twelve bits are the offset, and all the bits above them are the page number. Thirteen thousand in sixteen bits: the top four bits say three, and the low twelve say seven hundred twelve. No division needed. On this Mac, pages are sixteen kibibytes, two to the fourteen. So there, the low fourteen bits are the offset.
Translation
Frame Times Page Size Plus Offset
Now the page table does its job. Page three lives in frame seven. The physical address is the frame number times the page size, plus the offset. Seven times four thousand ninety-six is twenty-eight thousand six hundred seventy-two. Add seven hundred twelve, and you get twenty-nine thousand three hundred eighty-four. Only the page number was swapped for a frame number. The offset is copied unchanged. A common mistake is to add the page number to the offset, or to forget to multiply the frame by the page size.
Quick Check
Translating Logical Address 9,000
Quick check, with the same page table, where page two lives in frame three. A program uses logical address nine thousand, and pages are four kibibytes. Which physical address does it reach? Thirteen thousand ninety-six? Nine thousand? Or eight hundred eleven? Pause, and decide. Thirteen thousand ninety-six. Nine thousand is two times four thousand ninety-six, plus eight hundred eight. So it's page two, offset eight hundred eight. Page two is in frame three. Three times four thousand ninety-six, plus eight hundred eight, is thirteen thousand ninety-six. Nine thousand forgets to swap the page for the frame. Eight hundred eleven adds the frame to the offset, without multiplying.
Hidden Cost
Two Memory Trips per Access
There's a hidden cost. The page table itself sits in RAM. So every memory access now takes two trips: one to read the page table entry, and one to read the data. That would make every program run at about half speed. So something has to cut out the extra trip.
TLB
The Translation Lookaside Buffer
The cure is a small, very fast memory inside the CPU, called the TLB: the translation lookaside buffer. It remembers the latest page-to-frame answers. The CPU looks aside at it first. On a TLB hit, the frame comes back at once, and the CPU goes straight to the data. On a TLB miss, the CPU reads the page table in RAM, and stores the answer in the TLB for next time. Programs reuse the same pages again and again, as lesson four point nine explains. So hits are common.
Effective Access Time
Weighting Hits and Misses
How much does it help? The effective access time is the average time per access, weighted by how often each path happens. Take illustrative numbers: one hundred nanoseconds for a RAM access, and ten for a TLB lookup. A hit costs ten plus one hundred: one hundred ten. A miss costs ten plus one hundred plus one hundred: two hundred ten. With no TLB at all, every access costs two hundred nanoseconds. At a hit ratio of point nine, the average is one hundred twenty. At point nine eight, it's one hundred twelve, close to the ideal one hundred ten.
Quick Check
Access Time at a 0.8 Hit Ratio
Quick check. Same numbers: one hundred nanoseconds for RAM, and ten for the TLB. But this program's hit ratio is only point eight. What's its effective access time? One hundred twenty nanoseconds? One hundred sixty? Or one hundred thirty? Pause, and decide. One hundred thirty. Eight tenths of the accesses cost one hundred ten each, which gives eighty-eight. Two tenths cost two hundred ten each, which gives forty-two. Eighty-eight plus forty-two is one hundred thirty. One hundred sixty just averages the two costs, and ignores how often each happens. One hundred twenty is the answer for point nine.
Page Table Entries
Present Bits, Protection Bits and Levels
A page table entry holds more than a frame number. It also carries a few small flags. A present bit says whether the page is in RAM at all. If it's clear, the CPU raises the page fault from lesson four point seven. Protection bits say whether the page may be read, written, or run. So one program can't scribble on another's pages, or change its own code by accident. Tables can be big. With thirty-two bit addresses and four kibibyte pages, there are two to the twenty pages: over a million entries for each program. So real systems split the table into levels, and keep only the parts in use.
Real Case
Two Boxes on a Napkin
Ivy, who looks after the computers at a school, once explained all this to Sam on a napkin. She drew two boxes: a small one labeled TLB, and a big one labeled RAM. Nine times out of ten, she said, the answer is in the small box. Only when it isn't do we walk to the big one.
Key Takeaways
Pages, Frames, Tables and the TLB
To recap. Paging cuts a program into pages, and RAM into frames of the same size. Any page fits any free frame. A page table maps each page to its frame. A logical address splits into a page number and an offset. The physical address is the frame times the page size, plus the offset. And the TLB remembers recent answers, so most accesses skip the extra trip.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Paging
How do you translate a logical address to a physical address in paging?
What is a TLB in an operating system?
How do you calculate effective access time with a TLB?
Does paging eliminate memory fragmentation?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →