2017-09-28 93 views
1

這是Linux內核或系統管理員的問題。儘管免費報告「可用」,但「無法分配內存」

我從QEMU這個錯誤,嘗試啓動虛擬機與3GB內存:

ioctl(KVM_CREATE_VM) failed: 12 Cannot allocate memory 
failed to initialize KVM: Cannot allocate memory 

據我所知,這可能是因爲沒有足夠的內存或提交限制太低,但顯然不是......有5.9 GB的可用傾倒緩存和沒有提交限制:

$ free -m 
       total  used  free  shared buff/cache available 
Mem:   7696  1287   135   139  6274  5973 
Swap:   2892   525  2367 

$ cat /proc/sys/vm/overcommit_memory 
1 

於是我就寫了一個C++程序來分配先後更大的塊。我發現它未能分配超過2.1 GB。 (N.B.它被編譯爲64位)。這與Qemu沒有啓動一致,但爲什麼?

然後我修改它寫入內存。這導致一些緩存被傾倒,提供免費的報告,在這個分配約2 GB:

$ free -m 
       total  used  free  shared buff/cache available 
Mem:   7696  2988   288   143  4420  4268 
Swap:   2892   525  2367 

...這在程序終止:

$ free -m 
       total  used  free  shared buff/cache available 
Mem:   7696  1258  2253   147  4185  5994 
Swap:   2892   525  2367 

現在我試圖啓動的Qemu和神奇有效!免費報告:

$ free -m 
       total  used  free  shared buff/cache available 
Mem:   7696  2438  4451   147   806  4834 
Swap:   2892   530  2362 

所以看起來內核不願意當問一大塊釋放一些緩存,但是願意讓他們在幾個步驟走。這是怎麼回事?

我運行Debian測試: 的Linux - 4.11.0-1-AMD64#1 SMP的Debian 4.11.6-1(2017年6月19日)x86_64的GNU/Linux的

回答

0

我發現一種解決方法,其表明問題是內存碎片。在最近的一個問題的再次發生,我跑以下命令,解決了這一問題:

echo 1 > /proc/sys/vm/compact_memory 

相關崗位:https://unix.stackexchange.com/questions/44481/defragging-ram-oom-failure/147860#147860

這裏是從壓實前dmesg的轉儲,這可能會顯示有關該問題的更多信息,但我不能理解它:

