为什么 OOM killer 会攻击这里

为什么 OOM killer 会攻击这里

我们有一些在 xen 4.0.3 下运行内核 2.26.26-2 的虚拟机,这些虚拟机的 CPU 和 RAM 数量不同,有些虚拟机几乎会随机发生 OOM 事件,每次都会使虚拟机无法使用。输出如下,我有以下问题:

  1. 这跟什么_cpu_down有关?我发现所有受影响的机器上都有这个问题,但我认为它们都不应该调用这个(我认为属于 cpu-hotplug 系统)
  2. 有人在内存打印输出中看到一些怪异的东西吗?在每台出现此问题的机器上,HighMem 和 Normal 的可用值几乎相同。
  3. 由于该行的值降至低于,如果我将该行读HighMem free:496kB min:512kB low:9336kB作 OOM 的来源,我是否正确?freemin
  4. 关于如何追踪问题有什么建议吗?我监控了所有机器的内存使用情况,但没有一台机器在 OOM 时显示可用内存减少(监控间隔为 5 分钟,所以我可能会错过令人兴奋的部分)。
Jul  9 14:01:36 www23 kernel: [990735.330526] php-cgi invoked oom-killer: gfp_mask=0x1201d2, order=0, oomkilladj=0
Jul  9 14:01:42 www23 kernel: [990735.330544] Pid: 7749, comm: php-cgi Not tainted 2.6.26-2-xen-686 #1
Jul  9 14:04:20 www23 kernel: [990735.330555]  [<c0150df2>] oom_kill_process+0x4f/0x1bb
Jul  9 14:04:20 www23 kernel: [990735.330571]  [<c0125134>] __capable+0x8/0x1b
Jul  9 14:04:58 www23 kernel: [990735.330582]  [<c0151293>] out_of_memory+0x14e/0x17f
Jul  9 14:04:58 www23 kernel: [990735.330591]  [<c01532e1>] __alloc_pages_internal+0x2b8/0x34e
Jul  9 14:04:58 www23 kernel: [990735.330603]  [<c0153383>] __alloc_pages+0x7/0x9
Jul  9 14:04:58 www23 kernel: [990735.330617]  [<c0154e7c>] __do_page_cache_readahead+0x86/0x163
Jul  9 14:04:58 www23 kernel: [990735.330631]  [<c01552ae>] do_page_cache_readahead+0x3d/0x47
Jul  9 14:04:58 www23 kernel: [990735.330646]  [<c0150692>] filemap_fault+0x164/0x35a
Jul  9 14:04:58 www23 kernel: [990735.330658]  [<c015a5a5>] __do_fault+0x43/0x4c9
Jul  9 14:04:58 www23 kernel: [990735.330677]  [<c015ec3b>] handle_mm_fault+0x63c/0xda5
Jul  9 14:04:58 www23 kernel: [990735.330688]  [<c01e0aaf>] rb_erase+0x176/0x22f
Jul  9 14:04:58 www23 kernel: [990735.330702]  [<c010eaf3>] do_page_fault+0x605/0xb2e
Jul  9 14:04:58 www23 kernel: [990735.330712]  [<c023de5f>] evtchn_do_upcall+0xfa/0x191
Jul  9 14:04:58 www23 kernel: [990735.330725]  [<c010e4ee>] do_page_fault+0x0/0xb2e
Jul  9 14:04:58 www23 kernel: [990735.330736]  [<c02cc9c5>] error_code+0x35/0x3c
Jul  9 14:04:58 www23 kernel: [990735.330752]  [<c02c0000>] _cpu_down+0x50/0x20a
Jul  9 14:04:58 www23 kernel: [990735.330762]  =======================
Jul  9 14:04:58 www23 kernel: [990735.330771] Mem-info:
Jul  9 14:04:58 www23 kernel: [990735.330776] DMA per-cpu:
Jul  9 14:04:58 www23 kernel: [990735.330781] CPU    0: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330788] CPU    1: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330798] CPU    2: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330805] CPU    3: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330811] CPU    4: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330822] CPU    5: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330827] CPU    6: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330833] CPU    7: hi:    0, btch:   1 usd:   0
Jul  9 14:04:58 www23 kernel: [990735.330840] Normal per-cpu:
Jul  9 14:04:58 www23 kernel: [990735.330849] CPU    0: hi:  186, btch:  31 usd: 168
Jul  9 14:04:58 www23 kernel: [990735.330857] CPU    1: hi:  186, btch:  31 usd: 157
Jul  9 14:04:58 www23 kernel: [990735.330865] CPU    2: hi:  186, btch:  31 usd: 170
Jul  9 14:04:58 www23 kernel: [990735.330876] CPU    3: hi:  186, btch:  31 usd: 180
Jul  9 14:04:58 www23 kernel: [990735.330882] CPU    4: hi:  186, btch:  31 usd: 181
Jul  9 14:04:58 www23 kernel: [990735.330887] CPU    5: hi:  186, btch:  31 usd: 177
Jul  9 14:04:58 www23 kernel: [990735.330897] CPU    6: hi:  186, btch:  31 usd: 182
Jul  9 14:04:58 www23 kernel: [990735.330905] CPU    7: hi:  186, btch:  31 usd: 163
Jul  9 14:04:58 www23 kernel: [990735.330912] HighMem per-cpu:
Jul  9 14:04:58 www23 kernel: [990735.330917] CPU    0: hi:  186, btch:  31 usd:  18
Jul  9 14:04:58 www23 kernel: [990735.330925] CPU    1: hi:  186, btch:  31 usd: 159
Jul  9 14:04:58 www23 kernel: [990735.330930] CPU    2: hi:  186, btch:  31 usd: 110
Jul  9 14:04:58 www23 kernel: [990735.330938] CPU    3: hi:  186, btch:  31 usd:  92
Jul  9 14:04:58 www23 kernel: [990735.330945] CPU    4: hi:  186, btch:  31 usd:  66
Jul  9 14:04:58 www23 kernel: [990735.330951] CPU    5: hi:  186, btch:  31 usd: 137
Jul  9 14:04:58 www23 kernel: [990735.330959] CPU    6: hi:  186, btch:  31 usd: 165
Jul  9 14:04:58 www23 kernel: [990735.330970] CPU    7: hi:  186, btch:  31 usd: 134
Jul  9 14:04:58 www23 kernel: [990735.330979] Active:1895504 inactive:10287 dirty:0 writeback:0 unstable:0
Jul  9 14:04:58 www23 kernel: [990735.330981]  free:61788 slab:67983 mapped:13 pagetables:0 bounce:0
Jul  9 14:04:58 www23 kernel: [990735.330998] DMA free:6152kB min:72kB low:88kB high:108kB active:0kB inactive:0kB present:16256kB pages_scanned:0 all_unreclaimable? yes
Jul  9 14:04:58 www23 kernel: [990735.331008] lowmem_reserve[]: 0 706 8120 8120
Jul  9 14:04:58 www23 kernel: [990735.331028] Normal free:240504kB min:3364kB low:4204kB high:5044kB active:28964kB inactive:476kB present:723392kB pages_scanned:57291 all_unreclaimable? yes
Jul  9 14:04:58 www23 kernel: [990735.331044] lowmem_reserve[]: 0 0 59309 59309
Jul  9 14:04:58 www23 kernel: [990735.331060] HighMem free:496kB min:512kB low:9336kB high:18164kB active:7553052kB inactive:40672kB present:7591552kB pages_scanned:13757719 all_unreclaimable? yes
Jul  9 14:04:58 www23 kernel: [990735.331076] lowmem_reserve[]: 0 0 0 0
Jul  9 14:04:58 www23 kernel: [990735.331094] DMA: 126*4kB 44*8kB 47*16kB 42*32kB 8*64kB 1*128kB 0*256kB 1*512kB 0*1024kB 1*2048kB 0*4096kB = 6152kB
Jul  9 14:04:58 www23 kernel: [990735.331133] Normal: 41282*4kB 8957*8kB 62*16kB 1*32kB 2*64kB 2*128kB 0*256kB 1*512kB 0*1024kB 1*2048kB 0*4096kB = 240752kB
Jul  9 14:04:58 www23 kernel: [990735.331169] HighMem: 90*4kB 3*8kB 7*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 496kB
Jul  9 14:04:58 www23 kernel: [990735.331204] 18015 total pagecache pages
Jul  9 14:04:58 www23 kernel: [990735.331211] Swap cache: add 0, delete 0, find 0/0
Jul  9 14:04:58 www23 kernel: [990735.331221] Free swap  = 0kB
Jul  9 14:04:58 www23 kernel: [990735.331225] Total swap = 0kB
Jul  9 14:04:58 www23 kernel: [990735.358501] 2099200 pages of RAM
Jul  9 14:04:58 www23 kernel: [990735.358514] 1912832 pages of HIGHMEM
Jul  9 14:04:58 www23 kernel: [990735.358519] 19870 reserved pages
Jul  9 14:04:58 www23 kernel: [990735.358523] 6341777 pages shared
Jul  9 14:04:58 www23 kernel: [990735.358527] 0 pages swap cached
Jul  9 14:04:58 www23 kernel: [990735.358531] 0 pages dirty
Jul  9 14:04:58 www23 kernel: [990735.358535] 0 pages writeback
Jul  9 14:04:58 www23 kernel: [990735.358539] 13 pages mapped
Jul  9 14:04:58 www23 kernel: [990735.358542] 67983 pages slab
Jul  9 14:04:58 www23 kernel: [990735.358553] 0 pages pagetables
Jul  9 14:04:58 www23 kernel: [990735.358558] Out of memory: kill process 1493 (httpd) score 42880 or a child
Jul  9 14:04:58 www23 kernel: [990735.358629] Killed process 8099 (httpd)

