CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

16.317: Microprocessor System Design I
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
Segmentation and Paging Considerations
Configuring the Operating System Configure Performance Options Processor scheduling and memory usage Virtual memory Memory for network performance Configure.
UQC152H3 Advanced OS Memory Management under Linux.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Chapter 8.3: Memory Management
Memory Management (II)
Linux Vs. Windows NT Memory Management Hitesh Kumar
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
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.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
Virtual Memory By: Dinouje Fahih. Definition of Virtual Memory Virtual memory is a concept that, allows a computer and its operating system, to use a.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Address Translation Mechanism of 80386
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
CSNB334 Advanced Operating Systems 5. Memory Management
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
Computer Architecture Lecture 28 Fasih ur Rehman.
Linux Virtual Memory for Intel Processor
Lecture 19: Virtual Memory
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.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Lecture 9: Memory Hierarchy Virtual Memory Kai Bu
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:
Chapter 4 Memory Management Virtual Memory.
80386DX.
Memory Addressing in Linux (Chap. 2 in Understanding the Linux Kernel) J. H. Wang Oct. 15, 2009.
Virtual Memory 1 1.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Swap Space and Other Memory Management Issues Operating Systems: Internals and Design Principles.
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
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”
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Microprocessor system architectures – IA32 paging Jakub Yaghob.
Memory Management Chapter 5 Advanced Operating System.
CS203 – Advanced Computer Architecture Virtual Memory.
The Memory Hierarchy Lecture 31 20/07/2009Lecture 31_CA&O_Engr. Umbreen Sabir.
Memory Management & Virtual Memory. Hierarchy Cache Memory : Provide invisible speedup to main memory.
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Memory COMPUTER ARCHITECTURE
Lecture 12 Virtual Memory.
COMBINED PAGING AND SEGMENTATION
Address Translation Mechanism of 80386
Chapter 8: Main Memory.
CSCI206 - Computer Organization & Programming
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Introduction to the Intel x86’s support for “virtual” memory
Linux 운영체제 및 응용 Lecture Note 2 Memory Addressing 오상규 정보통신대학원.
Practical Session 9, Memory
Introduction to the Pentium’s support for “virtual” memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
COMP755 Advanced Operating Systems
Virtual Memory.
Virtual Memory 1 1.
Presentation transcript:

CE6105 Linux 作業系統 Linux Operating System 許 富 皓

Chapter 2 Memory Addressing

Linux Memory Segmentation under IA-32 or

Segments and Linear Address Space

The Paging Unit

A hardware Circuit. Translates linear addresses into physical ones. Checks the requested access type against the access rights of the linear address. If the memory access is not valid, it generates a Page Fault exception

Page Contiguous linear addresses are grouped in fixed-length intervals called pages. The term “ page ” is also refer to: A set of linear addresses The data contained in this group of addresses.

Page Frame The paging unit thinks of all RAM as partitioned into fixed-length page frames (physical pages). The size of a page is equal to the size of a page frame. Usually the size of a page frame is 4KB; however, sometimes a larger page frame size may also be used.

Page vs. Page Frame Page Frame: A constituent of main memory A storage area Page: A block of data that can be stored in a page frame.

Enable Paging Starting with the 80386, all 80x86 processors support paging; paging is enabled by setting the PG flag of the control register cr0. When PG flag=0, a virtual address is equal to a physical address. Paging mechanism is used in protected mode.

Division of a Virtual Address A 32-bit virtual address is divided into 3 parts: Directory : the 10 most significant bits. Table : the 10 intermediate bits Offset : the 12 least significant bits. Directory (10) Table (10) Offset (12)

Terminologies The translation of linear addresses is accomplished in two steps, each based on a type of translation tables. The first translation table is called the Page Directory, and the second is called the Page Table. P.S.: In the discussion that follows, the lowercase "page table" term denotes any page storing the mapping between linear and physical addresses, while the capitalized "Page Table" term denotes a page in the last level of page tables. page table = Page Table  Page Directory

