Linux

請幫忙解讀OOM-Killer

  • January 19, 2020

我們正在測試我們的 java 應用程序,它被 OOM Killer 殺死,日誌如下。

幾點:這是一個 java web 應用程序。它以 190G 堆執行。伺服器是一個總記憶體為 240G 的 EC2 實例。我們在 JDK 11 中嘗試了新的、實驗性的 ZGC。當時應用程序沒有負載,在類似 prod 的測試環境中執行。該應用程序確實有一些調度觸發的處理,並且可能是記憶體和 CPU 密集型的,但這些處理經常執行並且沒有失敗。

應用程式碼與我們在生產中的程式碼沒有顯著變化。我們也成功地對此進行了負載測試,包括沒有問題的 12 小時浸泡測試。

現在查看 OOM-Killer 日誌。完整的日誌如下,但我覺得很奇怪的一件事是這一行:

Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.571217] Killed process 4973 (java) total-vm:17181703924kB, anon-rss:9740kB, file-rss:0kB, shmem-rss:0kB

虛擬機總大小約為 17 TB。這對我來說很奇怪,因為我們的應用程序甚至不會嘗試正常請求這個。我懷疑我們可能遇到了一些 ZGC 或 ZGC+我們的程式碼錯誤,但想確保我沒看錯。

我非常感謝任何幫助,完整的日誌供參考:

Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.158902] java invoked oom-killer: gfp_mask=0x14200ca(GFP_HIGHUSER_MOVABLE), nodemask=(null),  order=0, oom_score_adj=0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.166556] java cpuset=/ mems_allowed=0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.168975] CPU: 15 PID: 4974 Comm: java Not tainted 4.14.55-62.37.amzn1.x86_64 #1
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.173353] Hardware name: Xen HVM domU, BIOS 4.2.amazon 08/24/2006
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.177219] Call Trace:
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.178806]  dump_stack+0x5c/0x82
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.180848]  dump_header+0x94/0x21c
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.183087]  ? get_page_from_freelist+0x525/0xba0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.185945]  oom_kill_process+0x213/0x410
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.188518]  out_of_memory+0x296/0x4c0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.190748]  __alloc_pages_slowpath+0x9ef/0xdd0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.193653]  __alloc_pages_nodemask+0x207/0x220
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.196455]  alloc_pages_vma+0x7c/0x1e0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.198924]  shmem_alloc_page+0x65/0xa0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.201277]  ? __radix_tree_insert+0x35/0x1f0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.204022]  ? __vm_enough_memory+0x23/0x130
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.206639]  shmem_alloc_and_acct_page+0x72/0x1b0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.209513]  shmem_getpage_gfp+0x14b/0xb40
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.212102]  ? __set_page_dirty+0xc0/0xc0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.214705]  shmem_fallocate+0x32d/0x440
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.217182]  vfs_fallocate+0x13f/0x260
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.219525]  SyS_fallocate+0x43/0x80
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.221657]  do_syscall_64+0x67/0x100
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.223944]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.227002] RIP: 0033:0x7fcc064ab1f9
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.229295] RSP: 002b:00007fcc071df800 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.233706] RAX: ffffffffffffffda RBX: 0000002f80000000 RCX: 00007fcc064ab1f9
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.237896] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000005
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.242203] RBP: 00007fcc071df860 R08: 0000000000000005 R09: 0000000000000000
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.246538] R10: 0000002f80000000 R11: 0000000000000246 R12: 0000000000001000
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.250675] R13: 0000002f80000000 R14: 00007fcc00030d18 R15: 0000002f80000000
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.254948] Mem-Info:
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313] active_anon:46337469 inactive_anon:15816944 isolated_anon:0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313]  active_file:362 inactive_file:1424 isolated_file:0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313]  unevictable:0 dirty:87 writeback:0 unstable:0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313]  slab_reclaimable:146831 slab_unreclaimable:12432
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313]  mapped:49788503 shmem:61099090 pagetables:297088 bounce:0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.256313]  free:264623 free_pcp:31 free_cma:0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.276739] Node 0 active_anon:185857908kB inactive_anon:62759744kB active_file:1448kB inactive_file:5696kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:199154012kB dirty:348kB writeback:0kB shmem:244396360kB shmem_thp: 0kB shmem_pmdmapped: 0kB anon_thp: 0kB writeback_tmp:0kB unstable:0kB all_unreclaimable? yes
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.293799] Node 0 DMA free:15904kB min:4kB low:16kB high:28kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:15988kB managed:15904kB mlocked:0kB kernel_stack:0kB pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.308882] lowmem_reserve[]: 0 1928 245809 245809
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.311710] Node 0 DMA32 free:976000kB min:528kB low:2500kB high:4472kB active_anon:0kB inactive_anon:1017428kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:2080768kB managed:1995880kB mlocked:0kB kernel_stack:0kB pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.327796] lowmem_reserve[]: 0 0 243881 243881
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.330558] Node 0 Normal free:66588kB min:67048kB low:316780kB high:566512kB active_anon:187190988kB inactive_anon:60409332kB active_file:1448kB inactive_file:5696kB unevictable:0kB writepending:0kB present:253755392kB managed:249734404kB mlocked:0kB kernel_stack:7280kB pagetables:1188352kB bounce:0kB free_pcp:124kB local_pcp:120kB free_cma:0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.348446] lowmem_reserve[]: 0 0 0 0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.350789] Node 0 DMA: 0*4kB 0*8kB 0*16kB 1*32kB (U) 2*64kB (U) 1*128kB (U) 1*256kB (U) 0*512kB 1*1024kB (U) 1*2048kB (M) 3*4096kB (M) = 15904kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.358404] Node 0 DMA32: 1*4kB (M) 1*8kB (U) 2*16kB (UM) 2*32kB (UE) 1*64kB (U) 1*128kB (U) 2*256kB (UE) 3*512kB (UME) 3*1024kB (UME) 2*2048kB (UM) 236*4096kB (M) = 976172kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.367499] Node 0 Normal: 2527*4kB (UME) 778*8kB (UME) 293*16kB (UME) 104*32kB (UME) 51*64kB (UME) 24*128kB (UME) 5*256kB (UM) 2*512kB (UM) 1*1024kB (U) 3*2048kB (UME) 8*4096kB (M) = 72924kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.377787] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=1048576kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.382919] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.387847] 61100730 total pagecache pages
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.390368] 0 pages in swap cache
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.392264] Swap cache stats: add 0, delete 0, find 0/0
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.395429] Free swap  = 0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.397195] Total swap = 0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.398971] 63963037 pages RAM
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.400873] 0 pages HighMem/MovableOnly
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.403102] 1026490 pages reserved
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.405255] [ pid ]   uid  tgid total_vm      rss nr_ptes nr_pmds swapents oom_score_adj name
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.410245] [ 2730]     0  2730     2833      194      11       3        0         -1000 udevd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.415382] [ 2848]     0  2848     2812      165      10       3        0         -1000 udevd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.420563] [ 2849]     0  2849     2812      161      10       3        0         -1000 udevd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.425740] [ 3137]     0  3137    27285       57      21       3        0             0 lvmetad
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.430993] [ 3146]     0  3146     6799       48      18       3        0             0 lvmpolld
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.436187] [ 3354]     0  3354     2353      121      10       3        0             0 dhclient
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.441499] [ 3410]     0  3410    13251       98      27       3        0         -1000 auditd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.446792] [ 3431]     0  3431    61878      132      23       3        0             0 rsyslogd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.452140] [ 3451]     0  3451    23291      114      15       3        0             0 irqbalance
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.457538] [ 3461]     0  3461     1630       25       9       3        0             0 rngd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.462533] [ 3478]    81  3478     5461       58      15       3        0             0 dbus-daemon
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.468050] [ 3513]     0  3513     1099       35       8       3        0             0 acpid
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.473222] [ 3609]     0  3609    20134      207      42       3        0         -1000 sshd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.478262] [ 3622]     0  3622    28967      266      60       3        0             0 sshd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.483118] [ 3624]   500  3624    28967      265      59       3        0             0 sshd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.488272] [ 3625]   500  3625    28850      113      13       3        0             0 bash
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.493403] [ 3658]    38  3658    29129      204      29       3        0             0 ntpd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.498490] [ 3702]     0  3702    22395      432      45       3        0             0 sendmail
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.503845] [ 3712]    51  3712    20259      374      40       3        0             0 sendmail
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.509091] [ 3724]     0  3724    30411      149      14       3        0             0 crond
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.514018] [ 3738]     0  3738     4797       42      13       3        0             0 atd
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.518902] [ 3773]     0  3773     1090       24       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.524491] [ 3775]     0  3775     1627       31       9       3        0             0 agetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.529721] [ 3778]     0  3778     1090       24       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.535029] [ 3781]     0  3781     1090       24       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.540245] [ 3783]     0  3783     1090       24       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.545404] [ 3785]     0  3785     1090       24       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.550610] [ 3787]     0  3787     1090       25       8       3        0             0 mingetty
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.556012] [ 4948]   500  4948    28285       60      12       3        0             0 start_server.sh
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.561798] [ 4973]   500  4973 4295425981     2435      71       5        0             0 java
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.566936] Out of memory: Kill process 4973 (java) score 0 or sacrifice child
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.571217] Killed process 4973 (java) total-vm:17181703924kB, anon-rss:9740kB, file-rss:0kB, shmem-rss:0kB
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.578364] oom_reaper: reaped process 4973 (java), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