[618172.910238] QEMU系統86:頁面分配失敗:順序:4,模式:0x16040c0(GFP_KERNEL | __GFP_COMP | __GFP_NOTRACK),nodemask =(空) [618172.910244] qemu-system-x86 cpuset =/mems_allowed = 0 [618172.910248] CPU:1 PID:19454 Comm:qemu-system-x86沒有污染4.13.0-1-amd64#1 Debian 4.13.13-1 [618172.910249]硬件名稱:系統製造商系統產品名稱/ P8Z68 -V LX,BIOS 4105 07/01/2013 [618172.910250]通話跟蹤: [618172.910256]? dump_stack + 0x5c/0x85 [618172.910257]? warn_alloc + 0x114/0x1b0 [618172.910259]? __alloc_pages_direct_compact + 0x4a/0xf0 [618172.910261]? __alloc_pages_slowpath + 0xd57/0xd60 [618172.910261]? __alloc_pages_slowpath + 0xd57/0xd60 [618172.910263]? __alloc_pages_nodemask + 0x228/0x250 [618172.910266]? cache_grow_begin + 0x80 /​​ 0x530 [618172.910267]? cache_grow_begin + 0x80 /​​ 0x530 [618172.910269]? fallback_alloc + 0x161/0x200 [618172.910271]?kmem_cache_alloc_trace + 0x1c3/0x5a0 [618172.910292]? kvm_dev_ioctl + 0xb6/0x6b0 [kvm] [618172.910305]? do_vfs_ioctl + 0x9f/0x600 [618172.910306]? SyS_ioctl + 0x74/0x80 [618172.910308]? system_call_fast_compare_end +位於0xC/0x97 [618172.910309] MEM-信息: [618172.910313] active_anon:337090 inactive_anon:152155 isolated_anon:0 active_file:140849 inactive_file:198001 isolated_file:0 unevictable:28髒:8的回寫:0不穩定:0 slab_reclaimable:773968 slab_unreclaimable:14206 映射:112839 SHMEM:69965個pagetables:12329彈跳:0 自由:320850 free_pcp:0 free_cma:0 [618172.910315]節點0 active_anon:1348360kB inactive_anon:608620kB active_file:563396kB inactive_file:792004kB unevictable:112KB隔離(anon):0kB隔離(文件):0kB映射:451356kB髒:32kB回寫:0kB shmem:279860kB shmem_thp:0kB shmem_pmdmapped:0kB anon_thp:215040kB writeback_tmp:0kB unstable:0kB all_unreclaimable?沒有 [618172.910315]節點0無DMA:15900kB最低:136kB低:168kB高:200kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevicetable:0kB writepending:0kB present:15984kB管理:15900kB mlocked:0kB kernel_stack:0kB pagetables:0KB彈跳:0KB free_pcp:0KB local_pcp:0KB free_cma:0KB [618172.910317] lowmem_reserve []:0 3200 7657 7657 7657 [618172.910319]節點0 DMA32自由:1205068kB分鐘:28184kB低:35228kB高:42272kB active_anon:462188kB inactive_anon:167656kB active_file:159796kB inactive_file:164356kB unevicetable:0kB writepending:0kB present:3362060kB managed:3296492kB mlocked:0kB kernel_stack:976kB pagetables:4164kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB [618172.910321] lowmem_reserve []: 0 0 4457 4457 4457 [618172.910323]節點0正常空閒:62432kB分鐘:39260kB低:49072kB高:58884kB active_anon :886172kB inactive_anon:440964kB active_file:403600kB inactive_file:627648kB unevictable:112KB writepending:32kB的存在:4708352kB管理:4568752kB mlocked:112KB kernel_stack:12672kB pagetables:45152kB彈跳:0KB free_pcp:0KB local_pcp:0KB free_cma:0KB [618172.910324] lowmem_reserve [ ]:0 0 0 0 0 [618172.910326]節點0 DMA:1 * 4kB(U)1 * 8kB(U)1 * 16kB(U)0 * 32kB 2 * 64kB(U)1 * 128kB(U) 256kB(U)0 * 512kB 1 * 1024kB(U)1 * 2048kB(M)3 * 4096kB(M)= 15900kB [618172.910332]節點0 DMA32:59795 * 4kB(UME)67824 * 8kB(UME)21933 * 16kB (UME)2275 * 32kB(UE)0 * 64kB 0 * 128kB 0 * 256kB 0 * 512kB 0 * 1024kB 0 * 2048kB 0 * 4096kB = 1205500kB [618172.910337]節點0正常:1460 * 4kB(UME)1303 * 8kB UME)2698 * 16kB(UME)104 * 32kB(UME)0 * 64kB 0 * 128kB 0 * 256kB 0 * 512kB 0 * 1024kB 0 * 2048kB 0 * 4096kB = 62760kB [618172.910343] Node 0 hugepages_total = 0 hugepages_free = 0 hu gepages_surp = 0 hugepages_size = 2048KB [618172.910343] 384298總頁緩存頁 [618172.910344] 9802頁交換緩存 [618172.910345]交換緩存統計:加1402693,刪除1392949,找到一百零七萬零三百九十二分之八十六萬一千七百七十七 [618172.910345]免費交換= 1537612kB [618172.910345]總計交換= 2962428kB [618172.910346] 2021599頁RAM [618172.910346] 0頁HIGHMEM/MovableOnly [618172.910346] 51313頁保留 [618172.910347] 0頁hwpoisoned