pca*_*upo 4 perl out-of-memory
我有一台32GB内存的Mac服务器(雪豹).当我尝试在Perl(v 5.10.0)中分配超过1.1GB的RAM时,出现内存不足错误.这是我使用的脚本:
#!/usr/bin/env perl
# My snow leopard MAC server runs out of memory at >1.1 billion bytes. How
# can this be when I have 32 GB of memory installed? Allocating up to 4
# billion bytes works on a Dell Win7 12GB RAM machine.
# perl -v
# This is perl, v5.10.0 built for darwin-thread-multi-2level
# (with 2 registered patches, see perl -V for more detail)
use strict;
use warnings;
my $s;
print "Trying 1.1 GB...";
$s = "a" x 1100000000; # ok
print "OK\n\n";
print "Trying 1.2 GB...";
$s = '';
$s = "a" x 1200000000; # fails
print "..OK\n";
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
Trying 1.1 GB...OK
perl(96685) malloc: *** mmap(size=1200001024) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Out of memory!
Trying 1.2 GB...
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样?
13/14/13更新时间:下午4:42
根据Kent Fredric(见下面的2篇文章),这是我的ulimits.虚拟内存默认为无限制
$ ulimit -a | grep bytes data seg size (kbytes, -d) unlimited max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited pipe size (512 bytes, -p) 1 stack size (kbytes, -s) 8192 virtual memory (kbytes, -v) unlimited $ perl -E 'my $x = "a" x 1200000000; print "ok\n"' perl(23074) malloc: *** mmap(size=1200001024) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug Out of memory! $ perl -E 'my $x = "a" x 1100000000; print "ok\n"' ok
我尝试将虚拟内存设置为100亿但无济于事.
$ ulimit -v 10000000000 # 10 billion $ perl -E 'my $x = "a" x 1200000000; print "ok\n"' perl(24275) malloc: *** mmap(size=1200001024) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug Out of memory!
您正在使用32位构建的Perl(如图所示perl -V:ptrsize),但您需要64位版本.我建议安装本地perl使用perlbrew.
这可以通过在安装Perl时传递-Duse64bitall来实现Configure.
这可以通过在安装Perl时传递--64all来实现perlbrew install.
(出于一些奇怪的原因,perl -V:use64bitall说这已经完成,但显然不是.)
| 归档时间: |
|
| 查看次数: |
1878 次 |
| 最近记录: |