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

Is it possible to use IPC COW with Perl?

by glasswalk3r (Friar)
on May 22, 2011 at 16:15 UTC ( [id://906180]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings monks,

Is it possible to create programs that use IPC to communicate and use the COW (copy on write) functionality on Linux OS?

I'm asking that because I've doing some tests and I could not get an situation that my forked child did not copy all variables from parent process.

I checked this situation by running htop program and seeing that the child process have the same amount of memory than the parent process. For what I have read about COW, the child process will copy its parent process variables in its own address space only if it tries to change those variables. My conclusion is, COW should help to reduce memory consumption but I never could checked that.

Given this little introduction, how can I:

  1. Check if COW is being used (or not) in a Linux box: there is any OS or Perl resource to check that?
  2. In practical terms, is it possible to avoid COW in Perl?

Thank you,

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Replies are listed 'Best First'.
Re: Is it possible to use IPC COW with Perl?
by Khen1950fx (Canon) on May 22, 2011 at 19:49 UTC
Re: Is it possible to use IPC COW with Perl?
by John M. Dlugosz (Monsignor) on May 22, 2011 at 19:47 UTC
    In a thread from a couple days ago, it was noted that the normal exit of perl will cause everything to be copied since it cleans up and frees data structures!

    If you are looking at running programs, you might not be able to tell how much memory is allocated from private (unique) memory. I looked into that to see what my web app was doing, and the replies indicated that in general you might not know if/when pages are shared at all. I only noted that the total memory used by all the processes was larger than my actual memory, so that's a good sign.

    Also, there may be a minimal allocation size involved. So try allocating a large amount of stuff, then make many forks and see how the memory load on the machine fares. Be sure the stage the terminations or kill them, or you'll run out during exit!

    I was also told to consider "Kernal SamePage Merging" which is available in Linux now.

Re: Is it possible to use IPC COW with Perl?
by sundialsvc4 (Abbot) on May 23, 2011 at 12:17 UTC

    There are a couple of considerations which could throw off your measurements.   One is, “exactly how is the figure of ‘amount of memory used by process X’ calculated?”   The other is, the copy-on-write functionality (like everything else in the virtual memory subsystem...) happens in terms of pages, and will respond to any change to that page, whether that change is considered by you to be “inconsequential” or not.

    COW does work in terms of memory pages.   The page-tables of the child process are set to point to the pages of the parent, but they are flagged to cause a page-fault if the page is subsequently “touched.” When that kind of page-fault occurs, the page is copied.   That is a very coarse level of granularity:   the size of a page.

    COW is a common feature of operating systems these days.   You should be able to assume that it is being used, and that it cannot be turned-off.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-24 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found