Block I/O In Linux - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Block I/O In Linux

Description:

Block devices are devices in which data is organized as an array of fixed size ... Data is read/written in terms of blocks. Block is the basic unit of I/O operations. ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 19
Provided by: tsaimi
Category:
Tags: block | linux | tmc

less

Transcript and Presenter's Notes

Title: Block I/O In Linux


1
Block I/O In Linux
  • Q36921115
  • ???

2
Block Device
  • Block devices are devices in which data is
    organized as an array of fixed size chunks called
    'blocks'
  • Data is read/written in terms of blocks
  • Block is the basic unit of I/O operations.

3
Devices Are Accessed In Three Ways
  • The kernel needs to read the block.
  • -example A file system needs to read the
    super block from the disk
  • Read/Write to the device file
  • - read/write system call on the device file
  • The device file is mapped into memory
  • - page fault or page flush on the mapped
    memory

4
File Operation on Block Devices
5
File Operation on Block Devices
  • Because most of the behavior of file operations
    are the same ,linux provides default
    file_operations functions for common block
    devices.
  • Different from character device drivers which
    implement file_operations, block device drivers
    implement block_device_operations

6
Generic Block Device Layer
  • Provides common functionality for all block
    devices in Linux
  • Uniform interface (to file system)
  • e.g. bread( ) block_prepare_write( )
  • block_read_full_page( ) ll_rw_block( )
  • buffer management and disk caching
  • Block I/O requests scheduling
  • Generates and queues actual I/O requests in a
    request queue (per device)
  • Individual device driver services this queue
    (likely interrupt driven)

7
Read Operation In Block Device
8
Read Operation In Block Device
  • submit_bh( )
  • -make I/O request invoke generic_make_request
    ( )
  • block_read_full_page( )
  • - check whether the buffers in the page are up
    to date or not and invoke submit_bh( )
  • bread( )
  • - reads a specified block and returns the
    buffer head.

9
Read Operation In Block Device
  • ll_rw_block( )
  • - read check whether the requested block in
    the
  • buffer is up to date or not.
  • - write check whether the requested block
  • in the buffer is dirty or not.
  • - invoke submit_bh( )

10
Write Operation In Block Deviceprepare_write
11
Write Operation In Block Devicecommit_write
12
Write Operation In Block Device
  • prepare_write
  • - in fact, it reads block data from disk.
  • - check whether the buffer in the memory is
    mapped to block in the disk. If not, allocate a
    new disk block for the file.
  • - if write operation doesnt write the whole
    buffer, it invoke ll_rw_block to read content
    from disk.
  • commit_write
  • - set buffer head uptodate and dirty.
  • - check whether the write operation enlarge the
    file size, update i_size in inode object
  • - invoke balance_dirty( ) to keep dirty buffers
    in the system bound.

13
I/O Request
  • __make_request()
  • - create bounce buffer ,if the buffer is in
    high memory
  • - inserts the buffer in the request queue
  • - plug and unplug
  • - enlarger an existing request
  • elevator algorithm

14
I/O Request
15
I/O Request
__make_request() inserts the buffer in the
request queue
16
I/O Request
  • Request queue
  • Data structure in include/linux/blkdev.h
  • Queue header type request_queue_t typedef
    structure request_queue request_queue_t
  • queue_head double linked list of pending
    requests
  • request_fn pointer to request service routine
  • Queue element struct request
  • cmd read or write
  • Number of request sectors, segments
  • bh, bhtail a list of buffer header
  • Memory area (for I/O transfer)

17
I/O Request
I/O request processing Plug and Unplug
18
Block Device Drvier
  • Implement device operation functions
  • - open, release, ioctl, check_media_change,
  • revalidate
  • Implement a request service routine
  • - request_fn_proc
  • Write interrupt handler and related tasklets
Write a Comment
User Comments (0)
About PowerShow.com