Why is barrier enabled on your Linux system?

Source: Internet
Author: User

Most popular Linux file systems, including EXT3 and EXT4, use the file system barrier as an enhanced security feature. It protects data from being written into the diary. However, in many cases, we do not know whether these barriers are useful. This article explains why barrier should be enabled on your Linux system.

Linux Log and barrier Functions

To understand barrier, you must first understand the file system log function. Common file systems use the log function to ensure the integrity of the file system. The idea behind this function is simple: before writing a new data block to a disk, the metadata is first written into the log. Writing metadata into logs in advance ensures that the log function can easily roll back to the status before and after the real data is written. This method ensures that the file system will not crash.

Using the log function alone cannot guarantee that there are no errors. Currently, most disks have large-capacity caches, so data is not immediately written to the disk, but first written to the disk cache. In this step, the disk controller can more efficiently copy it to the disk. This is good for performance, but opposite to the log function. To ensure log reliability, it must ensure that metadata is written in advance before real data is written. This is why we want to introduce the file system barrier.

We can easily understand the root cause of barrier usage: barrier itself prohibits writing data after barrier, and the actual data block will be completely written to the disk before the barrier is written. The use of barrier ensures the integrity of the file system, because the barrier function is enabled by default in the EXT4 File System (unless your operating system changes this default setting ).

Check whether the barrier of the Linux File System is enabled or disabled?

You can use the/proc/mounts file to monitor the current status of the file system barrier. For each mounted file system, you can view all the mounting options when you open this file. If you see barrier = 1, your file system is using the barrier function. The following is an example of a file system:

/Dev/sda1/boot ext4 rw, seclabel, relatime, barrier = 1, data = ordered 0 0/dev/mapper/luks-3e67401f-44c6-4a27-a1bf-cdf0dcf45f65/home ext4 rw, seclabel, noatime, barrier = 1, data = ordered 0 0

When does the file system barrier not work?

The problem with Barrier is that it cannot be applied to all conditions. If the device er is used as the storage layer priority, the file system barrier cannot work because the device er does not support barrier. Therefore, even if your file system supports barrier by default, still cannot run this function on logical volumes, soft RAID, or multi-path disks (red hat and all related Linux versions use barrier as the default option ).

One solution to this problem is to avoid using a device er. Therefore, when installing the server, you must fully consider the configuration options. First, you should not use LVM to install the server, but use the traditional partitioning method. Next, you cannot use a multi-path disk that works with the device er. It creates multiple redundant paths on the SAN. In some cases, the SAN vendor provides a proprietary drive as an option, but not all vendors provide this option. The best way is to use smart hardware.

One of the risks of using barrier protection is that when the system is interrupted, data will remain in the cache and will never be written to the file system. A simple battery backup controller can avoid this problem. When the Controller Used by the server fails, the disk controller can still ensure the change operation, which fully eliminates the need for barrier.

Another disadvantage of using barrier is that you need to reduce the performance cost. If you need top-level performance, you can use the mount Option-o barrier = 0 to disable the barrier function, such as mount/dev/sda2-o barrier = 0/data.

The barrier Function of the file system is very useful, but cannot work with the device er. If you want to use such devices but want to ensure file system integrity, you can back up the disk controller with a battery. If your hardware does not support this feature, you can only avoid using device mappers so that you can use the barrier feature to ensure file system integrity. In addition, if you want to achieve better system performance, it is best not to enable the barrier function, which will reduce the system running speed.

Connection: http://www.searchsv.com.cn/showcontent_46628.htm

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.