阅读软件包列表需要很长时间

阅读软件包列表需要很长时间

我一直在尝试更新我机器上的东西,但似乎无法读取我的软件包列表。似乎每次我这样做时,sudo apt-get install *something* && sudo apt-get update它都会卡在读取软件包列表,以前这不是问题。以下是我的规格和其他东西:

  • 内存:15.8 GB
  • 处理器:AMD Phenom(tm) II x4 965 处理器 x 4
  • 显卡:AMD BARTS 上的 Gallium 0.4
  • 操作系统类型:32位
  • 網速:在此处输入图片描述

答案1

我也见过这种情况。

我没有解决方案,但我有一个解决方法(echo 3 | sudo tee /proc/sys/vm/drop_caches)并且可能有更多的信息,以便有人可以进一步调查。

这不是网络问题,因为“正在读取包裹清单...”,它只是读取文件/var/lib/apt/lists/。答:

strace -tt -T -fo strace.log apt-get update

给出:

16394 14:43:03.921130 open("/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_precise_main_binary-i386_Packages", O_RDONLY|O_LARGEFILE) = 7 <0.000012>
[...]
16394 14:43:03.995238 read(6, "-3.1ubuntu2)\nConflicts: linux86\n"..., 32444) = 32444 <0.000111>
16394 14:43:05.787187 read(6, "c (<< 1:14.b.4-dfsg), erlang-exa"..., 32239) = 32239 <0.000069>
16394 14:43:05.788025 read(6, ".deb\nSize: 42130\nMD5sum: c7de671"..., 31695) = 31695 <0.000068>
16394 14:43:05.870734 read(6, "5: 29c4b395a92bdc12932f151c3643a"..., 31607) = 31607 <0.000071>
16394 14:43:05.890862 read(6, "e-pack-af-base\nFilename: pool/ma"..., 32538) = 32538 <0.000070>
16394 14:43:05.891425 read(6, "buntu-usb-live, ubuntu-dvd-live,"..., 32090) = 32090 <0.000066>
16394 14:43:05.891960 read(6, "cd9755b03ac2c9b8251125c7b6618\nDe"..., 32195) = 32195 <0.000034>
16394 14:43:06.043001 read(6, "rg>\nArchitecture: all\nVersion: 2"..., 32535) = 32535 <0.000072>

看看这 8 个read系统调用是如何耗时超过 2 秒的,尽管每个调用所需的时间不到 1 毫秒。运行time apt-get update或查看top,该进程在这两次调用之间并不繁忙。那么为什么会有延迟呢?

然后我做了:

echo t > /proc/sysrq-trigger

几次并查看结果kern.log

 apt-get         D 00000000     0 16790  12706 0x00000000
  e8695d30 00000086 f7bd5e6c 00000000 f7bd5e44 f74a6580 c1990e00 c1990e00
  efe46efe 000042cb f7b9de00 e71a7230 f74a6580 c107e116 00000000 00000000
  044aa200 00000000 00000000 00000000 00000000 e8695d0c e8695d0c c1038de8
 Call Trace:
  [<c107e116>] ? enqueue_entity+0x186/0x220
  [<c1038de8>] ? default_spin_lock_flags+0x8/0x10
  [<c15e13bd>] ? _raw_spin_lock_irqsave+0x2d/0x40
  [<c15e0533>] schedule+0x23/0x60
  [<c15deecf>] schedule_timeout+0x12f/0x290
  [<c1075c38>] ? ttwu_do_activate.constprop.86+0x58/0x70
  [<c1055190>] ? usleep_range+0x40/0x40
  [<c15e0846>] io_schedule_timeout+0x86/0xd0
  [<c15cef7d>] balance_dirty_pages.isra.17+0x3f5/0x4b4
  [<c15e118d>] ? _raw_spin_lock+0xd/0x10
  [<c1180781>] ? __set_page_dirty_buffers+0x81/0xb0
  [<c110deb5>] ? set_page_dirty+0x55/0x60
  [<c11812c9>] ? __block_page_mkwrite+0xe9/0x170
  [<c110f3ae>] balance_dirty_pages_ratelimited_nr+0xde/0x100
  [<c1126f53>] do_wp_page+0x503/0x830
  [<c1128ef7>] handle_pte_fault+0x267/0x2c0
  [<c1129c62>] handle_mm_fault+0x1e2/0x280
  [<c15e4988>] do_page_fault+0x158/0x4c0
  [<c104e4dc>] ? irq_exit+0x5c/0xa0
  [<c15e22d0>] ? do_debug+0x180/0x180
  [<c15e4830>] ? vmalloc_fault+0x195/0x195
  [<c15e1c53>] error_code+0x67/0x6c

所以,不确定这意味着什么,但这看起来像是关于页面错误的处理,因此指向一个潜在的内存管理问题。

然后我尝试了:

echo 3 >/proc/sys/vm/drop_caches

这确实使问题消失了。

现在,这看起来非常像是一个内核问题。因此,我已更新到最新内核(从 反向移植到 3.8 raring),这就是我目前的情况。如果新内核的问题仍然存在,我会更新。

