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.

Slides:



Advertisements
Similar presentations
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
Advertisements

Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Review: –What functionality is supported by IP? –What IP does not do? –How many classes of IP addresses? –Explain fields in an IP header? –How subnet works?
CS 241 Section Week #5 2/23/12. 2 Topics This Section MP4 overview Function Pointers Pthreads File I/O.
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.
Today’s topic: –File operations –I/O redirection –Inter-process communication through pipes.
The ‘system-call’ ID-numbers How can Linux applications written in assembly language create and access files?
OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002.
CS1061: C Programming Lecture 19: Random Access Files A. O’Riordan, 2004, 2007 updated.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
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.
Lecture 17 FS APIs and vsfs. File and File Name What is a File? Array of bytes. Ranges of bytes can be read/written. File system consists of many files,
NCHU System & Network Lab Lab 13 File I/O & Standard I/O.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Implementing system calls in the Y86 model Soumava Ghosh.
N305: C Programming Copyright ©2006  Department of Computer & Information Science File Handling in C.
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
Operating Systems Recitation 1, March th, 2002.
22. FILE INPUT/OUTPUT. File Pointers and Streams Declarations of functions that perform file I/O appear in. Each function requires a file pointer as a.
File Handling In C By - AJAY SHARMA. We will learn about- FFile/Stream TText vs Binary Files FFILE Structure DDisk I/O function OOperations.
Remote Shell CS230 Project #4 Assigned : Due date :
UNIX Files File organization and a few primitives.
NCHU System & Network Lab Lab 11 Memory Mapped File.
Chapter 8 : Binary Data Files1 Binary Data Files CHAPTER 8.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Today’s topic: UDP Reliable communication over UDP.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
CSE333 SECTION 3. Important Dates Jan 27 th – Homework 1 Due Feb 6 th – Midterm.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
CS 241 Section Week #8 (10/29/09). Outline MP5 Overview Files & I/O UNIX File Systems inodes Directories Links.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
File Systems - Part I CS Introduction to Operating Systems.
Recitation 9: 11/04/02 Outline Error Handling I/O Linux man pages Annie Luo Office Hours: Thursday 6:00 – 7:00 Wean 8402.
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.
CS 241 Section Week #5 9/22/11. 2 Topics This Section File I/O Advanced C.
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.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
Andrew Hanushevsky: Sendfile() First INFN International School on Architectures, tools and methodologies for developing efficient large scale scientific.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Error handling I/O Man pages
Andrew Hanushevsky: Basic I/O API’s
Lecture 31: Introduction to File System
Chapter 4 File Processing
Lecture 11 File input/output
Linux Kernel Driver.
File Handling in C.
File Handling in C.
Making Virtual Memory Real: The Linux-x86-64 way
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
Network Programming CSC- 341
Recitation 9 Greg Reshko
CSE 333 – Section 3 POSIX I/O Functions.
Text and Binary File Processing
File I/O (1) Prof. Ikjun Yeom TA – Mugyo
CSE 333 – Section 3 POSIX I/O Functions.
File Handling in C.
CSE 333 – Section 3 POSIX I/O Functions.
Chapter 12: File I/O.
Low-Level I/O – the POSIX Layer CSE 333 Winter 2019
Block I/O fread and fwrite functions are the most efficient way to read or write large amounts of data. fread() – reads a specified number of bytes from.
Shared Memory David Ferry, Chris Gill
September 5th, 2018 Prof. Ion Stoica
Unix Directories unix etc home pro dev motd snt unix ... slide1 slide2
Presentation transcript:

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 #include size_t read(int fildes, void *buf, size_t nbytes); size_t write(int fildes, const void *buf, size_t nbytes); DESCRIPTION The read system call reads up to nbytes bytes of data from the file associated with the file descriptor fildes and places them in the data area buf. The write system call arranges for the first nbytes bytes from buf to be written to the file associated with the file descriptor fildes.

fread, fwrite fread, fwrite - binary stream input/output, they come from the standarded C library. SYNOPSIS #include size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); DESCRIPTION The fread library function is used to read data from a file stream. Data is read into a data buffer given by ptr from the stream, stream. Both fread and fwrite deal with data records. These are specified by a record size, size, and a count, nitems, of records to transfer.

sendfile sendfile - transfer data between file descriptors SYNOPSIS #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); DESCRIPTION Because this copying is done within the kernel, sendfile() is more efficient than the combination of read and write, which would require transferring data to and from user space. It appears that as for Linux kernel 2.6.X sendfile() syscall can only be used to transfer data from a file descriptor to a socket descriptor. The so called "misfeature" of allowing data transfer between two files has been removed, while I could not find any reported problems about it in 2.4.X kernels where it can work with 2 file descriptors.

read() VS fread read Read with O_DIRECT fread Buffer sizeCPUSpeedtime 1 B99%2MB/s sec 1 KB99%1.42G/s0.7 sec Buffer sizeCPUSpeedtime 1 B99%53.2MB/s18.8 sec 1 KB99%2.85G/s0.35 sec Buffer sizeCPUSpeedtime 4 KB6%29.4MB/s33.99 sec 4 MB18%1.85G/s0.54 sec

Test Method Client: read data from file (1GB), and then send it to the socket. Server: read data from socket, and then write it to the output file. Using 1. Regular read() and write() 2. Read() and write() with O_DIRECT 3. Client: Sendfile() + Server: read() and write()

Test Results read()+write() O_DIRECT Sendfile()+read()+write Buffer sizeCPUSpeedtime 4 KB55%549.45MB/s1.82 sec 400 KB45%787.4 MB/s1.27 sec Buffer sizeCPUSpeedTime 4 KB7%14.97MB/s66.81 sec 400 KB16% MB/s2.98 sec Buffer sizeCPUSpeedTime 4 KB48% MB/s1.8 sec 400 KB31% MB/s1.33 sec

Test Results read()+write() VS sendfile() + read() + write() buffer size: 400KB, file size: 100GB CPUSpeedtime R+W27%305.39MB/s sec S+R+W27%307.97MB/s sec