为什么当我使用了 80% 的内存时,Java、Android 模拟器和 Chrome 也会崩溃并抱怨内存不足?

为什么当我使用了 80% 的内存时,Java、Android 模拟器和 Chrome 也会崩溃并抱怨内存不足?

我的主计算机最近在使用几个小时后大多数应用程序就开始崩溃,并抱怨内存不足。

我正在运行一台配备 16GB RAM 的 Dell Optiplex 7070。我知道 16GB 并不是什么了不起的东西,但根据我的经验,它应该足以运行我的设置。这台机器包含我的全栈开发环境,因此我主要通过 Android 设备管理器运行 SQL Server、Visual Studio 2022 和 Android 模拟器。

当我通过 Visual Studio 在 Android 模拟器上运行我的移动应用程序时,它经常会失败并显示一条消息,提示 javac 内存不足,并且此文件被添加到我的 .NET 项目的根目录中:

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 266338304 bytes for Failed to commit area from 0x0000000703600000 to 0x0000000713400000 of length 266338304.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (./src/hotspot/os/windows/os_windows.cpp:3386), pid=11788, tid=3400
#
# JRE version:  (11.0.16.1+1) (build )
# Java VM: OpenJDK 64-Bit Server VM (11.0.16.1+1-LTS, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#

---------------  S U M M A R Y ------------

Command Line: com.xamarin.manifestmerger.Main obj\Debug\net7.0-android\android\manifestmerger.rsp

Host: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz, 8 cores, 15G,  Windows 11 , 64 bit Build 22621 (10.0.22621.1485)
Time: Wed May  3 09:06:07 2023 E. South America Standard Time elapsed time: 0.014083 seconds (0d 0h 0m 0s)

---------------  T H R E A D  ---------------

Current thread (0x000001e60c77a000):  JavaThread "Unknown thread" [_thread_in_vm, id=3400, stack(0x000000cd12700000,0x000000cd12800000)]

Stack: [0x000000cd12700000,0x000000cd12800000]
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x62652a]
V  [jvm.dll+0x7b3249]
V  [jvm.dll+0x7b4938]
V  [jvm.dll+0x7b5013]
V  [jvm.dll+0x24fca8]
V  [jvm.dll+0x62383a]
V  [jvm.dll+0x617fe5]
V  [jvm.dll+0x307bac]
V  [jvm.dll+0x307a32]
V  [jvm.dll+0x30c746]
V  [jvm.dll+0x352b9f]
V  [jvm.dll+0x3525d0]
V  [jvm.dll+0x2e4ba8]
V  [jvm.dll+0x2e5d06]
V  [jvm.dll+0x78d097]
V  [jvm.dll+0x78e81f]
V  [jvm.dll+0x35f8e9]
V  [jvm.dll+0x770000]
V  [jvm.dll+0x3cd40f]
V  [jvm.dll+0x3cf7a1]
C  [jli.dll+0x5207]
C  [ucrtbase.dll+0x29363]
C  [KERNEL32.DLL+0x1269d]
C  [ntdll.dll+0x5a9f8]


---------------  P R O C E S S  ---------------

Threads class SMR info:
_java_thread_list=0x000001e60a606010, length=0, elements={
}

Java Threads: ( => current thread )

Other Threads:
  0x000001e60c790800 GCTaskThread "GC Thread#0" [stack: 0x000000cd12800000,0x000000cd12900000] [id=9592]
  0x000001e60c7ef000 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000cd12900000,0x000000cd12a00000] [id=6356]
  0x000001e60c7f5800 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000cd12a00000,0x000000cd12b00000] [id=8444]

[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffe999a4377]

VM state:not at safepoint (not fully initialized)

VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
[0x000001e60c7760e0] Heap_lock - owner thread: 0x000001e60c77a000

Heap address: 0x0000000703600000, size: 4042 MB, Compressed Oops mode: Non-zero based: 0x0000000703600000
Narrow klass base: 0x0000000000000000, Narrow klass shift: 0

GC Heap History (0 events):
No events

Deoptimization events (0 events):
No events

Classes redefined (0 events):
No events

Internal exceptions (0 events):
No events

Events (1 events):
Event: 0.006 Loaded shared library C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\zip.dll


