NCHU System & Network Lab Lab 11 Memory Mapped File.

Slides:



Advertisements
Similar presentations
Using our device-drivers How can an application display the data in a device special file?
Advertisements

Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS1: Overview of Operating Systems 1.1. Windows.
NCHU System & Network Lab Lab 15 Record Locking. NCHU System & Network Lab Record Locking (1/4) What happens when two process attempt to edit the same.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Ways to read data from disk to memory Tan Li. read, write read, write -- low level file access, it's an operation between two file discriptors. SYNOPSIS.
Read vs. mmap Tan Li. Man mmap #include void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); int munmap(void *start, size_t.
The ‘system-call’ ID-numbers How can Linux applications written in assembly language create and access files?
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
NCHU System & Network Lab Lab 12 Page Replacement Algorithm.
The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver.
File Systems CSE 121 Spring 2003 Keith Marzullo. CSE 121 Spring 2003Review of File Systems2 References In order of relevance... 1)Maurice J. Bach, The.
Accessing Files in CCS-2303, C-Term Accessing Files in C CS-2303 System Programming Concepts (Slides include materials from The C Programming Language,
Silberschatz, Galvin and Gagne  Operating System Concepts Common System Components Process Management Main Memory Management File Management.
Operating system Structure and Operation
NCHU System & Network Lab Lab 10 Message Queue and Shared Memory.
NCHU System & Network Lab Lab 13 File I/O & Standard I/O.
Memory-Mapped Files & Unified VM System Vivek Pai.
Introduction by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
ECE 4110 – Internetwork Programming Client-Server Model.
1 5/25/2016 操作系统课件 教材: 《操作系统概念(第六版 影印版)》 【原书名】 Operating System Concepts(Sixth Edition) [ 原书信息 ] Operating System Concepts(Sixth Edition) [ 原书信息 ] 【原出版社】
Introduction to Operating Systems J. H. Wang Sep. 18, 2015.
Operating Systems Recitation 1, March th, 2002.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
CS 149: Operating Systems April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
 2007 Pearson Education, Inc. All rights reserved C File Processing.
UNIX Files File organization and a few primitives.
7.2 Peripheral Supplementary From the view of OS to see interrupt.
Distributed System Concepts and Architectures 2.3 Services Fall 2011 Student: Fan Bai
Chapter 8 : Binary Data Files1 Binary Data Files CHAPTER 8.
1 Shared Memory. 2  Introduction  Creating a Shared Memory Segment  Shared Memory Control  Shared Memory Operations  Using a File as Shared Memory.
Distributed System Concepts and Architectures Services
12.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 12: File System Implementation Chapter 12: File System Implementation.
CSNB334 Advanced Operating Systems 4. Concurrency : Mutual Exclusion and Synchronization.
Processes and Virtual Memory
CSE 466 – Fall Introduction - 1 User / Kernel Space Physical Memory mem mapped I/O kernel code user pages user code GPLR virtual kernel C
NCHU System & Network Lab Lab 14 File and Directory.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS1: Overview of Operating Systems 1.1. Windows.
NCHU System & Network Lab Lab #6 Thread Management Operating System Lab.
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
SCIF. SCIF provides a mechanism for inter-node communication within a single platform, where a node is an Intel® MIC Architecture based PCIe card or an.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
 Backlight 에서 나온 백색광이 액정 셀을 통과하면 서 투과율이 조절되고 red, green, blue 의 color filter 를 투과해 나오는 빛의 혼합을 통해 색이 구 성됨  Color filter 는 셀사이의 빛을 차단하는 black matrix,
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
CSNB334 Advanced Operating Systems 4
Case Study 1: UNIX and LINUX
Andrew Hanushevsky: Memory Mapped I/O
Operating Systems Introduction
Making Virtual Memory Real: The Linux-x86-64 way
Text Illustrations in PPT Chapter 5 CPU Scheduling
CSE 333 – Section 3 POSIX I/O Functions.
Lab 5 Process Control Operating System Lab.
Text and Binary File Processing
CSE 333 – Section 3 POSIX I/O Functions.
Fundamental of Programming (C)
CSE 333 – Section 3 POSIX I/O Functions.
INFS 522 – Computer Systems Concepts
Virtual Memory: Systems CSCI 380: Operating Systems
Lab 10 Paging.
Low-Level I/O – the POSIX Layer CSE 333 Winter 2019
Shared Memory David Ferry, Chris Gill
Dirty COW Race Condition Attack
Lab #9 Semaphores Operating System Lab.
Presentation transcript:

NCHU System & Network Lab Lab 11 Memory Mapped File

NCHU System & Network Lab Introduction Previously, when we need to access a file –fopen(), fread(), fseek(), fwrite() Another promising approach –Memory mapped file Advantages –Easier to share file between two processes fopen( ) will lock the file, another process can’t access it. –More efficient Bypass the file system interface

NCHU System & Network Lab Memory Mapped File Mapped memory forms an association between a file and a process’s memory. The process can read and write the file's contents with ordinary memory access. In Linux, all device drivers appear as normal files.

NCHU System & Network Lab Memory Mapped File process memory file Memory Map Access memory

NCHU System & Network Lab Memory Mapping #include void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); Symbolic ConstantDescription PROT_READData can be read. PROT_WRITEData can be written. PROT_EXECData can be executed. PROT_NONEData cannot be accessed. addr : start address, usually be 0. len : mapped memory length, usually equal to file length. prot: flags: Symbolic ConstantDescription MAP_SHAREDChanges are shared. MAP_PRIVATEChanges are private. MAP_FIXEDInterpret addr exactly. fildes : a file descriptor. off : the offset from the beginning of the file. return : the address at which the mapping was placed. a value of MAP_FAILED and set errno to indicate the error.

NCHU System & Network Lab Memory Mapping file mapped part start addr = 0, offset = 0, length = file size start addr = 0, offset = d, length = l d l

NCHU System & Network Lab unmapping #include int munmap(void *addr, size_t len); addr: start address. len : length of the mapped memory region. return 0 for success, -1 for error

NCHU System & Network Lab Example – mmap()

NCHU System & Network Lab

Example – fopen()

NCHU System & Network Lab

Lab I A program that –user can input messages continuously –Program should record these messages into a file –Use mmap() approach instead of fopen() –Be care : The memory point that is returned by mmap() will always point to the start of mapped memory region. You should change it’s position by yourself.

NCHU System & Network Lab Read file by mmap()

NCHU System & Network Lab

Lab II Write two program use mmap() that –Consist of two concurrent program –Program 1 : user can input messages continuously and write the messages to a file. –Program 2 : read the messages from that file and show it on the screen continuously. –Be care: race condition

NCHU System & Network Lab Reference Advanced Programming in the UNIX Environment 2nd Author : Richard Stevens, Stephen A.Rago, Publisher : Addison-Wesley Beginning Linux Programming Author : Richard Stones, Neil MatthewPublisher : Wrox Operating System Concepts 6th edition Author : Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Publisher : John Wiley & Sons, inc. Google LINUX MAN PAGES ONLINE