Perl无法在具有32 GB RAM的Snow leopard Mac服务器上分配超过1.1 GB的空间

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!

ike*_*ami 6

您正在使用32位构建的Perl(如图所示perl -V:ptrsize),但您需要64位版本.我建议安装本地perl使用perlbrew.

这可以通过在安装Perl时传递-Duse64bitall来实现Configure.

这可以通过在安装Perl时传递--64all来实现perlbrew install.

(出于一些奇怪的原因,perl -V:use64bitall说这已经完成,但显然不是.)

  • 哼,我看到`use64bitall = define`,但你也应该在编译时选项下有'USE_64_BIT_ALL`.关于你的构建有些奇怪.我的建议是. (2认同)
  • @Virushunter配置确实非常奇怪.这可能是某种形式的跨平台构建:`-arch x86_64 -arch i386 -arch ppc`.无论如何,`intsize = 4,longsize = 4,ptrsize = 4`是一个特定的赠品,这是为32位系统编译的.这些是C类型的大小,而不是Perl数据结构,因此您不能超过4GB.(这仍然没有完全解释1,1GB截止) (2认同)