Linux uses the blockdev command to adjust the file read-ahead size

  
                

We can select pre-reading some files during use, which can speed up our work efficiency. However, sometimes encountering some large files will lead to incomplete reading, so how to solve this problem? Today Xiaobian and everyone share the method of setting the file read-ahead size using the blockdev command.

Solution:

command line calling the device's ioctl function. In Linux systems, it seems that the direct operation of the device is only the ioctl function. The parameters he accepts are not too many, and they all correspond one-to-one.

blockdev - Calling block device control programs from the command line

blockdev [options] commands devices

The blockdev tool allows you to call block device control programs from the command line.

–setro Set the device to read-only

–getro Read whether the device is read-only (success is 1,0 is readable and writable)

– Setrw setting is set to read and write

– getss the sector size of the printing device, usually 512

–getsize prints the capacity of the device, according to a sector of 512 bytes Compute

–setra N Set the read-ahead sector (512 bytes) to N. Set readahead to N 512-byte sectors.

–getra Print readahead (read-ahead sector) )

–flushbufs refresh buffer

–rereadpt Reread partition table.

I think & ndash; setro, setrw is more useful, this mount -o ro (rw) is different, mount is mounted on a partition at the file system level is read-only or readable and writable. The blockdev is set to read-only and readable and writable at the level of the setting.

See the output of the following command at a glance.

The code is as follows:

[root@lancy ~]# blockdev –setro /dev/hda4

[root@lancy ~]# blockdev –getro /dev/Hda4

1

[root@lancy ~]# mount /dev/hda4 /misc -o rw

mount: block device /dev/hda4 is write-protected, Mount read-only

[root@lancy ~]# umount /dev/hda4

[root@lancy ~]# blockdev –setrw /dev/hda4

[ Root@lancy ~]# blockdev –getro /dev/hda4

0

[root@lancy ~]# mount /dev/hda4 /misc -o rw

[root@lancy ~]# touch /misc/one

[root@lancy ~]# umount /dev/hda4

[root@lancy ~]# mount /dev/hda4 /misc -o ro

[root@lancy ~]# rm -f /misc/one

rm: Unable to delete ‘/misc/one’: read-only filesystem

The above is the method of setting the size of the Linux system read-ahead file using the blockdev command. It is necessary or interesting. Users can try the look on their computer.

Copyright © Windows knowledge All Rights Reserved