Access to High Memory Introduction to the kernel functions ‘kmap()’ and ‘kunmap()

Slides:



Advertisements
Similar presentations
Paging: Design Issues. Readings r Silbershatz et al: ,
Advertisements

Memory Management Unit
Tutorial 3 - Linux Interrupt Handling -
The Linux Kernel: Memory Management
Memory management.
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
Introduction to Operating Systems CS-2301 B-term Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials.
COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - III Lecturer: Hui Wu Session 2, 2005 Modified.
Presented By Srinivas Sundaravaradan. MACH µ-Kernel system based on message passing Over 5000 cycles to transfer a short message Buffering IPC L3 Similar.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the 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.
Memory Management (II)
Operating System Support Focus on Architecture
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
G Robert Grimm New York University Disco.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Memory Management 2010.
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)
Chapter 8 Operating System Support
Managing physical memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
Linux Memory Management How does the Linux kernel keep track of the Virtual Memory Areas that each process uses?
Vir. Mem II CSE 471 Aut 011 Synonyms v.p. x, process A v.p. y, process B v.p # index Map to same physical page Map to synonyms in the cache To avoid synonyms,
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Input / Output CS 537 – Introduction to Operating Systems.
Memory Management in Windows and Linux &. Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory.
Chapter 3 Operating Systems Introduction to CS 1 st Semester, 2015 Sanghyun Park.
ITEC 325 Lecture 29 Memory(6). Review P2 assigned Exam 2 next Friday Demand paging –Page faults –TLB intro.
The Computer Systems By : Prabir Nandi Computer Instructor KV Lumding.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
1 CS503: Operating Systems Spring 2014 Dongyan Xu Department of Computer Science Purdue University.
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.
Processes and OS basics. RHS – SOC 2 OS Basics An Operating System (OS) is essentially an abstraction of a computer As a user or programmer, I do not.
Chapter 4 Storage Management (Memory Management).
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
Enforcing Modularity Junehwa Song CS KAIST. Network Computing Lab. How to run multiple modules? Emacs X server Mail Reader File Server.
Computer Systems Week 14: Memory Management Amanda Oddie.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Lab4: Virtual Memory CS 3410 : Computer System Organization & Programming Spring 2015.
Operating Systems: Summary INF1060: Introduction to Operating Systems and Data Communication.
Low Overhead Real-Time Computing General Purpose OS’s can be highly unpredictable Linux response times seen in the 100’s of milliseconds Work around this.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Virtual Caches กรกฎ คชฤทธิ์ Virtual Caches CPU Virtual Cache Main Memory MMU Data Virtual Address Physical Address Virtual Address.
Linux 2.6 Memory Management Joseph Garvin. Why do we care? Without keeping multiple process in memory at once, we loose all the hard work we just did.
Introduction to Operating Systems
Non Contiguous Memory Allocation
Chapter 2 Memory and process management
Chapter 8: Main Memory.
Protection and OS Structure
Outline Paging Swapping and demand paging Virtual memory.
Page Replacement.
Today’s agenda Hardware architecture and runtime system
Translation Lookaside Buffer
Lecture Topics: 11/1 General Operating System Concepts Processes
CSE 451 Autumn 2003 November 13 Section.
Chapter 1: Introduction CSS503 Systems Programming
Synonyms v.p. x, process A v.p # index Map to same physical page
Presentation transcript:

Access to High Memory Introduction to the kernel functions ‘kmap()’ and ‘kunmap()

1GB ram?: too many ‘pages’! Some hardware needs virtual addresses (e.g., network and video display cards) CPU also needs some virtual addresses (e.g., for interprocessor communication) So not enough virtual addresses remain when system has a gigabyte or more of ram

Linux kernel’s ‘solution’ The kernel-space addresses are ‘shared’ The high-memory page-frames are made visible to the CPU (i.e., are ‘mapped’) only while access to them is actually needed Then these page-frames are ‘unmapped’ so that other page-frames can ‘reuse’ the same virtual address But sharing only affects ‘high memory’

