UQC152H3 Advanced OS Memory Management under Linux.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Memory Management Unit
Paging Hardware With TLB
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.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Chapter 8.3: Memory Management
Memory Management (II)
Linux Vs. Windows NT Memory Management Hitesh Kumar
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Memory-Management Strategies.
Chapter 3.2 : Virtual Memory
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 8: Memory Management Dr. Mohamed Hefeeda.
CS2422 Assembly Language & System Programming September 22, 2005.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Segmentation CS 537 – Introduction to Operating Systems.
UNIT 2 Memory Management Unit and Segment Description and Paging
ITEC 325 Lecture 29 Memory(6). Review P2 assigned Exam 2 next Friday Demand paging –Page faults –TLB intro.
CS333 Intro to Operating Systems Jonathan Walpole.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
Cosc 3P92 Week 9 & 10 Lecture slides
CSNB334 Advanced Operating Systems 5. Memory Management
Linux Virtual Memory for Intel Processor
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.
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.
Chapter 8: Memory-Management Strategies. 8.2 Chapter 8: Memory Management Strategies n Background n Swapping n Contiguous Memory Allocation n Paging n.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Memory Addressing in Linux (Chap. 2, Understanding the Linux Kernel) J. H. Wang Oct. 20, 2008.
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.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Implementation of Page Table Page table is kept in main memory Page-table base.
Chapter 4 Memory Management Virtual Memory.
80386DX.
Memory Addressing in Linux (Chap. 2 in Understanding the Linux Kernel) J. H. Wang Oct. 15, 2009.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
1 Microprocessors CSE Protected Mode Memory Addressing Remember using real mode addressing we were previously able to address 1M Byte of memory.
Page Replacement Implementation Issues Text: –Tanenbaum ch. 4.7.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
CS203 – Advanced Computer Architecture Virtual Memory.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
W4118 Operating Systems Instructor: Junfeng Yang.
CSE 120 Principles of Operating
CSNB334 Advanced Operating Systems 5. Memory Management
Outline Paging Swapping and demand paging Virtual memory.
Chapter 8: Main Memory Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
143A: Principles of Operating Systems Lecture 5: Address translation
Page Replacement Implementation Issues
CSE 153 Design of Operating Systems Winter 2018
Chapter 8: Main Memory.
Virtual Memory Partially Adapted from:
CSCI206 - Computer Organization & Programming
Page Replacement Implementation Issues
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Lecture 10 Paging & TLBs
CS703 - Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Chapter 8: Main Memory CSS503 Systems Programming
Presentation transcript:

UQC152H3 Advanced OS Memory Management under Linux

Memory Addressing Segmentation and paging background Segmentation –Intel segmentation hardware –Linux use of Intel segmentation Paging –Intel paging hardware –Linux use of Intel paging Memory layout –Kernel layout in physical memory –Process virtual memory layout –Kernel virtual memory layout

Segmentation Background Motivated by logical use of memory areas –Code, heap, stack, etc. Base + offset –Segment registers contain base Segments variable size (usually large) Process as collection of segments –No notion of linear, contiguous memory –Similar to “multi-stream” files (Mac) Requires “segment table”

Paging Background Motivated by notion of linear, contiguous, "virtual" memory (space) –Every process has it's own "zero" address Uniform sized chunks (pages – 4K on Intel) Virtually contiguous pages may be physically scattered Virtual space may have "holes" Page table translates virtual "pages" to physical "page frames"

Intel Segmentation/Paging Intel address terminology: –Logical – segment + offset –Linear (virtual) – 0.. 4GB (64GB with PAE) –Physical Logical -> Linear -> Physical Paging can be disabled Segmentation required –Though you can just have one big segment

Intel Segmentation Hardware Segment registers: cs, ss, ds, es, fs, gs –Indices ("selectors") into "segment descriptor tables" Segment descriptor tables: GDT, LDT –Global and local (per process, in theory) –Each holds about 8000 descriptors Segment descriptors: 8 bytes each –Base/limit, code/data privileges, type –Cached in ro registers when seg registers loaded Task segment descriptor (TSS) –Special segment for holding process context

