IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.

Slides:



Advertisements
Similar presentations
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Advertisements

OS Fall’02 Virtual Memory Operating Systems Fall 2002.
Paging Hardware With TLB
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Introduction to the Intel x86’s support for “virtual” memory
Operating Systems: Segments 1 Segmentation Hardware Support single user program system: – wish somehow to relocate address 0 to after operating system.
IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
IA-32 Processor Architecture
Page-Faults in Linux How can we study the handling of page-fault exceptions?
The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Memory Management (II)
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Chapter 3.2 : Virtual Memory
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
Venturing into 64-bit mode Examining the steps needed to take the processor into IA-32e mode -- and then back out again.
Venturing into protected-mode
Introduction to the Intel x86’s support for “virtual” memory
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 2: 80386DX Internal Architecture & Data Organization.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
UNIT 2 Memory Management Unit and Segment Description and Paging
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Computer Architecture Lecture 28 Fasih ur Rehman.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 34 Paging Implementation.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-8 Memory Management (2) Department of Computer Science and Software.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Computer Architecture 2011 – VM x86 1 Computer Architecture Virtual Memory (VM) – x86 By Dan Tsafrir, 30/5/2011 Presentation based on slides by Lihu Rappoport.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Implementation of Page Table Page table is kept in main memory Page-table base.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
Virtual Memory 1 1.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Page Table Implementation. Readings r Silbershatz et al:
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
CHAPTER 3-3: PAGE MAPPING MEMORY MANAGEMENT. VIRTUAL MEMORY Key Idea Disassociate addresses referenced in a running process from addresses available in.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Silberschatz, Galvin and Gagne  Operating System Concepts Paging Logical address space of a process can be noncontiguous; process is allocated.
Microprocessor system architectures – IA32 paging Jakub Yaghob.
CS203 – Advanced Computer Architecture Virtual Memory.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Chapter Overview General Concepts IA-32 Processor Architecture
CS161 – Design and Architecture of Computer
ECE232: Hardware Organization and Design
CS161 – Design and Architecture of Computer
Anton Burtsev February, 2017
143A: Principles of Operating Systems Lecture 5: Address translation
x86 segmentation, page tables, and interrupts
CS 301 Fall 2002 Computer Organization
Introduction to the Intel x86’s support for “virtual” memory
Virtual Memory Hardware
Practical Session 9, Memory
Introduction to the Pentium’s support for “virtual” memory
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS444/544 Operating Systems II Virtual Memory
Virtual Memory 1 1.
Presentation transcript:

IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory

What is ‘paging’? It’s a scheme for dynamically remapping addresses for fixed-size memory-blocks Virtual address-spacePhysical address-space

What’s ‘paging’ good for? For efficient ‘time-sharing’ among multiple tasks, an operating system needs to have several programs residing in main memory at the same time To accomplish this using actual physical memory-addressing would require doing address-relocation calculations each time a program was loaded (to avoid conflicting with any addresses already being used)

Why use ‘Paging’? Use of ‘paging’ allows ‘relocations’ to be done just once (by the linker), and every program can ‘reuse’ the same addresses Task #1 Task #2 Task #3 physical memory

How to enable paging PGPG CDCD NWNW AMAM WPWP NENE ETET TSTS EMEM MPMP PEPE Control Register CR0 Protected-Mode must be enabled (PE=1) Then ‘Paging’ can be enabled (set PG=1) # Here is how you can enable paging (must be in protected-mode) mov%cr0, %eax# get current machine status bts$31, %eax# turn on the PE-bit’s image mov%eax, %cr0# put modified status in CR0 jmppg# now flush the prefetch queue pg: # but you had better prepare the ‘mapping’ beforehand!

Several ‘paging’ schemes Intel’s design for ‘paging’ has continued to evolve since its introduction in CPU Pentiums support the initial design, as well as several optional extensions We shall describe the initial design which is simplest and remains as the ‘default’ It is based on subdividing the entire 4GB virtual address-space into 4KB blocks

Terminology The 4KB memory-blocks are called ‘page frames’ -- and they are non-overlapping Therefore each page-frame begins at a memory-address which is a multiple of 4K Remember: 4K = 4 x 1024 = 4096 = 2 12 So the address of any page-frame will have its lowest 12-bits equal to zeros Example: page six begins at 0x

Control Register CR3 Register CR3 is used by the CPU to find the tables in memory which will define the address-translation that it should employ This table is called the ‘Page Directory’ and its address must be ‘page-aligned’ Physical Address of the Page-Directory 310

Page-Directory The Page-Directory occupies one frame, so it has room for byte entries Each page-directory entry may contain a pointer to a further data-structure, called a Page-Table (also page-aligned 4KB size) Each Page-Table occupies one frame and has enough room for byte entries Page-Table entries may contain pointers

Two-Level Translation Scheme PAGE DIRECTORY CR3 PAGE TABLES PAGE FRAMES

Address-translation The CPU examines any virtual address it encounters, subdividing it into three fields offset into page-frame index into page-directory index into page-table bits 12-bits This field selects one of the 1024 array-entries in the Page-Directory This field selects one of the 1024 array-entries in that Page-Table This field provides the offset to one of the 4096 bytes in that Page-Frame

Page-Level ‘protection’ Each entry in a Page-Table can assign a collection of ‘attributes’ to the Page-Frame that it points to; for example: –The P-bit (page is ‘present’) can be used by the operating system to support its implementation of “demand paging” –The W/R-bit can be used to mark a page as ‘Writable’ or as ‘Read-Only’ –The U/S-bit can be used to mark a page as ‘User accessible’ or as ‘Supervisor-Only’

