Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Perl garbage collector and swap

by zby (Vicar)
on Mar 17, 2004 at 15:42 UTC ( [id://337359]=perlquestion: print w/replies, xml ) Need Help??

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

From a slashdot comment:
2. The garbage collector does _not_ play well with the swap file. It causes each page belonging to the Java heap to be regularly paged in. Often. Several times per garbage collection pass, in fact.

So whereas a system which stuck to C or C++ will still run at full speed when I load 550 MB of programs in a 512 MB of RAM, a 100% Java system would trash to death at that point. (In fact, see point 2: much sooner than that.)

Does the Perl garbage collector work better? Or is it unevitable for a language with garbage collection?

Replies are listed 'Best First'.
Re: Perl garbage collector and swap
by Abigail-II (Bishop) on Mar 17, 2004 at 16:16 UTC
    It depends. Perl will 'free' values when there are no more references to them. That means Perl has to access to those values, possible 'free' associated structures, and even cascading the 'freeing' of variables. This could mean accessing recently accessed memory (for instance, a lexical variable in a small loop), which might be found in cache. It could also mean accessing 'old' values (for instances, modifying a long living object), which means Perl might have to access whatever is swapped out.

    I expect this to be the case in almost any language that does garbabe collection. If you collect your garbage at one moment, and you have swapped, the act of collecting the garbage will cause a swap.

    What's the lesson to be learned here? Don't swap. Invest in more memory.

    Abigail

Re: Perl garbage collector and swap (5 vs 6)
by tye (Sage) on Mar 17, 2004 at 18:49 UTC

    Perl 5 doesn't have a traditional garbage collector. It uses reference counting and so doesn't need to visit every single item periodically as part of checking if it is still being referenced.

    Perl 6 will suffer from this problem but Perl 5 doesn't.

    - tye        

      This might strike quite painfully in web server programming where you need to run mass quantities of web servers. So this seems to be the first real argument against Perl 6. I hope a better threading could be used that to reduce the impact of this problem.

      By the way I guess it's a Parrot thing. So all other languages run on Parrot will suffer as well?

        Yes, it's a Parrot thing.

        It's possible that something like a generational GC can "cycle" slowly enough that the pages to be swapped in can be controlled and even anticipated. Also, a compacting GC will potentially run in a smaller footprint than Perl 5. (Though I think it was decided recently that a compacting GC was incompatible with threading in Parrot, if I recall.)

        But I agree with Abigail. If you're running a server, real memory almost always outperforms virtual memory. And with 64-bit computing coming online, there's really no limit to the amount of memory you can add now, apart from arbitrary limitations of particular hardware architectures that chintz out on giving you all your address lines...

        By the way I guess it's a Parrot thing. So all other languages run on Parrot will suffer as well?
        No, it's not a parrot thing, and tye's wrong on this. A sweep for dead objects only touches the object header arenas and those areas of the heap that belong to active objects and can contain pointers to other object headers. Those memory areas are generally segregated from the areas of the heap that contain non-pointer data such as strings.
Re: Perl garbage collector and swap
by iburrell (Chaplain) on Mar 17, 2004 at 19:13 UTC
    Perl doesn't really have a garbage collector. It uses reference counting and frees memory when nothing has a reference to it. This does work better with swap because there is no process that scans all the memory looking for unused memory to free.

    Perl does not return memory to the OS once it has been freed. It does do a good job of reusing memory, so it is possible to have pages swapped out with only free space or unused data.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found