Segmentation in Linux History –Early versions segmented; now paged –Using "shared" segments simplifies things –Some RISC chips don't support segmentation Linux only uses GDT –LDTs allocated for Windows emulation –Each process has TSS and LDT descriptors –TSS is per-process; LDT is shared

Linux Descriptor Allocation GDT holds 8192 descriptors –4 primary, 4 APM, 4 unused –8180 left / 2 -> 4090 processes (limit in 2.2) Primary (shared) segments –Kernel code, kernel data –User code, user data –Segments overlap in linear address space 2.4 removes 4K process restriction

Intel Paging Hardware Page table "maps" linear address space –Some pages may be invalid –Address space grows/shrinks (mapping) New regions mapped by DLLs, mmap(), brk() –Pages (linear) vs. page frames (physical) Page may map to different frame after swap –Page tables stored in kernel data segment Intel page size: 4K or 4M ("jumbo pages") –Jumbo pages reduce table size Paging "enabled" by writing cr0 register

Intel Two-Level Paging "Page table" is actually a two-level tree –Page Directory (root) –Page Tables (children) –Pages (grandchildren) Linear address carved into three pieces –Directory (10), Table (10), Offset (12) –Entries: frame # + bookkeeping bits Bookkeeping bits: –Present, Accessed, Dirty –Read/Write, User/Supervisor, Page Size Jumbo pages –Map entire 4GB address space with just top-level Directory –No need for Tables! (Kernel uses this technique)

Three-Level Paging How big are page tables on 64 bit arch? –Sparc, Alpha, Itanium –Assume 16K pages => 32 M per process! Better idea: three-level paging trees –Page Global Directory (pgd) –Page Middle Directory (pmd) –Page Table (pt) Carve linear address into 4 pieces Conceptual paging model –On Intel, page middle directory is compiled out

Aside: Caching Exploit temporal and spatial locality L1 and L2 caches (on chip) Cache "lines" (32 bytes on Intel) Kernel developer goals: –Keep frequently used struct fields in the same cache line! –Spread lines out for large data structures to keep cache utilized –The "Cache Police"

TLB Translation Look-aside Buffer –Virtual to physical cache Must be flushed (invalidated) when address space mappings change A significant cost of context switch

Paging in Linux Three-level scheme –Middle directories "collapsed" w/ macro tricks –No bits assigned for middle directory On context switch (address space change) –Save/load registers in TSS –Install new top-level directory (write cr3) –Flush TLB Lot's of macros for: –Allocating/deallocating, altering, querying… –Page directories, tables, entries –Examples: set_pte(), mk_pte(), pte_young(), new_page_tables()

Kernel Physical Layout Kernel is "pinned" (non-swappable) Usually about 1M; mapped in first 2M Some "holes" in low memory –Zero frame always invalid (avoids null dereference) –ISA "i/o aperture" (640K.. 1M) Kernel layout symbols (System.map) –_text (code start) (usually about 1M) –_etext (initialized data start) –_edata (uninitialized data start) –_end (end of kernel data) Remaining frames allocated as needed by kernel page allocator

Process Virtual Layout 4GB virtual space on a 32 bit system –Possible to install Linux on systems with more than 4GB of physical memory but you must use tricks to access "high" memory Kernel macro PAGE_OFFSET –Division between user and kernel regions –Typically 3GB user, 1 GB kernel (adjustable) We will look at details of user space later

Kernel Virtual Layout Kernel page tables initialized in two stages during startup –Phase one: only maps 4MB (provisional) –Phase two: maps all memory Provisional –Static PGD, just one PT –swapper_pg_dir –Low 4M of user & kernel map low 4M physical –Allows kernel to be addressed virtually or physically

Final Kernel Virtual Layout Kernel code –Operates using linear (virtual) addresses –Macros to go from physical to virtual and back _pa(virual), _va(physical) Kernel mapped using jumbo pages Kernel virtual address space –Low physical frames (containing kernel) mapped to virtual addresses starting at PAGE_OFFSET –Remaining frames allocated on demand by kernel and user processes and mapped to virtual addresses

Summary Intel hybrid segmented/paged architecture Segment support used minimally Linux has a conceptual 3 level page table Kernel is mapped into high memory of every process address space but is stored in low physical memory