Dynamic libraries:
0x00007ff76ec00000 - 0x00007ff76ec0d000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\java.exe
0x00007fff4cc90000 - 0x00007fff4cea4000     C:\Windows\SYSTEM32\ntdll.dll
0x00007fff4b150000 - 0x00007fff4b212000     C:\Windows\System32\KERNEL32.DLL
0x00007fff4a660000 - 0x00007fff4a9fc000     C:\Windows\System32\KERNELBASE.dll
0x00007fff4a2b0000 - 0x00007fff4a3c1000     C:\Windows\System32\ucrtbase.dll
0x00007fff33ba0000 - 0x00007fff33bb5000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\VCRUNTIME140.dll
0x00007fff346b0000 - 0x00007fff346c7000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\jli.dll
0x00007fff4b780000 - 0x00007fff4b92b000     C:\Windows\System32\USER32.dll
0x00007fff25d90000 - 0x00007fff2601e000     C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.608_none_a9444ca7c10bb01d\COMCTL32.dll
0x00007fff4aa70000 - 0x00007fff4aa96000     C:\Windows\System32\win32u.dll
0x00007fff4b690000 - 0x00007fff4b737000     C:\Windows\System32\msvcrt.dll
0x00007fff4cbb0000 - 0x00007fff4cbd9000     C:\Windows\System32\GDI32.dll
0x00007fff4a0d0000 - 0x00007fff4a1e3000     C:\Windows\System32\gdi32full.dll
0x00007fff4a5c0000 - 0x00007fff4a65a000     C:\Windows\System32\msvcp_win.dll
0x00007fff4b220000 - 0x00007fff4b251000     C:\Windows\System32\IMM32.DLL
0x00007fff33b00000 - 0x00007fff33b9b000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\msvcp140.dll
0x00007ffe996b0000 - 0x00007ffe9a23a000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\server\jvm.dll
0x00007fff4b5e0000 - 0x00007fff4b68e000     C:\Windows\System32\ADVAPI32.dll
0x00007fff4ad70000 - 0x00007fff4ae14000     C:\Windows\System32\sechost.dll
0x00007fff4c560000 - 0x00007fff4c677000     C:\Windows\System32\RPCRT4.dll
0x00007fff4cc40000 - 0x00007fff4cc48000     C:\Windows\System32\PSAPI.DLL
0x00007fff37f50000 - 0x00007fff37f84000     C:\Windows\SYSTEM32\WINMM.dll
0x00007fff475c0000 - 0x00007fff475c9000     C:\Windows\SYSTEM32\WSOCK32.dll
0x00007fff431d0000 - 0x00007fff431da000     C:\Windows\SYSTEM32\VERSION.dll
0x00007fff4afc0000 - 0x00007fff4b031000     C:\Windows\System32\WS2_32.dll
0x00007fff490e0000 - 0x00007fff490f8000     C:\Windows\SYSTEM32\kernel.appcore.dll
0x00007fff449d0000 - 0x00007fff449e0000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\verify.dll
0x00007fff47030000 - 0x00007fff4725e000     C:\Windows\SYSTEM32\DBGHELP.DLL
0x00007fff4b930000 - 0x00007fff4bcb9000     C:\Windows\System32\combase.dll
0x00007fff4aaa0000 - 0x00007fff4ab77000     C:\Windows\System32\OLEAUT32.dll
0x00007fff46ff0000 - 0x00007fff47022000     C:\Windows\SYSTEM32\dbgcore.DLL
0x00007fff4a540000 - 0x00007fff4a5bb000     C:\Windows\System32\bcryptPrimitives.dll
0x00007fff33ad0000 - 0x00007fff33af8000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\java.dll
0x00007fff44050000 - 0x00007fff4405a000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\jimage.dll
0x00007fff33ab0000 - 0x00007fff33ac8000     C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\zip.dll

dbghelp: loaded successfully - version: 4.0.5 - missing functions: none
symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\Windows\SYSTEM32;C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.608_none_a9444ca7c10bb01d;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin\server

VM Arguments:
java_command: com.xamarin.manifestmerger.Main obj\Debug\net7.0-android\android\manifestmerger.rsp
java_class_path (initial): C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.26\tools\manifestmerger.jar
Launcher Type: SUN_STANDARD

[Global flags]
     intx CICompilerCount                          = 4                                         {product} {ergonomic}
     uint ConcGCThreads                            = 2                                         {product} {ergonomic}
     uint G1ConcRefinementThreads                  = 8                                         {product} {ergonomic}
   size_t G1HeapRegionSize                         = 1048576                                   {product} {ergonomic}
    uintx GCDrainStackTargetSize                   = 64                                        {product} {ergonomic}
   size_t InitialHeapSize                          = 266338304                                 {product} {ergonomic}
   size_t MarkStackSize                            = 4194304                                   {product} {ergonomic}
   size_t MaxHeapSize                              = 4238344192                                {product} {ergonomic}
   size_t MinHeapDeltaBytes                        = 1048576                                   {product} {ergonomic}
    uintx NonNMethodCodeHeapSize                   = 5836300                                {pd product} {ergonomic}
    uintx NonProfiledCodeHeapSize                  = 122910970                              {pd product} {ergonomic}
    uintx ProfiledCodeHeapSize                     = 122910970                              {pd product} {ergonomic}
    uintx ReservedCodeCacheSize                    = 251658240                              {pd product} {ergonomic}
     bool SegmentedCodeCache                       = true                                      {product} {ergonomic}
     bool UseCompressedClassPointers               = true                                 {lp64_product} {ergonomic}
     bool UseCompressedOops                        = true                                 {lp64_product} {ergonomic}
     bool UseG1GC                                  = true                                      {product} {ergonomic}
     bool UseLargePagesIndividualAllocation        = false                                  {pd product} {ergonomic}