更新: 看起來 17 TB 虛擬記憶體(top在應用程序執行期間也可見)並不是真正的問題。

我們設置了一個簡單的 Spring Boot hello world 應用程序,除了啟用 ZGC 之外的預設設置,同樣的事情發生了。看起來 ZGC 分配了 4 TB 的地址空間而不管堆大小,並且還會多次映射同一個物理地址,所以這顯然是正常的。我找不到任何人討論它,這令人驚訝。

當我們嘗試關閉應用程序時,OOM-Killer 似乎參與其中。鑑於我們無論如何都試圖關閉它,我並不特別擔心。

再次感謝大家的幫助。

記憶體不足。

12 月 18 日 23:24:59 ip-10-0-3-36 核心:

$$ 775.566936 $$ 記憶體不足:殺死程序 4973 (java) 得分 0 或犧牲孩子

來自同一日誌(ps);

$$ 775.561798 $$ $$ 4973 $$ 500 4973 4295425981 2435 71 5 0 0 爪哇

4295425.981 大約是 4TB。並且行 total-vm:17181703924kB 顯示大約 17TB。

你能調試你的記憶體分配常式嗎?至於我,您的應用程序在某個地方出現了錯誤的循環,並且必須佔用所有可用的資源,並且交換也可用。

Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.214705]  shmem_fallocate+0x32d/0x440
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.217182]  vfs_fallocate+0x13f/0x260
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.219525]  SyS_fallocate+0x43/0x80
Dec 18 23:24:59 ip-10-0-3-36 kernel: [  775.221657]  do_syscall_64+0x67/0x100

