linux挂载mount参数优化

在一次挂载 硬盘时,前辈跟我讲的一些维护mount参数,委实之前没听说过, 然后就查了一些资料,然后才发现这些参数可以提供硬盘的使用效率, 具体的思路就是在内核级别做调整,就是调整filesystem访问记录等,减少文件系统的 访问记录,减少硬盘操作记录,减少IO框架,提高硬盘效率。 标记,以防以后自己找不到。


一、

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 吗

给文件系统挂载的时候加上 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}
安心做技术
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值