Logging:
Log output configuration:
 #0: stdout all=warning uptime,level,tags
 #1: stderr all=off uptime,level,tags

Environment Variables:
JAVA_HOME=C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot
PATH=C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Microsoft SQL Server\160\Tools\Binn\;C:\Program Files\Microsoft SQL Server\160\Tools\Binn\;C:\Program Files\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\dotnet\;C:\Users\Arthur\AppData\Local\Microsoft\WindowsApps;C:\Users\Arthur\.dotnet\tools;C:\Users\Arthur\AppData\Roaming\npm;C:\Program Files\Azure Data Studio\bin;C:\Users\Arthur\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Arthur\AppData\Local\GitHubDesktop\bin;C:\Program Files (x86)\Rico Suter\NSwagStudio\;C:\Users\Arthur\AppData\Local\Programs\Fiddler;C:\Users\Arthur\AppData\Local\Programs\Azure Data Studio\bin;C:\Users\Arthur\.dotnet\tools
USERNAME=Arthur
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
TMP=C:\Users\Arthur\AppData\Local\Temp
TEMP=C:\Users\Arthur\AppData\Local\Temp



---------------  S Y S T E M  ---------------

OS: Windows 11 , 64 bit Build 22621 (10.0.22621.1485)
OS uptime: 0 days 3:02 hours
Hyper-V role detected

CPU:total 8 (initial active 8) (8 cores per cpu, 1 threads per core) family 6 model 158 stepping 13 microcode 0xde, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, 3dnowpref, lzcnt, tsc, tscinvbit, bmi1, bmi2, adx, fma

Memory: 4k page, system-wide physical 16165M (3479M free)
TotalPageFile size 16165M (AvailPageFile size 100M)
current process WorkingSet (physical memory assigned to process): 10M, peak: 10M
current process commit charge ("private bytes"): 60M, peak: 314M

vm_info: OpenJDK 64-Bit Server VM (11.0.16.1+1-LTS) for windows-amd64 JRE (11.0.16.1+1-LTS), built on Aug 20 2022 20:09:04 by "" with MS VC++ 15.9 (VS2017)

END.

当 Android 模拟器崩溃时,我有时会(并非总是)收到日志消息,我会在模拟器上收到此错误消息:

在此处输入图片描述

Chrome 也经常会因为内存不足而停止播放 YouTube 上的某些内容。

如果这确实是问题所在,我可以更新到 32GB,但我觉得这很奇怪,因为我在 16GB 内存上长时间承受着这种负载。我也有这种环境,有时我会在 16GB 的 MacBook Pro 上运行 Parallels,也从未遇到过这种问题。在我的 MacBook 上,我有相同甚至更多的开发工具,从未遇到过这种错误。

考虑到错误消息,这可能听起来很愚蠢,但可能是某些 Java 设置?我觉得自从我为这台机器添加了 HDD 作为辅助存储后,问题就开始了。

这是任务管理器内存选项卡上的屏幕截图。在屏幕截图中,我正在运行 Visual Studio,使用 Android Emulator 进行调试,Chrome、Postman 和在后台运行的 SQL Server:

在此处输入图片描述

答案1

查看任务管理器屏幕截图,我认为您已禁用交换/页面文件。它仅显示 16GB 的物理内存,没有任何额外虚拟内存(页面文件)的迹象。

我可以通过底部“已提交”下的数字判断出情况确实如此,其中显示已提交 13.7GB,总内存为 15.8GB。15.8 是系统中的最大虚拟内存量,是物理 RAM 和页面文件提供的后备存储的总和。

通常,该数字应该略大于您的物理 RAM,因为应该始终为页面文件或内存映射文件分配一定大小。在现代系统中,即使有大量物理 RAM,我也会惊讶地发现它小于 1GB。它实际上小于 16GB 表明没有页面文件,并且您实际上已经将一些 RAM 丢失到用于与系统中的设备通信的缓冲区(它是物理 RAM 减去“硬件保留”数字)。

您应该启用页面文件。一旦您这样做,一切都应该正常运行。

Windows 不喜欢耗尽虚拟内存,因为它允许(并完全提交)内存分配,而不像 Linux 和 BSD 风格的操作系统那样允许内存过度提交,而不需要由实际内存或存储支持分配。

Linux 允许内存过量使用,并希望进程不会使用它,并在需要时终止它们,而 Windows 在虚拟内存耗尽时只会拒绝原始请求。结果是 Windows 绝对需要一个交换文件来保证内存分配,即使它们未被使用。

相关内容