我在 AWS t2.micro 实例中运行下载服务器,并且我为 Java 进程配置了最大堆 512 MB 和最小堆 256 MB。我正在单线程中执行迁移类型的进程,从 Google Drive 下载文件(大小 < 50MB)。但是当我运行它时,我收到以下错误
error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 33558528 bytes for committing reserved memory.
以下是 hs_err_pid13942.log 的摘录
VM 参数:
jvm_args: -Xms256m -Xmx512m -XX:PermSize=32m -XX:MaxPermSize=64m -XX:+HeapDumpOnOutOfMemoryError
这是我的 meminfo
/proc/meminfo:
MemTotal: 1016324 kB
MemFree: 58792 kB
Buffers: 344 kB
Cached: 15984 kB
SwapCached: 0 kB
Active: 899232 kB
Inactive: 14664 kB
Active(anon): 897692 kB
Inactive(anon): 332 kB
Active(file): 1540 kB
Inactive(file): 14332 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 72 kB
Writeback: 0 kB
AnonPages: 897608 kB
Mapped: 6284 kB
Shmem: 416 kB
Slab: 22276 kB
SReclaimable: 10960 kB
SUnreclaim: 11316 kB
KernelStack: 1408 kB
PageTables: 7460 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 508160 kB
Committed_AS: 881084 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 4664 kB
VmallocChunk: 34359727628 kB
HardwareCorrupted: 0 kB
AnonHugePages: 591872 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 28672 kB
DirectMap2M: 1150976 kB
这是 CPU 信息
/proc/cpuinfo:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
stepping : 2
microcode : 0x25
cpu MHz : 2394.552
cache size : 30720 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm xsaveopt fsgsbase bmi1 avx2 smep bmi2 erms invpcid
bogomips : 4789.10
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
Memory: 4k page, physical 1016324k(58792k free), swap 0k(0k free)
我可以看到有 58 MB 可用空间,而且我在使用“free -h”命令监控实例时也看到足够的可用内存。所以我不明白为什么会出现这个错误。有人能向我解释一下原因吗?以及我在内存配置方面做错了什么?
答案1
看起来应用程序通过直接内存访问(本机内存分配(mmap))从堆中分配内存。
您可以使用选项 -XX:MaxDirectMemorySize=55m 运行该应用程序(Java 7&8 中的默认值为 0)。
答案2
Possible solutions:
Reduce memory load on the system
Increase physical memory or swap space
Check if swap backing store is full
Use 64 bit Java on a 64 bit OS
Decrease Java heap size (-Xmx/-Xms)
Decrease number of Java threads
Decrease Java thread stack sizes (-Xss)
Set larger code cache with -XX:ReservedCodeCacheSize=