如您所见,该机器是一个网络服务器,在正常情况下,它的 meminfo 显示如下内容:

MemTotal:      8388804 kB
MemFree:        666696 kB
Buffers:         49352 kB
Cached:        5589884 kB
SwapCached:      14368 kB
Active:        2106596 kB
Inactive:      5127116 kB
HighTotal:     7646976 kB
HighFree:       455376 kB
LowTotal:       741828 kB
LowFree:        211320 kB
SwapTotal:     1048568 kB
SwapFree:      1024244 kB
Dirty:             496 kB
Writeback:           0 kB
AnonPages:     1580456 kB
Mapped:          13340 kB
Slab:           367520 kB
SReclaimable:   343680 kB
SUnreclaim:      23840 kB
PageTables:          0 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
WritebackTmp:        0 kB
CommitLimit:   9437372 kB
Committed_AS:  9499972 kB
VmallocTotal:   114680 kB
VmallocUsed:      5180 kB
VmallocChunk:   106596 kB

系统是 Debian,内核是 2.6.26-2-xen-686。欢迎提出任何想法。

答案1

我最近在尝试使用我们的 Web 工具生成多个 PDF 时遇到了这个问题。对于我们来说,答案是通过更改 /etc/php.ini 文件中的以下设置来为 PHP 提供更多内存:

memory_limit = 128M

您可能需要退一步思考您的 PHP 请求/作业正在做什么,以评估应将内存限制设置到多高。

为了追踪它,我会查看 apache 的访问/错误日志,看看在 7 月 9 日 14:01:36 之前发出了哪些请求。任何错误、警告或长服务器请求都可能表明您的 Web 应用程序的哪一部分可能正在使用 PHP 允许的内存限制。

答案2

_cpu_down()改变当前任务的亲和力,然后在最后恢复它;如果我没记错的话,我的谷歌搜索被证明是正确的。

因此,这似乎是一个转移注意力的花招,只不过是被调用的 oom_killer 的清理任务。

php-cgi invoked oom-killer:这个 cgi 进程的内存是否受到限制?代码中是否调用了 ini_set() 来提高内存限制?

我还会使用以下工具查看 Apache 可用的线程数:https://github.com/Oneiroi/apachebuddy.pl估计可能的总内存使用量。

根据提供的信息,我认为您的问题要么在于所有消耗的 php 进程,要么在于允许生成太多 php 进程,从而过度利用可用内存。

相关内容