Translation Table Types Page Directory (each process has only ONE page directory table.) Page Table. Both of the above tables are located in main memory. Are initialized by kernel, before paging mechanism is activated.

Why Use a Two-Level Scheme Reduce the amount of RAM required for per-process page tables. Assume a process’s maximum virtual address space is 4 GB. For a single level scheme,2 20 entries are needed. If each translation table entry requires 4 bytes, then each process needs 2 20 *4=4MB memory to store its translation table. For a two-level scheme, translation tables are used only for those virtual memory regions actually used by a process (P.S.: For most processes, most virtual memory regions are not used. )

Translation Table Allocation Each active process must have a Page Directory assigned to it. The physical address of the Page Directory of the active process is stored in the control register cr3. Allocating page frames to a page table occurs only when the process needs to access it.

Paging of 80x86 -- The Directory Field and Table Field The Directory field within the virtual address determines the entry in the Page Directory that points to the proper page table. Hence, there are 2 10 entries in a page directory. Because each entry’s size is 4 bytes; a Page Directory uses 4 KB. The address’s Table filed, in turn, determines the entry in the Page Table that contains the physical address of the page frame containing the page. Similarly, each Page Table contains 2 10 entries. Because each entry’s size is 4 bytes; a Page Table uses 4 KB

Paging of 80x86 -- The Offset Field The offset field determines the relative position within the page frame. Each page frame consists of 4096 (i.e ) bytes of data.

Paging by 80x86 Processors

Double-Layered Paging with 4-KB Pages

Structures of Page Directories And Page Tables Both Page Directory entries and Page Tables have the same structure. Present flag Field containing the 20 most significant bits of a page frame physical address. Access flag Dirty flag Read/write flag User/Supervisor flag PCD and PWT flags Page size flag Global flag

Entry Fields (1): Present flag: 1: yes 0: no. Save the virtual address  cr2 Issue the Page Fault Exception. 20-bit physical address field: Contain the 20 most significant bits of a page frame physical address. The size of Page Directories, Page Tables, and page frame are all 4k bytes; therefore, the first physical address of the above entities is a multiple of 4 KB. In other words, the physical address’s least 12 significant bits are always zero and there is no need to store these 12 bits. Paging Unit

Entry Fields (2): Accessed flag: Set each time the paging unit addresses the corresponding page frame. When swapping out a page frame is needed, OS uses this flag as a parameter to decide which page frame should be swapped out. Dirty flag. Apply to Page Table entries only. When a write operation is performed on a page frame, its corresponding Page Table entry’s Dirty flag is set. As the Accessed flag, this flag is also used by OS when determining choosing which page frame to swap out. The paging unit never resets the above two flags; this must be done by the operating system.

Entry Fields (3): Read/Write flag: Contain the access right (Read/Write or Read) of the page or the Page Table. User/Supervisor flag: Contains the privilege level required to access the page or Page Table.

Entry Fields (4): PCD and PWT flags: Controls the way the page or Page Table is handled by the hardware cache. Page Size flag: Apply only to Page Directory entries: If it is set, the entry refers to a 2 MB– or 4 MB-long page frame. Global flag: Applies to Page Table entries only to prevent frequently used pages from being flushed from the TLB cache. Is used with the Page Global Enable ( PGE ) flag of cr4 register.

Extended Paging

Why Extended Paging Is Introduced ? Introduced starting from the Pentium model. Allows page frames to be 4MB instead of 4KB in size. Extended paging is used to translate large contiguous linear address ranges into corresponding physical ones; in these cases, the kernel can do without intermediate Page Tables and thus save memory and preserve TLB entries.

Is enabled by setting the Page Size flag of a Page Directory entry. setting the PSE flag of the cr4 processor register. Enable Extended Paging

Virtual Address Layout under Extended Paging Under extended paging, the paging unit divides the 32 bits of a linear address into two fields: Directory (10 bits). Offset (22 bits; P.S.: 2 22 =4MB) Directory Offset

New Futures of Page Directory Entries under Extended Paging Under extended paging, the structure of a Page Directory and the entries inside it are the same as those in regular paging, except: The Page Size flag is set. Only the 10 most significant bits of the 20-bit physical address field are significant.

