Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Perl "Out of memory!" Error signal backtrace

by OnEhIppY (Initiate)
on Nov 13, 2021 at 05:15 UTC ( [id://11138768]=perlquestion: print w/replies, xml ) Need Help??

OnEhIppY has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to get a Signal call for the Out of memory! call within a perl script?

Somewhere deep within the thread it gives me that message, yet there seems no way to catch that call, to do a traceback to the whole call structure, to see where things go wrong, like the warn and die have a signal, yet these are not triggered by this particular one.

There are some kill signals about memory, but these seem neither to be triggered.

Anyone an idea how to trace the code point?
  • Comment on Perl "Out of memory!" Error signal backtrace

Replies are listed 'Best First'.
Re: Perl "Out of memory!" Error signal backtrace
by dave_the_m (Monsignor) on Nov 13, 2021 at 08:58 UTC
    The problem is that once the perl interpreter has exhausted all memory, there's very little it can do. There is a reserved fixed buffer to allow it to display the the OOM error itself, but doing anything complex like displaying a Carp::confess()-like stack backtrace would require many memory allocations to generate the display, all of which would themselves fail.

    Dave.

Re: Perl "Out of memory!" Error signal backtrace
by eyepopslikeamosquito (Archbishop) on Nov 13, 2021 at 08:38 UTC
      Just noticed this today, but Test::Valgrind is available as a package in Ubuntu (libtest-valgrind-perl). Valgrind is mentioned in the target page link by eyepopslikeamosquito, but I am pointing out it may offer an expedient way to research the issue on your system.
Re: Perl "Out of memory!" Error signal backtrace (updated)
by LanX (Saint) on Nov 13, 2021 at 05:37 UTC
    I'd say you need to track the growth of your memory consumption. Not sure what the codepoint can tell you.

    You probably have a memory leak due to recursive data structures.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    update

    according to splain -v it's non-trappable

    DESCRIPTION OF DIAGNOSTICS These messages are classified as follows (listed in increasing ord +er of desperation): (W) A warning (optional). (D) A deprecation (enabled by default). (S) A severe warning (enabled by default). (F) A fatal error (trappable). (P) An internal error you should never see (trappable). =====> (X) A very fatal error (nontrappable). (A) An alien error message (not generated by Perl). ... Trappable errors may be trapped using the eval operator. See "eval" in perlfunc. In almost all cases, warnings may be selectiv +ely disabled or promoted to fatal errors using the warnings pragma. See warnings. Out of memory! (#1) (X) The malloc() function returned 0, indicating there was insuffi +cient remaining memory (or virtual memory) to satisfy the request. Perl + has no option but to exit immediately. At least in Unix you may be able to get past this by increasing yo +ur process datasize limits: in csh/tcsh use limit and limit datasize n (where n is the number of kilobytes) to check the current limits and change them, and in ksh/bash/zsh use ulimit + -a and ulimit -d n, respectively.

    Well ...

    ... probably the trace options of the debugger can help?

    If you log them to a file, you should see where they stop.

Re: Perl "Out of memory!" Error signal backtrace
by perlfan (Vicar) on Nov 13, 2021 at 16:54 UTC
    > Somewhere deep within the thread

    If you reproduce it, post the code here. I am guessing you're making some wrong assumption about threads and how they work in perl; without knowing what you're doing, I can blindly suggest: 1) get it working serially, and 2) if you need to workshare, use fork or better, Parallel::ForkManager. Also, if you're reading in a entire 1 TB file or grabbing a billion rows from mysqld, then there are better ways to do it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11138768]
Approved by LanX
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found