编辑

新内核的问题仍然存在,尽管没有那么严重。同样的事情,

echo 3 | sudo tee /proc/sys/vm/drop_caches

暂时可以解决问题。我只在 MSI 笔记本电脑上看到过这种情况(产品名称:CR61 2M/CX61 2OC/CX61 2OD)。

编辑 2015 年 12 月

经确认,btrace aptitude/apt-get当时确实执行了一些磁盘 I/O。它/var/cache/apt/pkgcache.bin.<random-chars>在内存中映射了一个临时文件 (),这就是它未显示在输出中的原因strace

仍然无法解释为什么它只发生在某些机器上,为什么删除缓存有帮助,为什么切换到 64 位有帮助。

如果有人可以重现它,那么一个有趣的测试就是看看在运行时是否也会发生这种情况,eatmydata或者移动/var/cache/apttmpfsramdisk 是否有帮助。

答案2

建议http://antti-juhani.kaijanaho.fi/newblog/archives/521已经在不同的计算机上多次帮我加快了速度:

sudo dpkg --clear-avail
sudo sync-available

(该博客也建议sudo dpkg --forget-old-unavail在这两个步骤之间进行,但显然已被弃用并且不再需要。)

答案3

按照步骤:

  • 清除缓存:

    sudo apt-get clean
    
  • 移动sources.list所以apt不能使用它:

    mv /etc/apt/sources.list /etc/apt/sources.list1 && sudo apt-get update
    
  • 将其移回然后更新:

    mv /etc/apt/sources.list1 /etc/apt/sources.list && sudo apt-get update 
    

还要检查并删除您不需要的任何 PPA 和源代码行。

答案4

在我的系统上,原因是LANGUAGE=环境变量中的值不正确。它应该包含诸如 这样的值en:fr:de,而不是en_US.UTF-8,sl_SI.UTF-8

root@fik:~
# locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8,sl_SI.UTF-8
LC_CTYPE=sl_SI.UTF-8
LC_NUMERIC=sl_SI.UTF-8
LC_TIME=sl_SI.UTF-8
LC_COLLATE=sl_SI.UTF-8
LC_MONETARY=sl_SI.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=sl_SI.UTF-8
LC_NAME=sl_SI.UTF-8
LC_ADDRESS=sl_SI.UTF-8
LC_TELEPHONE=sl_SI.UTF-8
LC_MEASUREMENT=sl_SI.UTF-8
LC_IDENTIFICATION=sl_SI.UTF-8
LC_ALL=

运行strace该命令时(通过),调用apt-get update时会卡住read()。执行时间很长,并且会占用一个 CPU 核心的所有可用周期:

root@fik:~
# strace apt-get update
[snip]
read(5, "form, hardware::opengl, implemen"..., 32146) = 32146
read(5, " Maintainers <pkg-bluetooth-main"..., 32658) = 32658
read(5, ": 17569748\nMD5sum: 9c20d52f9a0d5"..., 32200) = 32200
brk(0x55ac79212000)                     = 0x55ac79212000
read(5, "scription-md5: ca1156b27bec24d4c"..., 32469) = 32469
read(5, " Boost.Math Library\nMulti-Arch: "..., 32477) = 32477
read(5, "epends: libc6 (>= 2.4), lsb-base"..., 32648) = 32648
^C--- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} ---
strace: Process 18452 detached

如果我设置LANGUAGE=为正确的值(例如en),一切都会恢复正常:

root@fik:~
# export LANGUAGE=en

root@fik:~
# locale
LANG=en_US.UTF-8
LANGUAGE=en
LC_CTYPE=sl_SI.UTF-8
LC_NUMERIC=sl_SI.UTF-8
LC_TIME=sl_SI.UTF-8
LC_COLLATE=sl_SI.UTF-8
LC_MONETARY=sl_SI.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=sl_SI.UTF-8
LC_NAME=sl_SI.UTF-8
LC_ADDRESS=sl_SI.UTF-8
LC_TELEPHONE=sl_SI.UTF-8
LC_MEASUREMENT=sl_SI.UTF-8
LC_IDENTIFICATION=sl_SI.UTF-8
LC_ALL=

root@fik:~
# apt-get update
Hit:1 http://ftp.at.debian.org/debian experimental InRelease
Ign:3 http://ftp.at.debian.org/debian jessie InRelease                                                      
Hit:4 http://ftp.at.debian.org/debian jessie-updates InRelease  
Hit:5 http://ftp.at.debian.org/debian jessie-backports InRelease                                                                             
Hit:6 http://ftp.at.debian.org/debian sid InRelease                                                                    
Hit:7 http://ftp.at.debian.org/debian stretch InRelease                               
Hit:8 http://ftp.at.debian.org/debian stretch-updates InRelease                                             
Hit:9 http://ftp.at.debian.org/debian jessie Release                                  
Hit:2 http://screenshots.getdeb.net xenial-getdeb InRelease                           
Hit:10 http://security.debian.org jessie/updates InRelease      
Hit:11 http://security.debian.org stretch/updates InRelease
Reading package lists... Done 

相关内容