【问题标题】:Python OSError No space left on devicePython OSError 设备上没有剩余空间
【发布时间】:2017-03-29 06:54:21
【问题描述】:

我将很多文件写入一个文件夹,没有子目录,但是在 280 万个文件之后出现此错误:

with open(bottleneck_path, 'w') as save_file:
OSError: [Errno 28] No space left on device: '/home/user/path/redacted'

我检查了文件名的长度,它只有 149 个字符长。文件大小应该在 18K 左右。

我的操作系统是 Linux。

df -i:

Filesystem                               Inodes   IUsed    IFree IUse% Mounted on
udev                                    4106923     544  4106379    1% /dev
tmpfs                                   4113022     836  4112186    1% /run
/dev/sda2                              28401664 9008557 19393107   32% /
tmpfs                                   4113022      40  4112982    1% /dev/shm
tmpfs                                   4113022       5  4113017    1% /run/lock
tmpfs                                   4113022      16  4113006    1% /sys/fs/cgroup
/dev/sda1                                     0       0        0     - /boot/efi

df -T

Filesystem                             Type      1K-blocks       Used  Available Use% Mounted on
udev                                   devtmpfs   16427692          0   16427692   0% /dev
tmpfs                                  tmpfs       3290420      22136    3268284   1% /run
/dev/sda2                              ext4      447088512  355325584   69029056  84% /
tmpfs                                  tmpfs      16452088      82448   16369640   1% /dev/shm
tmpfs                                  tmpfs          5120          4       5116   1% /run/lock
tmpfs                                  tmpfs      16452088          0   16452088   0% /sys/fs/cgroup
/dev/sda1                              vfat         523248       3684     519564   1% /boot/efi

du -sh .

56G

ls | wc -l

2892084

据我了解,ext4 应该可以很好地处理这个问题。

编辑:

tune2fs -l /dev/sda2

tune2fs 1.42.13 (17-May-2015)
Filesystem volume name:   <none>
Last mounted on:          /
Filesystem UUID:          cd620466-1f88-400b-acf5-457a9c9544cf
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              28401664
Block count:              113587456
Reserved block count:     5679372
Free blocks:              82864623
Free inodes:              25755495
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      996
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Wed Mar  1 15:14:22 2017
Last mount time:          Mon Mar 27 13:20:00 2017
Last write time:          Mon Mar 27 13:20:00 2017
Mount count:              35
Maximum mount count:      -1
Last checked:             Wed Mar  1 15:14:22 2017
Check interval:           0 (<none>)
Lifetime writes:          1813 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
First orphan inode:       1312056
Default directory hash:   half_md4
Directory Hash Seed:      e186507d-32b5-49c0-8ce1-09bf2a75d816
Journal backup:           inode blocks

使用

touch /home/user/path/redacted/somefile_1

引发错误,但具有不同名称的相同文件名结构可以正常工作。例如:

touch /home/user/path/redacted/somefile_2

【问题讨论】:

  • 您是将所有 280 万个文件作为所述目录的子级写入,还是嵌套?根据this question 看来,ext4 每个目录的子目录限制为 64k
  • @HoriaComan 没有嵌套,看看那个 ls。
  • ext4 应该能够很好地处理这个问题。没有子目录。
  • @MatteoItalia 已发布。 df -T 上方
  • 当然,它可能能够处理它,但它仍然是一个相当糟糕的主意,可以轻松避免。

标签: python linux ext4


【解决方案1】:

ext4 的最大 inode 没有默认限制,这取决于设备的大小和创建时选择的选项。使用检查现有限制

tune2fs -l /path/to/device

【讨论】:

    【解决方案2】:

    这是由于哈希冲突。禁用 dir_index 解决了这个问题。

    【讨论】:

    • 如果没有dir_index,性能不会有问题吗?文件查找的速度仍然可以接受吗?
    猜你喜欢
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 2012-01-14
    • 2012-05-15
    • 2018-11-22
    • 2015-07-21
    • 2020-12-16
    相关资源
    最近更新 更多