zoukankan      html  css  js  c++  java
  • 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}
  • 相关阅读:
    [剑指offer] 42. 和为S的两个数字
    [剑指offer] 41. 和为S的连续正数序列
    datagridview bindingsource刷新数据
    datagridview bindingsource
    slot-具名插槽
    基于uniapp的ui库
    组件之间通讯
    vue实现word或pdf文档导出的功能
    Vue之富文本tinymce爬坑录
    12道vue高频原理面试题,你能答出几道?
  • 原文地址:https://www.cnblogs.com/itcomputer/p/4660188.html
Copyright © 2011-2022 走看看