AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 540821
Accepted
Emma
Emma
Asked: 2013-09-23 08:06:27 +0800 CST2013-09-23 08:06:27 +0800 CST 2013-09-23 08:06:27 +0800 CST

ext4 文件列表在一个包含大量文件的特定目录中非常慢

  • 772

背景

我有一个小的 logrotate 失误...... Logrotate 会因错误而旋转归档日志,从而导致我的/var/log/. 当我发现有什么不对劲的时候,/var/log/已经包含了几百万个文件......

我设法(在一些脱发和 find/sed/grep 魔术之后)删除了所有有问题的文件并修复了我的 logrotate 配置。并认为一切都很好......

问题

每当我ls/du -hs或以其他方式列出/var/log/(现在包含 80mb 的档案/日志和最多几百个文件)的内容时,执行该操作的过程会挂起一两分钟。我确实相信这在某种程度上与 logrotate 事故有关,但我不确定,可能是其他原因。无论如何,我不知道从哪里开始调试或寻找解决方案。请帮助:3

其他信息

uname -a
Linux xxx 3.3.8-gentoo #18 SMP Sat Sep 21 22:44:40 CEST 2013 x86_64 Intel(R) 
Core(TM)2 CPU 4400 @ 2.00GHz GenuineIntel GNU/Linux

cat /proc/meminfo 
MemTotal:        2051552 kB
MemFree:           75612 kB
Buffers:            9016 kB
Cached:          1740608 kB
SwapCached:            0 kB

CFQ IO scheduler + SLUB allocator 

我以为:一个目录中有多少文件太多了?(从网上下载数据)是相关的,但我没有留下文件了。

编辑

即使在调用之后问题仍然存在,init 1 所以我认为可以安全地假设除了 FS 之外没有其他进程可以归咎于。

解决方案(从接受的答案中应用)

init 1
mv /var/log /var/log1
mkdir /var/log
chmod --reference=/var/log1 /var/log
chown --reference=/var/log1 /var/log
tar -C /var/log1 -cvp . | tar -C /var/log -xvp
rm -rf /var/log1
init 5
performance
  • 2 2 个回答
  • 2537 Views

2 个回答

  • Voted
  1. Best Answer
    Matthew Ife
    2013-09-23T09:40:08+08:002013-09-23T09:40:08+08:00

    目录只会增长,不会缩小。尝试将所有这些文件移出一个临时目录(如 log2),然后 rmdir 旧目录并将临时目录重命名为新的永久目录。

    • 26
  2. moonwalker
    2020-10-10T07:19:06+08:002020-10-10T07:19:06+08:00

    来自man e2fsck:

    -D     Optimize directories in filesystem.  This option causes e2fsck to try to optimize all  directories,
    either  by  reindexing  them if the filesystem supports directory indexing,  or by sorting and com‐
    pressing directories for smaller directories, or for filesystems using traditional linear  directo‐
    ries.
    
    Even without the -D option, e2fsck may sometimes optimize a few directories --- for example, if di‐
    rectory indexing is enabled and a directory is not indexed and would benefit from being indexed, or
    if the index structures are corrupted and need to be rebuilt.  The -D option forces all directories
    in the filesystem to be optimized.  This can sometimes make them  a  little  smaller  and  slightly
    faster to search, but in practice, you should rarely need to use this option.
    
    The  -D  option  will  detect  directory  entries with duplicate names in a single directory, which
    e2fsck normally does not enforce for performance reasons.
    

    换句话说,如果你有一个文件系统卷,你可以脱机,你可以简单地e2fsck -Df <block_device>在它上面运行,它会缩小所有目录。包括文件系统中的根目录,除非重新格式化卷,否则无法删除。在我的例子中,它成功地将卷上的根目录从 56MiB(曾经有超过 1M 的文件)缩小到大约 220KiB(大约 3-4K 的文件)。

    • 1

相关问题

  • 基于 Microsoft 的服务器(IIS、MSSQL 等)上的病毒扫描应排除哪些内容?

  • jvm性能调优技巧/资源?

  • 加快 MSSQL 快照复制到 SQLExpress 副本的速度

  • 聚集索引与非聚集索引?

  • 使用大量 javascript 的页面上的鱿鱼速度很慢

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve