http://qs321.pair.com?node_id=11138768

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?

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

    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.