Some energy-saving skills for file systems in Linux

Source: Internet
Author: User
Article Title: some energy-saving techniques for file systems in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

  Introduction:The file system is an important part of the Linux system. The configuration and use of the file system has an important impact on the operation of the entire system. This article introduces some file system configuration skills on Linux to save energy and improve system performance. Although the energy-saving effect of the file system is slight compared to the energy-saving effect of the CPU and display, but the accumulation is much less, the Green Earth will be completed by 1.1 drops.

This document assumes that your main File System resides on the hard disk. A hard disk is a part of the system that has less active time than the CPU, memory, and other devices. If the hard disk is idle, the power consumption is very small. When the disk is started for read/write, the power consumption will greatly increase. Therefore, the core idea of saving energy through the file system is to minimize disk I/O and make the hard disk more idle.

  Processing atime

According to POSIX, Linux, Unix, and other systems must record the last access time of all files in the system, which is called atime. For some applications, atime is very important information. For example, some email programs will determine whether the email has been read through the atime of the mail file; some backup and cleanup programs will not be accessed according to the duration of the file, to determine whether to clean up and archive files.

However, for most applications, atime information is not important, but the overhead of updating atime is huge. Because every time the system accesses a file, a new atime time value is required for this file. The access I mentioned here is not to open a file from the user's perspective, but to each open and read operation at the underlying level of the system. Imagine that every time we perform a read operation on a file, it will cause a write operation on the disk, even if the content we want to read already exists in the Page Cache of the memory, you still need to perform a write operation on the disk. The overhead caused by this is indeed huge. These write operations will make the disk more busy, this is detrimental to system performance (because the disk temporarily blocks other write operations when completing a write operation) and power consumption.

Therefore, if you can determine that your application does not use the atime information of the file, you can disable atime update. For the entire file system, the noatime option of the mount command will not update files in the entire file system. Run the following command:

Mount-o remount, noatime/

You can also write the noatime option in the/etc/fstab file.

If you do not want to disable atime update for the entire file system, but want to disable it for some files or directories, you can run the chattr command as follows:

Chattr-R + A/some/dir

You can disable atime update for a directory and all its files.

In addition to noatime, there are two file system options related to atime. One is nodiratime. This option only disables atime update for directories (note that noatime takes effect for both files and directories and is the superset of nodiratime ). In this way, the ls command will not update the atime value of the directory.

For some applications of some users, atime information may be necessary, such as the e-mail program and backup tool mentioned at the beginning of this section. If you completely disable atime updates, these programs will not work properly. In this case, Linux adds a new mount option relatime (relative atime) in kernel 2.6.20 ). Relatime indicates that when accessing a file, atime is updated only when atime is earlier than the file change time. In kernel 2.6.24, relatime was extended. when accessing a file, atime was updated when it was not updated for more than a certain period of time (for example, one day. This extension is used to adjust the update granularity of atime.

Currently, relatime has not been widely used, because many Linux distributions do not support this option in kernel versions and mount commands. If your system supports relatime, you can use the following command to enable it:

Mount-o remount, relatime/

  Adjust Page Cache and VM System

  Adjust Page Cache

In the Linux kernel, a Page Cache mechanism is provided for reading and writing files ). The Page Cache exists in the memory. When you want to read the content of a disk file, the kernel first searches the Page Cache. If the content to be read already exists in the Page Cache, you do not need to initiate an actual read operation on the disk. When you need to write a file, the write operation only stores the content in the Page Cache, and the changes in the Page Cache are periodically written back to the disk by the kernel process pdflush. By default, the pdflush process wakes up every five seconds to write data back. This write-back time value is defined in the/proc/sys/vm/dirty_writeback_centisecs parameter. If a power failure or system crash occurs within five seconds, data may be lost. If the user's power supply is relatively reliable, or the risk of data loss is not very concerned, You can appropriately increase the data write-back time. Run the following command to view the current write-back time value of the system:

Cat/proc/sys/vm/dirty_writeback_centisecs

500

The unit of this time value is 1/100 seconds. Use the following command to change the value:

Echo 2000>/proc/sys/vm/dirty_writeback_centisecs

In this way, the pdflush process can only wake up once in 20 seconds, thus reducing the frequency of disk access.

There is also a parameter/proc/sys/vm/dirty_expire_centisecs that controls how long after a changed page is considered to be an expired page and must be written back, the default value is 3000 (unit: 1/100 seconds ). You can also add this value to make the page stay in the memory for a longer time. Run the following command:

Echo 4000>/proc/sys/vm/dirty_expire_centisecs

Another case of pdflush processing is that when the amount of available memory is reduced, some buffer pages are written back to the disk to release the memory. This behavior is controlled by the/proc/sys/vm/dirty_background_ratio parameter. The default value of this parameter is 10, which means that when the total size of all changed pages exceeds 10% of the working memory, pdflush starts writing back to work. You can increase this proportion to increase the time for the page to reside in the memory. The method for changing this parameter is the same as the preceding two parameters.

[1] [2] Next page

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