kernel mapping function ‘kmap()’ can create new page-mappings It works on a page-by-page basis ‘kunmap()’ can invalidate these mappings Prototypes: #include void * kmap( struct page * page ); void kunmap( struct page * page );

Visualizing kernel-space Memory below 896MB is ‘directly mapped’ ‘phys_to_virt()’ just adds 0xC ‘virt_to_phys()’ subtracts 0xC Master Page Directory provides a template kernel space user space

Recall ‘mem_map[ ]’ array unsigned longnum_physpages; struct page *mem_map; struct page *highmen_start_page; highmem_start_page = &mem_map[ 896 ]; struct page { … ; void * virtual; };

How ‘kmap()’ works void * kmap( struct page * page ) { if ( page < highmem_start_page ) return page->virtual; return kmap_high( page ); }

How does ‘kmap_high()’ work? Kernel first performs a quick check: Is the high page is already ‘mapped’? If so, just return its existing virtual address If not, find an ‘unused’ virtual address Set page-table entry that ‘maps’ the page BUT… … there might not be any ‘unused’ entries!

Details of ‘kmap_high()’ void kmap_high( struct page * page ) { unsigned longvaddr; spin_lock( &kmap_lock ); vaddr = (unsigned long)page->virtual; if ( !vaddr ) vaddr = map_new_virtual( page ); ++pkmap_count[ (vaddr - PKMAP_BASE)>>12 ]; spin_unlock( &kmap_lock ); return(void *)vaddr; }

Task maybe will sleep If a new kernel mapping cannot be set up (because all addresses are already in use) then the ‘map_new_virtual()’ function will ‘block’ the task (i.e., will put it to sleep)

How process gets blocked DECLARE_WAITQUEUE( wait, current ); current->state = TASK_UNINTERRUPTIBLE; add_wait_queue(&pkmap_map_wait,&wait); spin_unlock( &kmap_lock ); schedule(); remove_wait_queue(&pkmap_map_wait,&wait); spin_lock( &kmap_lock ); if ( page->virtual ) return page->virtual;

Purpose of ‘kunmap()’ Programming sequence: void * vaddr = kmap( page ); // get address … /* use this virtual address to access the page */ … kunmap( page ); // release the address Now kernel can awaken ‘blocked’ tasks

Reference counters Kernel maintains an array of counters static int pkmap_count[ LAST_PKMAP ]; One counter for each ‘high memory’ page Counter values are 0, 1, or more than 1 =0: page is not mapped =1: page not mapped now, but used to be =n >1: page was mapped (n-1) times

Flushing the TLB ‘kunmap( page )’ decrerments refcount When refcount == 1, mapping isn’t needed But CPU still has ‘cached’ that mapping So the mapping must be ‘invalidated’ With multiple CPUs, all of them must do it

Special CPU instruction Pentium has a special instruction: invlpgm; invalidates one TLB entry But it only affects CPU that executes it. In SMP systems, aother CPUs may still have ‘stale’ physical-to-virtual address- mapping cached in their TLB Prevents other CPU from uptodate access

Solution: notify other CPUs CPU 0 Backside bus CPU 1 I/O APIC System RAM Peripheral devices

What about interrupts? Interrupt-handlers can’t risk using ‘kmap()’ Yet may need access to high memory data Data might not be ‘mapped’ when needed! So an ‘emergency’ mechanism is required

Temporary Mappings A small number of ‘windows’ are reserved These are ‘emergency’ page-table entries Just five or six such entries (per CPU) Interrupt-handlers can use these safely A temporary page-mapping is set up fast No checking for other possible users No assurance that mapping will persist

‘kmap_atomic()’ May be safely called by interrupt-handlers No need to do ‘unmapping’ No TLB clashes with other CPUs You can experiment with ‘kmap_atomic()’ But use ‘kmap()/kunmap()’ for project #3