Block devices and character devices in linux

Source: Internet
Author: User
Linux Block devices and character devices-general Linux technology-Linux programming and kernel information. The following is a detailed description. Devices in the system that can access chunks of a fixed size are called Block devices, which are called blocks. The most common block device is the hard disk, in addition to many other Block devices, such as floppy drives, CD-ROM drives, and Flash. Note that they are all used to install the file system-this is also a general access method for Block devices.

Another basic device type is character devices. Character devices are accessed sequentially in the form of character streams, such as serial ports and keyboards. If a hardware device is accessed in the form of a forward stream, it should be attributed to a character device. In turn, if a device is accessed randomly (unordered, it belongs to a block device.

The fundamental difference between the two types of devices is whether they can be randomly accessed-in other words, whether they can jump from one location to another freely when accessing the device. For example, a keyboard device provides a data stream. When you press the string "fox, the keyboard driver returns the data stream consisting of three characters in exactly the same order as the input. It makes no sense to disturb the keyboard driver to read strings or read other characters. Therefore, the keyboard is a typical character device, which provides the character stream input from the keyboard. When you perform a read operation on the keyboard, you will get a compaction stream, namely "f", "o", and "x". The final result is the end of the file (EOF ). When no one knocks on the keyboard, the seek stream is empty. Hard Disk devices are not the same. The drive of the hard disk device may need to read the content of any block on the disk, and then switch to read the content of another block. The read block location on the disk may not be consecutive, therefore, a hard disk can be accessed randomly, rather than in a stream. It is obviously a block device.

The kernel management block device is much more detailed than the character management device, and the problems to consider and the work to be done are much more complicated than the character device. This is because the character device only needs to control one location-the current location-and the access location of the block device must be able to move before and after different intervals of the media. Therefore, in fact, the kernel does not have to provide a dedicated subsystem to manage character devices, but the management of Block devices must have a dedicated subsystem to provide services. Not only is the complexity of Block devices far higher than that of character devices, but more importantly, Block devices require high execution performance. The performance of the entire system is improved when multiple hard disks are used, the effect is much higher than the keyboard throughput speed. In addition, we will see that the complexity of Block devices will leave a lot of room for this optimization.

To put it simply, Block devices can be randomly accessed, and character devices cannot be randomly accessed. What should we do with bare devices?

Do bare devices, such as disk bare devices, cannot be randomly read? Then, create a 2 GB Data File with bare devices in the database. In order to access the last data block, Does ORACLE need to read all the previous data blocks? Obviously, this is not in line with the facts, in this case, the operating system cannot read data randomly, which does not mean that the database cannot read data randomly.

Block devices read data through the system cache instead of directly reading data from physical disks. Character devices can be read directly from physical disks. Does not pass the system cache. (For example, the keyboard is directly interrupted)
Related Article

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: 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.