Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Fork and multiple subs

by Illuminatus (Curate)
on Feb 17, 2011 at 14:00 UTC ( [id://888719]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Fork and multiple subs
in thread Fork and multiple subs

fork doesn't copy anything
Even though I have been working with Linux exclusively for the last 3 years, I still 'default' to Solaris in my *nix response :(. Linux only initially copies the page tables (very small). Solaris, on the other hand, does copy all of the address space (unless you use vfork). In both environments, text (ie code) pages are read-only. I am 99% sure that in Solaris, text pages are only ever put into physical memory once (which includes the text portion of shared libs once they are loaded the first time), and referenced by all processes using them. For Linux, it would not matter in this case, since pages are copy-on-write, and text pages can never be written to (hence, they would never be copied).

fnord

Replies are listed 'Best First'.
Re^4: Fork and multiple subs
by Eliya (Vicar) on Feb 17, 2011 at 15:32 UTC

    I think your argumentation is overlooking the fact that Perl code doesn't equal compiled machine code.

    What the OS treats as text pages (code) is what is marked as such in the respective binary or shared library that's being loaded.  With respect to Perl, this applies only to the compiled machine code that makes up the interpreter itself, not the "byte code"-like instructions that Perl code is compiled into at runtime (i.e. after the Perl binary has been loaded/mapped).

    In other words, from the perspective of the OS, the compiled Perl opcodes are considered "data" (located on the heap) of the Perl executable. And you'd have to have rather good knowledge of the Perl internals to tell whether some bits in those data structures might possibly change (or not) as a result of running the code, which in turn would trigger copy-on-write...

Re^4: Fork and multiple subs
by ikegami (Patriarch) on Feb 17, 2011 at 21:31 UTC

    Linux only initially copies the page tables (very small). Solaris, on the other hand, does copy all of the address space (unless you use vfork).

    Thanks for the correction. I didn't know that some systems (i.e. Solaris) didn't use copy-on-write.

    In both environments, text (ie code) pages are read-only.

    And thus they can't possibly be used. Perl wouldn't be able to populate it if it started read-only. Additionally, it can't become read-only (if that's possible) because Perl can compile more code at any time (as mentioned earlier).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://888719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found