Perl在具有32 GB RAM的Snow Leopard Mac服务器上不能分配超过1.1 GB的内存 [英] Perl cannot allocate more than 1.1 GB on a Snow leopard Mac server with 32 GB RAM

查看:72
本文介绍了Perl在具有32 GB RAM的Snow Leopard Mac服务器上不能分配超过1.1 GB的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台具有32GB RAM的Mac服务器(雪豹).当我尝试在Perl(v 5.10.0)中分配超过1.1GB的RAM时,出现内存不足错误.这是我使用的脚本:

I have a Mac server (snow leopard) with 32GB RAM. When I try to allocate more than 1.1GB RAM in Perl (v 5.10.0) I get an out of memory error. Here is the script that I used:

#!/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";

这是我得到的输出:

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...

有任何想法为什么会发生这种情况?

Any ideas why this is happening?

UPDATE 13年11月14日下午4:42

UPDATE 4:42pm 11/14/13

根据肯特·弗雷德里克(Kent Fredric)(请参阅下面的2个帖子),这是我的限制.虚拟内存默认为无限制

As per Kent Fredric (see 2 posts below), here are my ulimits. Virtual memory defaults to unlimited


$ 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亿,但无济于事.

I tried setting virtual memory to 10 billion but to no avail.


$ 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!

推荐答案

我想我明白了.当文档中另有说明时,我无法接受Apple交付了32位Perl.来自"man perl":

I think I figured it out. I could not accept that Apple shipped a 32-bit Perl when their documentation says otherwise. From 'man perl':

64-BIT SUPPORT
Version 5.10.0 supports 64-bit execution (which is on by default).  Version 5.8.8
only supports 32-bit execution.

然后我想起了,我在Mac服务器上安装了Fink,它存在32位和64位问题,有点怪异.所以,我注释掉了

Then I remembered, I installed Fink on my Mac server and it being, er, finicky with 32 and 64 bit issues. So, I commented out

#test -r /sw/bin/init.sh && . /sw/bin/init.sh

来自我的.profile.现在,我至少可以在32 GB RAM服务器上分配14 GB RAM(是的!)

from my .profile. Now I can at least allocate 14 GB RAM (yeah!) on my 32 GB RAM server

$ perl -E 'my $x = "a" x 14000000000; print "ok\n"'
ok

我尝试了16GB,但是在我放弃之前它挂了5分钟.现在,一个介于32位和64位之间的perl -V之间的diff讲述了这个故事(但是为什么还是intsize=4?).

I tried 16GB but it hung for 5 minutes before I gave up. Now, a diff between perl -V for 32-bit and 64-bit tells the tale (but why still intsize=4?).

$ diff perlv.32 perlv.64
16c16
<     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
---
>     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
18c18
<     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
---
>     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
34,35c34,36
<                         PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_ITHREADS
<                         USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
---
>                         PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
>                         USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
>                         USE_PERLIO USE_REENTRANT_API

谢谢大家的帮助,

保罗

这篇关于Perl在具有32 GB RAM的Snow Leopard Mac服务器上不能分配超过1.1 GB的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