Extended Paging

Single-Layered Paging with 4-MB Pages

Hardware Protection Scheme

Privilege Levels The segmentation unit uses four possible privilege levels to protect a segment (the two-bit request privilege levels, 0 for kernel mode, 3 for user mode). The paging unit uses a different strategy to protect Page Tables and page frames  the User/Supervisor flag. 0  CPU’s CPL must be less than 3 (i.e. for Linux, when the processor is in kernel mode.) 1  the corresponding Page Table or page frame can always be accessed.

Access Rights Instead of the three types of access rights (Read, Write, Execute) associated with segments (determined by the type field of a segment descriptor), only two types of access rights (Read, Write) are associated with page tables and pages and are determined by the Read/Write flags of corresponding page tables entries. Read/Write flag: 0: can be read. 1: can be read and write.

The Physical Address Extension (PAE) Paging Mechanism

Starting with the Pentium Pro, all Intel processors have 36 address lines; therefore, they are now able to address 2 36 =64GB of RAM when is in PAE mode. PAE is activated by setting the Physical Address Extension ( PAE ) flag in the cr4 control register. Question: CPU registers such as EIP, ESP, are still 32 bits; thus, how to transfer a 32-bit virtual address into a 36- bit physical one? Answer: Introduce a new paging mechanism. Physical Address Extension (PAE) Paging Mechanism (1)

Physical Address Extension (PAE) Paging Mechanism (2) The 64 GB (= 2 24 x2 12 ) of RAM are split into KB page frames. The entry size of Page Directories or Page Tables is increased from 4 bytes to 8 bytes; thus, each 4-KB page frame contains 512 (=2 9 ) entries instead of 1024 entries. The address field of each page table entry is increased form 20 bits to 24 bits; therefore, the address field can point to any of the KB page frames. A new level of page table is introduced --- the Page Directory Pointer Table (PDPT)

Physical Address Extension (PAE) Paging Mechanism (3) Each PDPT entry is 8 byte long. The PDPT has only 4 entries. The base address of a PDPT is store in cr3 control register. The PDPT is located in the first 4 GB of RAM (i.e. the 4 most significant bits are 0) and aligned to 32 bytes (2 5 ); therefore, the cr3 only needs 27 bits to point a PDPT (4+27+5=36.)

Physical Address Extension (PAE) Paging Mechanism (4) When PAE is activated, and the PS flag in Page Directory is cleared (i.e. each page frame is 4KB), a virtual address is split into the following four fields PDPT (2 bits), PD (9 bits), PT (9 bits), Offset (12 bits).

Physical Address Extension (PAE) Paging Mechanism (5) When PAE is activated, and the PS flag in Page Directory is set (i.e. each page frame is 2MB(=2 21 ), a virtual address is split into the following three fields PDPT (2 bits), PD (9 bits), Offset (21 bits).

Physical Address Extension (PAE) Paging Mechanism (6) The contribution of the PAE paging mechanism: Without the new mechanism, no matter how many RAM a system has, at most, the system can only access the first 4 GB of RAM. With the new mechanism, for a system with 64 GB of RAM, a system can access any subset of page frames of the 64 GB RAM. And the size of the subset is 4 GB. Question: When internal registers’ size is only 32 bits, how could a process address more than 4GB Physical addresses?

Paging for 64-bit Architectures All hardware paging systems for 64-bit processors make use of additional paging levels. The number of levels used depends on the type of processor.

Paging Levels in Some 64-bit Architectures platform name page sizenumber of address bits used number of paging levels Linear address splitting alpha8 KB ia644 KB ppc644 KB sh644 KB x86_644 KB

Locality Types Temporal locality The concept that a resource that is referenced at one point in time will be referenced again sometime in the near future. Spatial locality The concept that likelihood of referencing a resource is higher if a resource near it was just referenced. Sequential locality The concept that memory is accessed sequentially.

Locality Principle Locality principle holds for both data structures and programs, because of the cyclic structure of programs and the packing of related data into adjacent area.