linux掛載mount參數優化


一、

1) 藍色:表示經過優化的xfs

mount時的參數
defaults,noatime,nodiratime,nobarrier,discard,allocsize=256m,logbufs=8,attr2,logbsize=256k

2) 灰色:表示默認的xfs

mount時的參數
defaults,noatime,nodiratime,nobarrier

3) 黃色:表示ext4。

mount時的參數:
defaults,noatime,nodiratime,nobarrier

二、

noatime
Do not update inode access times on this filesystem (e.g., for faster access on the news spool to speed up news
servers).

nodiratime
Do not update directory inode access times on this filesystem.

nobarrier
Enable/disable the use of block-layer write barriers. Write barriers ensure that certain IOs make it through the
device cache and are on persistent storage. If disabled on a device with a volatile (non-battery-backed) write-back
cache, the nobarrier option will lead to filesystem corruption on a system crash or power loss.

三、

 /proc/mounts              //查看詳細的掛載參數(文件系統),包括未顯示的重要的掛載項.如:/dev/pts 

c121 admin # cat /proc/mounts
/dev/md2 / ext4 rw,noatime,data=ordered 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /run tmpfs rw,nodev,relatime,size=1623100k,mode=755 0 0
dev /dev devtmpfs rw,nosuid,relatime,size=10240k,nr_inodes=2028409,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620 0 0
shm /dev/shm tmpfs rw,nosuid,nodev,noexec,relatime 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
cgroup_root /sys/fs/cgroup tmpfs rw,nosuid,nodev,noexec,relatime,size=10240k,mode=755 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
openrc /sys/fs/cgroup/openrc cgroup rw,nosuid,nodev,noexec,relatime,release_agent=/lib64/rc/sh/cgroup-release-agent.sh,name=openrc 0 0
/dev/md1 /boot ext3 rw,noatime,data=ordered 0 0
/dev/md3 /app ext4 rw,noatime,data=ordered 0 0

四、需要同時設置 noatime 和 nodiratime 嗎

相信對性能、優化這些關鍵字有興趣的朋友都知道在 Linux 下面掛載文件系統的時候設置 noatime 可以顯著提高文件系統的性能。默認情況下,Linux ext2/ext3 文件系統在文件被訪問、創建、修改等的時候記錄下了文件的一些時間戳,比如:文件創建時間、最近一次修改時間和最近一次訪問時間。因為系統運行的時候要訪問大量文件,如果能減少一些動作(比如減少時間戳的記錄次數等)將會顯著提高磁盤 IO 的效率、提升文件系統的性能。Linux 提供了 noatime 這個參數來禁止記錄最近一次訪問時間戳

給文件系統掛載的時候加上 noatime 參數能大幅提高文件系統性能:

# vi /etc/fstab

/dev/sda1        /             ext3     defaults,noatime,errors=remount-ro 0 0
devpts           /dev/pts      devpts   gid=5,mode=620             0 0
proc             /proc         proc     defaults                   0 0
/dev/sda2        swap          swap     defaults,noatime           0 0

修改設置后只需要重新掛載文件系統、不需要重啟就可以應用新設置:

# mount -o remount /

# mount
/dev/sda1 on / type ext3 (rw,noatime,errors=remount-ro)
proc on /proc type proc (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

網上很多資料都提到要同時設置 noatime 和 nodiratime,不知道這個結論來自哪里,其實不需要像設置 noatime 那樣設置 nodiratime,最可靠的資料應該是源代碼,VPSee 查了一下源代碼,發現在內核源代碼 linux-2.6.33/fs/inode.c 文件里有一個 touch_atime 函數,可以看出如果 inode 的標記位是 NOATIME 的話就直接返回了,根本就走不到 NODIRATIME 那里去,所以只設置 noatime 就可以了,不必再設置 nodiratime.

void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
1405{
1406        struct inode *inode = dentry->d_inode;
1407        struct timespec now;
1408
1409        if (inode->i_flags & S_NOATIME)
1410                return;
1411        if (IS_NOATIME(inode))
1412                return;
1413        if ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode))
1414                return;
1415
1416        if (mnt->mnt_flags & MNT_NOATIME)
1417                return;
1418        if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1419                return;
...
1435}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM