最新消息:

xfs文件系统优化方案

xfs admin 4492浏览 0评论

先贴出优化前后的对比,只是简单的用dd命令测试了一下而已,不怎么专业。写和读的文件为内存2倍。

优化前:
#写性能
[root@sapling ~]# dd if=/dev/zero of=/data/test bs=8M count=1000
1000+0 records in
1000+0 records out
8388608000 bytes (8.4 GB) copied, 172.835 seconds, 48.5 MB/s
#读性能
[root@sapling ~]# dd if=/data/test of=/dev/null bs=8M count=1000
1000+0 records in
1000+0 records out
8388608000 bytes (8.4 GB) copied, 89.7978 seconds, 93.4 MB/s
优化后:
#写性能
[root@sapling ~]# dd if=/dev/zero of=/DaTa/test bs=8M count=1000
1000+0 records in
1000+0 records out
8388608000 bytes (8.4 GB) copied, 70.1252 seconds, 120 MB/s
#读性能
[root@sapling ~]# dd if=/DaTa/test of=/dev/null bs=8M count=1000
1000+0 records in
1000+0 records out
8388608000 bytes (8.4 GB) copied, 47.0801 seconds, 178 MB/s

先是格式化xfs分区mkfs.xfs的参数(你也可以只设置-i size=512,其他会根据分区大小自动选择):

mkfs.xfs -f -i size=512 -l size=128m,lazy-count=1 -d agcount=16 /dev/sdb1
  • -i size=512 : 默认的值是256KB,这里的设置是为了selinux的,这个设置针对inode size,selinux使用xfs的Extend Attribute,首先要写到inode中,如果容量不够(默认是256KB的时候就不够,刚刚多一点点),就写到block中,这会损失性能,当需要使用selinux的时候。这似乎对一般用户没什么作用,因为一般用户都不用selinux的,大家对linux系统的安全性还是挺信任的,不过,说实话,我不信任,况且RedHat 的FC已经默认配置了selinux,这很好。做了这个改动,方便以后我在系统中配置selinux而不担心性能的损失。
  • -l size=128m :注意是小写的m,不是大写的。默认值的是10m(bsize=4096 x blocks=2560)。这个值可以设置成32m(分区容量不小于250M)/64m(分区容量不小于500M)/128m(分区容量不小于700M),对于分区容量的限制,我这里列出的只是大概,最大可设128m。修改这个参数成128m,可以显著的提高xfs文件系统删除文件的速度,当然还有其它,如拷贝文件的速度。 这个参数需要大内存的支持,内存太少的机器大概不能设置这么高。(标准是什么?512M?1G?我不了解,所以我上面说要自己实际的测试一下。)
  • -l lazy-count=value
    This changes the method of logging various persistent counters  in  the  superblock.   Under metadata  intensive  workloads, these counters are updated and logged frequently enough that the superblock updates become a serialisation point in the  filesystem.  The  value  can  be either 0 or 1.
    With  lazy-count=1,  the superblock is not modified or logged on every change of the persis-tent counters. Instead, enough information is kept in other parts of the  filesystem  to  be able  to  maintain  the  persistent  counter  values  without  needed  to  keep  them in the superblock.  This gives significant improvements in performance on some configurations.  The default  value  is  0 (off) so you must specify lazy-count=1 if you want to make use of this feature.
  • -d agcount=4 :默认值是根据容量自动设置的。可以设置成1/2/4/16等等,这个参数可以调节对CPU的占用率,值越小,占用率越低。这是理论上的,在我的机器上,agcount=1反而比agcount=2的cpu占用率还高,我想这是因为我的cpu是双核的原因吧。要注意,cpu的占用率低,那每一秒处理的数据量也会降低一些。我比较了agcount=2和4,发现还是4比较好。这样一来,这个参数的设置,就是需要自己去选择的了。

然后是mount的xfs选项(关键参数nobarrier): 

vi /etc/fstab
#修改挂载选项
/dev/sdb1               /data                    xfs     defaults,noatime,nobarrier       0 0
#重新挂载
mount -o remount /data
  • nobarrier
    • Many hardware RAID have a persistent write cache which preserves it across power failure, interface resets, system crashes, etc. Using write barriers in this instance is not recommended and will in fact lower performance. Therefore, it is recommended to turn off the barrier support and mount the filesystem with “nobarrier”. But take care about the hard disk write cache, which should be off.
  • noatime 默认的方式下linux会把文件访问的时间atime做记录,这在绝大部分的场合都是没有必要的,如果遇到机器IO负载高或是CPU WAIT高的情况,可以尝试使用noatime,疗效好,见效快。
    • logbufs=value
      Set  the number of in-memory log buffers.  Valid numbers range from 2-8 inclusive.  The default value is 8 buffers for filesystems with a blocksize of 64K, 4 buffers for filesystems with a blocksize of 32K,  3 buffers for filesystems with a blocksize of 16K, and 2 buffers for all other configurations.  Increasing the number of buffers may increase performance on some workloads at the cost of the memory used for  the additional log buffers and their associated control structures.
    • logbsize=value
      Set  the  size  of each in-memory log buffer.  Valid sizes are 16384 (16K) and 32768 (32K).  The default value for machines with more than 32MB of memory is 32768,  machines  with  less  memory  use  16384  by default.

转载请注明:爱开源 » xfs文件系统优化方案

您必须 登录 才能发表评论!