Advanced I/O - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Advanced I/O

Description:

streams are normally loaded into the kernel at compile time ... functions re-read' or re-write' until all data is transferred. 9/5/09. 15. Memory Mapped I/O ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 16
Provided by: richarde78
Category:

less

Transcript and Presenter's Notes

Title: Advanced I/O


1
Advanced I/O
  • functions involved in atypical I/O
  • non-blocking functions
  • record locking
  • streams
  • I/O multiplexing
  • select() function
  • poll() function
  • readv(), writev() functions
  • memory mapped I/O

2
Nonblocking I/O
  • term for I/O using system calls that arent
    slow
  • a slow call can theoretically block
    indefinitely
  • reads from files where data may be delayed or
    never arrive
  • write to files that cant accept data immediately
  • conditional open
  • reads and writes to files with mandatory locks
  • other IOCTL and IPC functions
  • calls to open can be designated non-blocking
  • fcntl() functions can alter an open FD to make it
    non-blocking
  • non-blocking calls return immediately if ops
    cannot be performed, with a would have blocked
    error

3
Record Locking
  • used by one process to prevent other processes
    from changing a portion of file in use by the
    first process
  • some UNICES only support locking entire file
  • locking can be advisory or mandatory
  • advisory locking depends on cooperative functions
  • mandatory locking is enforced by the kernel

4
fcntl() record locking
  • uses flock structure to describe lock
    requirements
  • locks can start and extend beyond the current
    EOF, but not beyond the current SOF
  • locks can be shared read or exclusive write
  • multiple read locks are allowed
  • only one write lock is allowed
  • a read locked file segment cannot be write
    locked, and vice versa
  • if two processes are each waiting on the others
    lock, you have deadlock, which is typically
    overridden by the system

5
Inheritance and Release of Locks
  • locks are associated with a process and a file
  • if a process exits, all locks are released
  • if a file is closed, all locks are released
  • multiple descriptors for a file to NOT prevent
    lock release, locks are associated with the file
    and not the descriptor
  • locks are not inherited by children
  • locks are typically inherited across an exec, but
    are not required to be so by POSIX

6
Advisory vs. Mandatory Locking
  • advisory locking is essentially voluntary
  • requires cooperating functions
  • mandatory locking is essentially involuntary
  • enforced by the kernel
  • limited to open(), read() and write() functions
  • mandatory locking can result in unexpected
    consequences
  • file may still be modifiable under certain
    circumstances
  • can be used by to maliciously control files

7
Streams
  • SYSV methodology for interfacing comm drivers
    with the kernel
  • streams are full duplex paths between processes
    and device drivers
  • streams are normally loaded into the kernel at
    compile time
  • data flows upstream to the process,
    downstream to the driver
  • streams uses a messaging paradigm for passing
    information to and from processes and devices

8
I/O Multiplexing
  • multiplexing is a methodology for handling
    unpredictable I/O on multiple file descriptors
  • using nonblocking I/O results in polling
  • using blocking I/O may cause available I/O on
    another descriptor to be ignored
  • multiplexing uses a function that returns when
    any of a given list of FDs is available for I/O

9
select() Function
  • common function for multiplexing
  • takes
  • highest FD1
  • descriptor lists read, write, exception
  • timeout
  • returns
  • -1 error OR
  • 0 no FDs ready OR
  • number of descriptors ready
  • select() clears all bits on descriptors that are
    not ready

10
working with select()
  • four macros are available to work with FD sets
    used with select
  • FD_ZERO clears all bits
  • FD_SET turns on bit for particular FD
  • FD_CLR turns off bit for particular FD
  • FD_ISSET tests for bit on in particular FD
  • descriptors are ready if
  • in read set and read wont block
  • in write set and write wont block
  • in except set and exception is pending
  • whether or not an FD is blocking is irrelevant to
    the operation of select()

11
poll() Function
  • variant form of select()
  • uses array of nfds structures, in place of FD
    sets
  • more fine grained control of events that
    trigger return

12
Asynchronous I/O
  • asynchronous I/O is a method whereby I/O is
    requested (queued), and the called process
    returns immediately, allowing the calling process
    to continue
  • on some systems AIO involves a kernel generated
    signal when queued I/O requests change status
  • on other systems AIO is handled by the process
    calling a function to determine status

13
readv() and writev() Functions
  • functions for writing to/from multiple buffers
    from a single function call
  • scatter read
  • gather write
  • uses array of iovec structures for buffers
  • improves efficiency over multiple read/writes
  • cleaner then combining smaller buffers into
    single large buffer

14
readn() and writen() Functions
  • repeating read() and write() functions
  • used for reading and writing fixed amounts of
    data to and from end devices which may cause a
    return before all data is transferred
  • terminal devices, network devices, SVR4 streams
    typically
  • functions re-read or re-write until all data
    is transferred

15
Memory Mapped I/O
  • methodology for manipulating files transparently,
    via the manipulation of a memory buffer
  • when data is written to the buffer, the file (or
    a copy) is written, when read from the buffer,
    the file is read
  • mapped regions can be shared across processes
  • mapped regions are unmapped when the process
    terminates
  • closing an FD does not unmap the region
Write a Comment
User Comments (0)
About PowerShow.com