Perl code compiles to an opcode tree. I'm curious if Perl manages to leave large chunks of this tree as read-only so that related processes can continue to share that memory.

My knowledge of *nix kernel memory management is stale at this point, so take this with a grain of salt.

It used to be the case that the read-only pages were so marked in the executable file. The executable also contained some number of writeable data pages, and info for creating a "blank static storage" section to house uninitialized structures. Additional storage (e.g., allocated by malloc()) grew upwards from writable storage via sbrk(), and the stack grew downwards from high memory.

Perl process build their opcode trees in writeable space. I'm not aware of a mechanism to mark writeable pages as read-only at runtime.

However, depending on how fork() is implemented, writeable pages from the parent process may shared with the child process using a "copy on write" scheme, in which pages are shared until one of the process tries writes into the page, at which point a copy is made for each process. Such a scheme would work well with Perl, allowing the opcode tree to be shared.

Now, will somebody please update me by telling me how this is wrong?


In reply to Re: (tye)Re: collective unconcious (about shared memory...) by dws
in thread collective unconcious (about shared memory...) by dshahin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.