Introduction to the Intel x86’s support for “virtual” memory

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Management Unit
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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.
Segmentation and Paging Considerations
Allocating Memory.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Introduction to the Intel x86’s support for “virtual” memory
IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.
Linux Memory Issues An introduction to some low-level and some high-level memory management concepts.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Chapter 8.3: Memory Management
Memory Management (II)
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Lecture 11: Memory Management
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Linux Memory Issues Introduction. Some Architecture History 8080 (late-1970s) 16-bit address (64-KB) 8086 (early-1980s) 20-bit address (1-MB) (mid-’80s)
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 3.2 : Virtual Memory
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Memory Management Chapter 5.
Virtual Memory I Chapter 8.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
UNIT 2 Memory Management Unit and Segment Description and Paging
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Memory Management Chapter 7.
CSNB334 Advanced Operating Systems 5. Memory Management
Computer Architecture Lecture 28 Fasih ur Rehman.
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.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
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.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
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.
Paging Example What is the data corresponding to the logical address below:
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
80386DX.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory 1 1.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
Memory Management. Why memory management? n Processes need to be loaded in memory to execute n Multiprogramming n The task of subdividing the user area.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Virtual Memory Chapter 8.
SLC/VER1.0/OS CONCEPTS/OCT'99
Computer Organization
Memory Management.
Chapter 2 Memory and process management
Practice Six Chapter Eight.
Module IV Memory Organization.
Introduction to the Intel x86’s support for “virtual” 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
COMP755 Advanced Operating Systems
Virtual Memory 1 1.
Presentation transcript:

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

What is ‘paging’? It’s a scheme for dynamically remapping addresses for fixed-size memory-blocks Physical address-space Virtual 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 #3 Task #1 physical memory Task #2

Several ‘paging’ schemes Intel’s design for ‘paging’ has continued to evolve since its introduction in 80386 CPU New processors 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 = 212 So the address of any page-frame will have its lowest 12-bits equal to zeros Example: page six begins at 0x00006000

Physical Address of the Page-Directory 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’ 31 Physical Address of the Page-Directory

Page-Directory The Page-Directory occupies one frame, so it has room for 1024 4-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 1024 4-byte entries Page-Table entries may contain pointers

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

Address-translation The CPU examines any virtual address it encounters, subdividing it into three fields 31 22 21 12 11 0 index into page-directory index into page-table offset into page-frame 10-bits 10-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 31 12 11 10 9 8 7 6 5 4 3 2 1 0 PAGE-FRAME BASE ADDRESS AVAIL D A P C D P W T U W P 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 31 12 11 10 9 8 7 6 5 4 3 2 1 0 PAGE-TABLE BASE ADDRESS AVAIL P S A P C D P W T U W P 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) PS = Page-Size (0=4KB, 1 = 4MB) PWT = Page Write-Through (1=yes, 0 = no) PCD = Page Cache-Disable (1 = yes, 0 = no)

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 3 2 1 0 reserved (=0) U / S W / R P Legend: P (Present): 1=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

‘ioremap()’ and ‘iounmap()’ The Linux kernel offers ‘helper functions’ that let modules request modifications to the kernel’s page-mapping tables Examples: void * ioremap( phys_addr, length ); adds page-table entries that ‘map’ the region void iounmap( void *virt_addr ); remove previously created page-table entries

Our ‘ioremap.c’ demo To illustrate use of the ‘ioremap()’ function we created this Linux kernel module It asks the kernel to set up a ‘mapping’ of the page at physical address 0xFEE00000 into the kernel’s virtual address-space This is the page where each processor’s Local-APIC resides Each APIC register is ‘paragraph-aligned’

Multiple Logical Processors Multi-CORE CPU CPU CPU 1 I/O APIC LOCAL APIC LOCAL APIC Each processor’s Local-APIC contains a 32-bit register (at offset 0x20) known as the Local-APIC Identification Register which has an 8-bit field intended to store that processor’s unique identification-number 31 24 23 0 processor ID-number reserved

‘ioread32()’ Our module uses the ‘ioread32()’ function to ‘input’ the current value from one of the Local-APIC device’s memory-mapped registers (and could use the companion function ‘iowrite32()’ to ‘output’ a value to these device-registers (It might be possible on x86 platforms just to use normal “C” assignment-statements)

In-class exercise #1 Try modifying the ‘ioremap.c’ module so it accesses the Local-APIC Identification Register using a C assignment-statement instead of calling the ‘ioread32()’ function Example: int id_register; // declare local ‘int’ variable id_register = *(int *)(lapic+0x20); // input value

In-class exercise #2 Examine the effect on page-table entries when the ‘ioremap_nocache()’ function replaces the ‘ioremap()’ function in our ‘ioremap.c’ module HINT: Install our ‘dram.ko’ kernel object and then use our ‘fileview’ utility to view the page-directory and the page-tables