一次讲清Ext3文件系统的限制
Posted smallfishy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一次讲清Ext3文件系统的限制相关的知识,希望对你有一定的参考价值。
虽然现在基本上都用xfs或者btrfs,但是某些情况下,由于某些原因,还是会用到ext3.但是ext3缺有一个坑,就是文件或目录不能太多,究竟是怎么样回事呢,本文就尝试一次讲清。
先说结论:
1、受文件系统inode限制,如果小文件过多,可能由于inode耗尽无法新建
2、某一目录下文件和子目录总计不得超过31998 ---------------- 没有找到证据
下面开始测试:
1、受inode限制的情况
[root@CentOS-Oracle ~]# df -T ######先查看当前系统环境
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 3977996 0 3977996 0% /dev
tmpfs tmpfs 3995064 0 3995064 0% /dev/shm
tmpfs tmpfs 3995064 12540 3982524 1% /run
tmpfs tmpfs 3995064 0 3995064 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 52403200 4699224 47703976 9% /
/dev/sda1 xfs 1038336 187792 850544 19% /boot
/dev/mapper/centos-oracle xfs 20961280 7439368 13521912 36% /oracle
/dev/mapper/centos-home xfs 20961280 33136 20928144 1% /home
/dev/mapper/centos-u01 xfs 20961280 3450108 17511172 17% /u01
tmpfs tmpfs 799016 8 799008 1% /run/user/42
tmpfs tmpfs 799016 0 799016 0% /run/user/0
[root@CentOS-Oracle ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 5 0 wz--n- <499.00g 385.12g
[root@CentOS-Oracle ~]# lvcreate -n lv_test -L 20 centos ######创建测试lv
Logical volume "lv_test" created.
[root@CentOS-Oracle ~]# mkfs.ext3 /dev/centos/lv_test #####格式化成ext3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
5136 inodes, 20480 blocks
1024 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=20971520
3 block groups
8192 blocks per group, 8192 fragments per group
1712 inodes per group
Superblock backups stored on blocks:
8193
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CentOS-Oracle ~]# mkdir /test
[root@CentOS-Oracle ~]# mount /dev/centos/lv_test /test ###挂载
[root@CentOS-Oracle ~]# cd /test
[root@CentOS-Oracle test]# df -T | grep test ##再次查看/test
/dev/mapper/centos-lv_test ext3 18803 177 17602 1% /test
[root@CentOS-Oracle test]# df -i | grep test
/dev/mapper/centos-lv_test 5136 11 5125 1% /test ####文件系统总共20M,inode也不多
[root@CentOS-Oracle test]# df -h | grep test
/dev/mapper/centos-lv_test 19M 177K 18M 1% /test
[root@CentOS-Oracle test]# ls -l ######当前该文件系统是孔的
total 12
drwx------ 2 root root 12288 May 19 12:39 lost+found
[root@CentOS-Oracle test]# i=1;while true;do touch $i;i=$(($i + 1));done ##一个简单的循环,开始建文件都是空的
touch: cannot touch ‘5126’: No space left on device ####很快就开始报错,No space left on device
touch: cannot touch ‘5127’: No space left on device
touch: cannot touch ‘5128’: No space left on device
touch: cannot touch ‘5129’: No space left on device
touch: cannot touch ‘5130’: No space left on device
。。。。。
[root@CentOS-Oracle test]# ls -l | wc -l ######统计显示已创建了5127个文件(如果排除默认的 lost+found ,应该是 5126个)
5127
[root@CentOS-Oracle test]# > a ###手动创建一个a,也不行
-bash: a: No space left on device
[root@CentOS-Oracle test]# df -h | grep test #######df -h 显示,空间只使用了 2%,怎么会报 No space left on device
/dev/mapper/centos-lv_test 19M 265K 18M 2% /test
[root@CentOS-Oracle test]# df -i | grep test ######查看inode使用率。果然,inode耗尽了
/dev/mapper/centos-lv_test 5136 5136 0 100% /test
2、把20M的lv_test删了,换20G试试
[root@CentOS-Oracle ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 13M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 4.5G 46G 9% /
/dev/sda1 1014M 184M 831M 19% /boot
/dev/mapper/centos-oracle 20G 7.1G 13G 36% /oracle
/dev/mapper/centos-home 20G 33M 20G 1% /home
/dev/mapper/centos-u01 20G 3.3G 17G 17% /u01
tmpfs 781M 8.0K 781M 1% /run/user/42
/dev/mapper/centos-lv_test 19M 265K 18M 2% /test ######lv_test只有19M,使用率2%
tmpfs 781M 0 781M 0% /run/user/0
[root@CentOS-Oracle ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- 20.00g
lv_test centos -wi-ao---- 20.00m
oracle centos -wi-ao---- 20.00g
root centos -wi-ao---- 50.00g
swap centos -wi-ao---- <3.88g
u01 centos -wi-ao---- 20.00g
[root@CentOS-Oracle ~]# lvremove -y /dev/centos/lv_test #######删掉lv_test
Logical volume "lv_test" successfully removed
[root@CentOS-Oracle ~]# lvcreate -n lv_test -L 20G centos #########新建一个lv_test,大小调整为20G
WARNING: ext3 signature detected on /dev/centos/lv_test at offset 1080. Wipe it? [y/n]: y
Wiping ext3 signature on /dev/centos/lv_test.
Logical volume "lv_test" created.
[root@CentOS-Oracle ~]# mkfs.ext3 /dev/centos/lv_test ########还是ext3格式
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CentOS-Oracle ~]# mount /dev/centos/lv_test /test ######仍然挂载到 /test 进行测试
[root@CentOS-Oracle ~]# cd /test
[root@CentOS-Oracle test]# i=1;while true;do touch $i;i=$(($i + 1));done #####开始造文件
很久都没有报错,新开一个窗口。
[root@CentOS-Oracle test]# ls -l | wc -l #####已经建了45581个文件
45581
[root@CentOS-Oracle test]# df -i | grep test
/dev/mapper/centos-lv_test 1310720 54242 1256478 5% /test ##inode使用率5%
[root@CentOS-Oracle test]# ls -l | wc -l
131043
[root@CentOS-Oracle test]# df -i | grep test
/dev/mapper/centos-lv_test 1310720 147457 1163263 12% /test
[root@CentOS-Oracle test]# ls -l | wc -l #####已经建了331165个文件
331165
[root@CentOS-Oracle test]# df -i | grep test
/dev/mapper/centos-lv_test 1310720 338540 972180 26% /test ##inode使用率26%
[root@CentOS-Oracle test]# df -h | grep test
/dev/mapper/centos-lv_test 20G 52M 19G 1% /test ##20G的文件系统使用了1%
[root@CentOS-Oracle test]# df -T | grep test
/dev/mapper/centos-lv_test ext3 20511356 53232 19409548 1% /test ##确认就是 ext3
3、把这些文件全删了,建个目录,看看某一目录下最多能建多少个文件
[root@CentOS-Oracle test]# rm -fr * ###文件有点多
-bash: /usr/bin/rm: Argument list too long
[root@CentOS-Oracle test]# find . -name "*" | awk ‘{print "rm -f "$1}‘ | sh #换个方式删
rm: cannot remove ‘.’: Is a directory
rm: cannot remove ‘./lost+found’: Is a directory
[root@CentOS-Oracle test]# ls -l
total 16
drwx------ 2 root root 16384 May 19 12:44 lost+found
[root@CentOS-Oracle test]# mkdir test
[root@CentOS-Oracle test]# cd test #切换到子目录下
[root@CentOS-Oracle test]# df -i | grep test
/dev/mapper/centos-lv_test 1310720 12 1310708 1% /test
[root@CentOS-Oracle test]# df -T | grep test
/dev/mapper/centos-lv_test ext3 20511356 53244 19409536 1% /test
[root@CentOS-Oracle test]# df -h | grep test
/dev/mapper/centos-lv_test 20G 52M 19G 1% /test
[root@CentOS-Oracle test]# pwd
/test/test
[root@CentOS-Oracle test]# i=1;while true;do touch $i;i=$(($i + 1));done #####开始生产碎文件
^C ##跟预期的不同,一直跑下去了,那就强行中止吧
^C
[root@CentOS-Oracle test]# pwd
/test/test
[root@CentOS-Oracle test]# ls -l | wc -l #####已经生成了350,968多文件。测试不符合预期
350968
[root@CentOS-Oracle test]#
上面是在centos7.7上测试,换个操作系统试试
localhost:/test/test # ls -l | wc -l #######suse15.1测试结果也与预期不符
209364
localhost:/test/test # pwd
/test/test
localhost:/test/test # df -T | grep test
/dev/mapper/system-lv_test ext3 20511356 50468 19412312 1% /test
localhost:/test/test # df -i | grep test
/dev/mapper/system-lv_test 1310720 209375 1101345 16% /test
localhost:/test/test # df -h | grep test
/dev/mapper/system-lv_test 20G 50M 19G 1% /test
localhost:/test/test # cat /etc/issue
Welcome to SUSE Linux Enterprise Server 15 SP1 (x86_64) - Kernel (l).
localhost:~ # cat /etc/issue
Welcome to SUSE Linux Enterprise Server 12 SP5 (x86_64) - Kernel (l). #######suse12.5测试结果也与预期不符
localhost:~ # lvcreate -n lv_test -L 20G test
Logical volume "lv_test" created.
localhost:~ # mkfs.ext3 /dev/test/lv_test
mke2fs 1.43.8 (1-Jan-2018)
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: f83e74b6-27a1-4576-b44b-eaa2ac6a2c8a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
localhost:~ # mkdir /test
localhost:~ # mount /dev/test/lv_test /test/
localhost:~ # cd /test
localhost:/test # mkdir test
localhost:/test # cd
lost+found/ test/
localhost:/test # cd
lost+found/ test/
localhost:/test # cd test/
localhost:/test/test # i=1;while true;do touch $i;i=$(($i + 1));done
^C^C
localhost:/test/test # ls -l | wc -l
47508
localhost:/test/test # >test
localhost:/test/test # >b
localhost:/test/test # mkdir a
localhost:/test/test # mkdir aaaa
localhost:/test/test # ls -l| wc -l
47512
localhost:/test/test # df -i|grep test
/dev/mapper/test-lv_test 1310720 47523 1263197 4% /test
localhost:/test/test # df -h|grep test
/dev/mapper/test-lv_test 20G 46M 19G 1% /test
localhost:/test/test # df -T |grep test
/dev/mapper/test-lv_test ext3 20511356 46160 19416620 1% /test
localhost:/test/test #
最终也没有找到证据,或许是新的系统已经取消了这个限制。后续碰到再完善
以上是关于一次讲清Ext3文件系统的限制的主要内容,如果未能解决你的问题,请参考以下文章