您的應用程序程序正在嘗試fallocate在 shmem 文件系統上呼叫。從快速Google搜尋來看,ZGC 似乎使用 fallocate 從 shm 文件系統中獲取初始堆記憶體,然後繼續使用 fallocate 來擴展堆。這種 fallocate 系統呼叫的使用是相當不尋常的,所以要麼這是一個 ZGC 錯誤(正如您已經懷疑的那樣),要麼是其他原因導致大量記憶體洩漏,從而導致堆擴展失敗。

我建議,您配置 ZGC 以避免額外的執行時分配(設置XmsXmx相同的值)。如果由於不相關的事情而發生記憶體洩漏,這可能無法解決您的問題,但至少您將有更好的機會找到真正的罪魁禍首。

請注意,您的整體設置有些危險——ZGC 顯然喜歡擁有大量連續記憶體,但如果您在 240G RAM 機器上有 190G 堆,則可能沒有足夠大的連續區域可供使用fallocate。在這種情況下,ZGC 將回退到通過進一步呼叫來拾取小記憶體區域fallocate(參見連結錯誤報告的描述),並且問題將再次變得模糊……在 JVM 中啟用大頁面支持(普通大頁面,而不是透明大頁面!)和在引導期間預分配大頁面(使用核心參數) - 無論如何,對於您的堆大小,建議使用大頁面。

引用自:https://serverfault.com/questions/946160