Linux ‘Demand-Paging’

Slides:



Advertisements
Similar presentations
Memory Management in Linux Anand Sivasubramaniam.
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.
Memory Management Unit
CSCC69: Operating Systems
Kernel Memory Allocator
Memory management.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
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.
The Linux PCI Interface An introduction to the PCI configuration space registers.
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.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Linux Memory Management High-Level versus Low-Level.
Memory Management (II)
“Virtual” Memory How does the OS kernel provide “private” and “shared” memory areas to multiple concurrent processes?
The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
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)
Kernel timing issues An introduction to the use of kernel timers and work queues.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
Access to High Memory Introduction to the kernel functions ‘kmap()’ and ‘kunmap()
The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver.
Introduction to the Intel x86’s support for “virtual” memory
Linux Memory Management How does the Linux kernel keep track of the Virtual Memory Areas that each process uses?
Notes for Lab 10 On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
Memory Mapping Sarah Diesburg COP5641.
Memory Mapped Files Using the Linux mechanism for direct access to device data.
ITEC 325 Lecture 29 Memory(6). Review P2 assigned Exam 2 next Friday Demand paging –Page faults –TLB intro.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Penn State CSE “Optimizing Network Virtualization in Xen” Aravind Menon, Alan L. Cox, Willy Zwaenepoel Presented by : Arjun R. Nath.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
Nachos Project 3.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
CS 3204 Operating Systems Godmar Back Lecture 17.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
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.
What is a Process ? A program in execution.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Why Kernel Works? kernel function gets dynamic memory in a fairly straightforward manner _get_free_pages( ) or alloc_pages( ) The simple approaches work.
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.
Virtual Memory – Paging Techniques
Chapter 2: The Linux System Part 4
Linux Details: Device Drivers
Virtual Memory: Systems
Mechanism: Limited Direct Execution
CSE 120 Principles of Operating
CSE 153 Design of Operating Systems Winter 2018
Threads and Locks.
CSE 153 Design of Operating Systems Winter 2018
O.S Lecture 13 Virtual Memory.
Virtual Memory: Systems
SWE3015 Operating System Project Assignment 2 박은수, 박경원, 김지원
Introduction to the Intel x86’s support for “virtual” memory
Virtual Memory.
Linux Details: Device Drivers
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Virtual Memory: Systems CSCI 380: Operating Systems
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Kernel Memory Chris Gill, David Ferry, Brian Kocoloski
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory and Paging
Dirty COW Race Condition Attack
Presentation transcript:

Linux ‘Demand-Paging’ Using ‘nopage()’ with ‘mmap()’

Recall ‘mysis.c’ device-driver Demonstrated the ‘mmap()’ driver-method Used ‘remap_page_range()’ function Mapped video frame-buffer to user space Set up all page-table entries in advance Driver was tested using ‘mmwhere.cpp’ NOTE: A flaw was spotted by Qing Huang A revised version now posted on website

Deferring page-table setups An alternative ‘mmap()’ driver-method Don’t set up all page-tables in advance Many entries might never be needed Waste of cpu time to build unused entries Our frame-buffer may span 128 MB Each page-directory entry controls 4 MB So there may be 32 (=128/4) page-tables! Our screen display needs less than 8 MB

Linux ‘nopage()’ mechanism Avoids using ‘remap_page_range()’ Requires a ‘vm_operations_struct’ object This object contains ‘callback’ functions The main one is named ‘nopage()’ We can implement a ‘nopage()’ method It will get called by the ‘page_fault’ handler It can set up a needed page-table entry

Prototype for ‘nopage()’ struct page * my_vma_nopage( struct vm_area_struct *vma, unsigned long address, int write_access );

Less to do for ‘mmap()’ In device-driver’s ‘mmap()’ method: Does not call ‘remap_page_range()’ Installs ‘callback’ functions instead: vma->vm_ops = &my_vm_ops;

Demo: ‘mynopage.c’ A working example is on course website It can be tested using ‘mmwhere.cpp’ Changes are ‘transparent to application But offer improved efficiency inside kernel Less memory consumed by page-tables Less processor time used for table setups

An idea for further efficiency Bypass ‘mmap()’ mechanism altogether Use Pentium’s ‘Page-Size Extensions’ Use page-directory entries for 4MB frames Avoids allocating/initializing page-tables Avoids creating/inserting ‘vm_area_struct’ Mapping done by driver’s ‘open()’ method Unmapping is done by ‘release()’ method

Page-Directory is modified Where is task’s page-directory located? long *pgdir = current->mm->pgd; Which directory-entries do we modify? What page attributes should we assign? Demo maps frame-buffer to 0x10000000 Why? It seems kernel won’t contend this

Loop to setup directory entries long physaddr = fb_base; long virtaddr = 0x10000000; long entry_index = (virtaddr >> 22); long entry_count = (fb_size >> 22); for (i = 0; i < entry_count; i++) { pgdir[ entry_index ] = physaddr | 0x87; physaddr += (1<<22); ++entry_index; }

‘mmtest.cpp’ Simple application to test ‘mymmfb.c’ It opens the device file ‘/dev/vram’ It uses ‘lseek()’ to get frame-buffer’s size Then it directly writes to the frame-buffer It uses the agreed-upon virtual-address: long *vram = (long)0x10000000;

Is this a ‘safe’ approach? Can we create a confliting application? We could read the Linux source-code  Or we could perform some experiments! Try using ‘malloc()’ to allocate regions See if any regions overlay our frame-buffer But how would we know if they did?