mkdir抛出设备上没有剩余空间,而创建一个大文件很好(有足够的空间和inode可用)

时间:2017-07-21 06:55:49

标签: filesystems mkdir

非常奇怪的行为

我无法创建目录

[root@XXXXXX DEV]# mkdir 1
mkdir: cannot create directory `1': No space left on device
[root@dev-albert DEV]# pwd
/deployment/.octopus/Applications/OctopusServer/DEV
[root@XXXXXX DEV]# df -P /deployment
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/mapper/deploymentvg-deployment  10321208   5229888   4567096      54% 
/deployment
[root@dev-albert DEV]# df -Pi /deployment
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/mapper/deploymentvg-deployment  655360   69129  586231   11% 
/deployment

正如您所看到的,充足的空间,大量的inode免费。

有没有人知道我的系统发生了什么。

[root@dev-albert DEV]# dmsetup ls
rootvg-tmp      (252:6)
rootvg-usr      (252:7)
rootvg-var      (252:8)
deploymentvg-usropenv   (252:3)
deploymentvg-deployment (252:2)
rootvg-agent    (252:4)
rootvg-oracle   (252:11)
rootvg-varlock  (252:9)
rootvg-deployment       (252:5)
rootvg-swap     (252:1)
rootvg-root     (252:0)
rootvg-varspool (252:10)

最高输出

top - 14:44:35 up 347 days, 20:40,  2 users,  load average: 2.02, 2.02, 2.05
Tasks: 125 total,   2 running, 123 sleeping,   0 stopped,   0 zombie
Cpu(s):100.0%us,  0.0%sy,  0.0%ni,117100.0%id,-42916200.0%wa,  0.0%hi,  
0.0%si,200.0%st
Mem:   4071932k total,  3394132k used,   677800k free,   780312k buffers
Swap:  4194300k total,    22604k used,  4171696k free,  1742552k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
747 root      20   0     0    0    0 S  3.0  0.0 303:33.05 jbd2/dm-2-8
20679 root      20   0     0    0    0 S  2.7  0.0   0:14.24 kworker/0:2
16319 root      20   0     0    0    0 R  2.3  0.0 266:30.45 flush-252:2

当我用strace运行mkdir时

open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=99158576, ...}) = 0
mmap(NULL, 99158576, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd4c4b04000
close(3)                                = 0
mkdir("1", 0777)                        = -1 ENOSPC (No space left on 
device)
open("/usr/share/locale/locale.alias", O_RDONLY) = 3


write(2, ": No space left on device", 25: No space left on device) = 25

uname输出

Linux  2.6.39-400.17.1.el6uek.x86_64 #1 SMP Fri Feb 22 18:16:18 PST 2013 x86_64 x86_64 x86_64 GNU/Linux

1 个答案:

答案 0 :(得分:0)

有时这可能是由 ext4 用作目录索引的 b-tree 达到其高度限制引起的。如果您在 mkdir 上收到某些名称的 No space left on device 错误但其他名称没有,或者有足够的空间和 inode,请检查您的 dmesg 是否有以下警告:

EXT4-fs warning (device dm-0): ext4_dx_add_entry:2226: Directory (ino: 80087286) index full, reach max htree level :2 
EXT4-fs warning (device dm-0): ext4_dx_add_entry:2230: Large directory feature is not enabled on this filesystem

这意味着你达到了 b-tree 的限制,在紧要关头你可以启用大目录:

tune2fs -O large_dir <dev>

它不需要卸载或重启,它将限制从10M增加到2B。根据您在做什么,您可能会遇到性能瓶颈或在再次达到限制之前实际填充磁盘,但我建议重新考虑您的目录结构以避免在同一目录中创建太多文件和子目录,并使用上述仅在紧急情况下才能解决。