File pre-read readahead of Linux kernel,

Source: Internet
Author: User

File pre-read readahead of Linux kernel,

File pre-read readahead in Linux means that the Linux system kernel caches pre-read pages in a certain area of the specified file, so that page fault will not occur when reading the specified area) and blocking. Because reading from memory is much faster than reading from disk. Pre-reading can effectively reduce the number of disk seek times and the application I/O wait time. It is one of the important optimization methods to improve the disk read I/O performance.

Introduction to readhead on Wikipedia:

Readahead is a system call of the Linux kernel that loads a file's contents into the page cache, providing that way a file prefetching technology. when a file is subsequently accessed, its contents are read from the main memory (RAM) rather than from a hard disk drive (HDD ), resulting in much lower file access latencies due to much higher performance of the main memory. [1] [2]

Except Linux distributions use readahead on a list of commonly used files to speed up booting. in such a setup, if the kernel is booted with the profile boot parameter, it will record all file accesses during bootup and write a new list of files to be read during later boot sequences. this will make additional installed services start faster, because they are not supported ded in the default readahead list. [3]

In Linux distributions that use partition EMD, readahead binary (as part of the boot sequence) is replaced by partition EMD-readahead. [4] [5] However, support for readahead was removed from systemd in its version 219, being described as unmaintained and unable to provide expected performance benefits. [6]

Certain experimental page-level prefetching systems have been developed to further improve performance. [7]

View and set the readhead command blockdev. As follows:

[root@localhost ~]# /sbin/blockdev
 
Usage:
  blockdev -V
  blockdev --report [devices]
  blockdev [-v|-q] commands devices
 
Available commands:
        --getsz                        get size in 512-byte sectors
        --setro                        set read-only
        --setrw                        set read-write
        --getro                        get read-only
        --getss                        get logical block (sector) size
        --getpbsz                      get physical block (sector) size
        --getiomin                     get minimum I/O size
        --getioopt                     get optimal I/O size
        --getalignoff                  get alignment offset
        --getmaxsect                   get max sectors per request
        --getbsz                       get blocksize
        --setbsz BLOCKSIZE             set blocksize on file descriptor opening the block device
        --getsize                      get 32-bit sector count
        --getsize64                    get size in bytes
        --setra READAHEAD              set readahead
        --getra                        get readahead
        --setfra FSREADAHEAD           set filesystem readahead
        --getfra                       get filesystem readahead
        --flushbufs                    flush buffers
        --rereadpt                     reread partition table

View the pre-read sector of a disk

[root@localhost ~]# /sbin/blockdev --getra /dev/sda
 
256
 
[root@localhost ~]# /sbin/blockdev --getra /dev/sdb
 
256
 
[root@localhost ~]# 

 

Set the pre-read sector of the Disk

[root@localhost ~]# /sbin/blockdev --getra /dev/sda
256
[root@localhost ~]# /sbin/blockdev --setra 2048 /dev/sda
[root@localhost ~]# /sbin/blockdev --getra /dev/sda
2048
[root@localhost ~]# /sbin/blockdev --getra /dev/sdb
256
[root@localhost ~]# /sbin/blockdev --setra 2048 /dev/sdb
[root@localhost ~]# /sbin/blockdev --getra /dev/sdb
2048
[root@localhost ~]# 

You must write it to the configuration file/etc/rc. local. Otherwise, the restart will fail.

 
[root@localhost ~]# echo '/sbin/blockdev --setra 2048 /dev/sda' >> /etc/rc.local
[root@localhost ~]# more /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
/sbin/blockdev --setra 2048 /dev/sda
[root@localhost ~]# echo '/sbin/blockdev --setra 2048 /dev/sdb' >> /etc/rc.local
[root@localhost ~]# more /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
/sbin/blockdev --setra 2048 /dev/sda
/sbin/blockdev --setra 2048 /dev/sdb

References:

Https://en.wikipedia.org/wiki/Readahead

Http://www.hustyx.com/cpp/96/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.