Format of a Page-Table entry PAGE-FRAME BASE ADDRESSPWU PWTPWT PCDPCD AD AVAIL LEGEND P = Present (1=yes, 0=no) W = Writable (1 = yes, 0 = no) U = User (1 = yes, 0 = no) A = Accessed (1 = yes, 0 = no) D = Dirty (1 = yes, 0 = no) PWT = Page Write-Through (1=yes, 0 = no) PCD = Page Cache-Disable (1 = yes, 0 = no)

Format of a Page-Directory entry PAGE-TABLE BASE ADDRESSPWU PWTPWT PCDPCD A0 PSPS AVAIL LEGEND P = Present (1=yes, 0=no) W = Writable (1 = yes, 0 = no) U = User (1 = yes, 0 = no) A = Accessed (1 = yes, 0 = no) PWT = Page Write-Through (1=yes, 0 = no) PCD = Page Cache-Disable (1 = yes, 0 = no) PS = Page-Size (0=4KB, 1 = 4MB)

Violations When a task violates the page-attributes of any Page-Frame, the CPU will generate a ‘Page-Fault’ Exception (interrupt 0x0E) Then the operating system’s page-fault exception-handler gets control and can take whatever action it deems is suitable The CPU will provide help to the OS in determining why a Page-Fault occurred

The Error-Code format The CPU will push an Error-Code onto the operating system’s stack P W/RW/R U/SU/S reserved (=0) Legend: P (Present): 0=attempted to access a ‘not-present’ page W/R (Write/Read): 1=attempted to write to a ‘read-only’ page U/S (User/Supervisor): 1=user attempted to access a ‘supervisor’ page User means that CPL = 3; Supervisor means that CPL = 0, 1, or 2

Control Register CR2 Whenever a ‘Page-Fault’ is encountered, the CPU will save the virtual-address that caused that fault into the CR2 register –If the CPU was trying to modify the value of an operand in a ‘read-only’ page, then that operand’s virtual address is written into CR2 –If the CPU was trying to read the value of an operand in a supervisor-only page (or was trying to fetch-and- execute an instruction) while CPL=3, the relevant virtual address will be written into CR2

Identity-mapping When the CPU first turns on the ‘paging’ capability, it must be executing code from an ‘identity-mapped’ page (or it crashes!) We have created a demo-program that shows how to create the Page-Directory and Page-Tables for an identity-mapping of the entire bottom megabyte of RAM The demo is named ‘trypages.s’

Page-Table initialization (1MB) Only the first 256 page-frames need to be mapped (so one Page-Table will suffice): # This code-fragment shows how to construct a loop in assembly language # that will initialize the first 256 Page-Table entries for an identity-mapping # of the conventional memory area (i.e., the bottom megabyte of memory).code32 xor%ebx, %ebx# Page-Table’s initial array-index mov$256, %ecx# number of entries to be defined mov$0x , %eax# entry 0: P=W=U=1 nxpte: mov%eax, pgtbl(, %ebx, 4)# write this table-entry add$0x1000, %eax# compute next entry inc%ebx# increment array-index loopnxpte# setup all the entries

CR3 and Task-Switching link esp0 ss0 esp1 ss1 esp2 ss2 PTDB EIP ss0 ES CS SS DS FS GS LDTR IOMAPTRAP EFLAGS EAX ECX EDX EBX ESP EBP ESI EDI I/O permission bitmap = field is ‘static’ = field is ‘volatile’ = field is ‘reserved’ longwords 32-bits Page-Table Directory Base This value will get loaded into register CR3 as part of the context-switching mechanism when paging has been enabled (PG=1) So the ‘incoming task’ will automatically have its own individual mapping of its ‘virtual’ address-space to page-frames in the CPU’s ‘physical’ address-space

Extensions to ‘paging’ scheme In the Pentium Intel has provided several enhancements to the original 386 paging These enhancements are ‘optional’ and must be selectively enabled by software Control Register CR4 implements bits to “turn on” the desired ‘paging-extension’ and some other enhancements that are unrelated to the ‘paging’ architectures

Control Register CR4 VMXEVMXE PCEPCE PGEPGE MCEMCE PAEPAE PSEPSE DEDE TSDTSD PVIPVI VMEVME Legend (for paging-related extensions): PSE = Page-Size Extension is enabled (1 = yes, 0 = no) PAE = Page-Address Extension is enabled (1 = yes, 0 = no) PGE = Page-Global Extension is enabled (1 = yes, 0 = no)

Efficiency? When paging is enabled, every reference to memory requires the CPU to ‘translate’ the virtual address into a physical-address That ‘translation’ is based on table-lookups These lookups must be done ‘sequentially’ So ‘address-translation’ could be costly in terms of CPU speed – a high percentage of instructions typically refer to memory

The ‘TLB’ solution When the CPU has performed the table lookups that map a virtual-address to a physical-address, it “remembers” that relationship by saving the pair of page- addresses (virtual-page  physical page) in a special CPU cache known as the TLB (“Translation Look-aside Buffer”) So future references to that virtual page can be quickly resolved via that cache

4-way set-associative The TLB is implemented as a ‘4-way set- associative’ cache -- it’s like a parallelized version of a Hash Table (with ‘evictions’) Due to the ‘locality of reference’ principle, the TLB concept generally works well in most common programming contexts as an efficient ‘speedup’ of the page-address table-lookup translation mechanism Modifying CR3 will invalidate the TLB

In-class Exercise Modify the ‘trypages.s’ demo so it does a little bit of ‘non-identical’ page-mapping (i.e., so some virtual-address is different from its physical-address) For example, try mapping the page-frame at virtual address 0x to physical address 0x000B8000 (by changing the Page-Table entry at table-index 8), then write a message at address 0x

The exercise illustrated video memory physical page-framesvirtual page-frames 0x000B8000 0x