Copy-on-Write memory management

  • Follow


Let's say I wanted to implement a memory management system where I can
allocate a block of memory, write some data to it, and then clone it
in such a way that two separate pieces of code could own a copy of the
data, write to their copy, and when they read from their copy, they
saw their own written data there.

Now let's say that I want the clone operation to not result in an
increase in my footprint in the system memory until it was necessary
to write to the copy of the data.

Which operating systems, runtimes, libraries, architectures or
patterns have facilities which make this less difficult than it would
be without the facilities they provide?

(It's related to a performance-robustness balance problem I
occasionally encounter at work, but I'm mostly interested out of
personal curiosity; If my question seems ambiguous, it's because I'm
not looking for knowledge, not an exact solution.)
0
Reply mikemol (370) 4/25/2009 10:26:44 PM

On Apr 26, 12:26=A0am, Michael  Mol <mike...@gmail.com> wrote:
> Let's say I wanted to implement a memory management system where I can
> allocate a block of memory, write some data to it, and then clone it
> in such a way that two separate pieces of code could own a copy of the
> data, write to their copy, and when they read from their copy, they
> saw their own written data there.
>
> Now let's say that I want the clone operation to not result in an
> increase in my footprint in the system memory until it was necessary
> to write to the copy of the data.
>
> Which operating systems, runtimes, libraries, architectures or
> patterns have facilities which make this less difficult than it would
> be without the facilities they provide?
>
> (It's related to a performance-robustness balance problem I
> occasionally encounter at work, but I'm mostly interested out of
> personal curiosity; If my question seems ambiguous, it's because I'm
> not looking for knowledge, not an exact solution.)

http://en.wikipedia.org/wiki/Copy_on_write
0
Reply andrew3888 (270) 4/25/2009 10:48:07 PM


On Apr 25, 6:48=A0pm, Andrew Tomazos <and...@tomazos.com> wrote:
> On Apr 26, 12:26=A0am, Michael =A0Mol <mike...@gmail.com> wrote:
>
>
>
> > Let's say I wanted to implement a memory management system where I can
> > allocate a block of memory, write some data to it, and then clone it
> > in such a way that two separate pieces of code could own a copy of the
> > data, write to their copy, and when they read from their copy, they
> > saw their own written data there.
>
> > Now let's say that I want the clone operation to not result in an
> > increase in my footprint in the system memory until it was necessary
> > to write to the copy of the data.
>
> > Which operating systems, runtimes, libraries, architectures or
> > patterns have facilities which make this less difficult than it would
> > be without the facilities they provide?
>
> > (It's related to a performance-robustness balance problem I
> > occasionally encounter at work, but I'm mostly interested out of
> > personal curiosity; If my question seems ambiguous, it's because I'm
> > not looking for knowledge, not an exact solution.)
>
> http://en.wikipedia.org/wiki/Copy_on_write

Because Wikipedia takes pains to avoid being too technical, its
notability policies and its tendency to flag non-statistically-
aggregated experience as "original research", it doesn't and won't
have much information on the subject (I checked), and certainly isn't
the place for active discussion. (And this isn't the place to debate
Wikipedia's policies, either; I'm just explaining why they don't have
the information I'm looking for, at the risk of goig offtopic.)
0
Reply mikemol (370) 4/25/2009 11:04:23 PM

On Apr 26, 1:04=A0am, Michael  Mol <mike...@gmail.com> wrote:
> On Apr 25, 6:48=A0pm, Andrew Tomazos <and...@tomazos.com> wrote:
>
>
>
> > On Apr 26, 12:26=A0am, Michael =A0Mol <mike...@gmail.com> wrote:
>
> > > Let's say I wanted to implement a memory management system where I ca=
n
> > > allocate a block of memory, write some data to it, and then clone it
> > > in such a way that two separate pieces of code could own a copy of th=
e
> > > data, write to their copy, and when they read from their copy, they
> > > saw their own written data there.
>
> > > Now let's say that I want the clone operation to not result in an
> > > increase in my footprint in the system memory until it was necessary
> > > to write to the copy of the data.
>
> > > Which operating systems, runtimes, libraries, architectures or
> > > patterns have facilities which make this less difficult than it would
> > > be without the facilities they provide?
>
> > > (It's related to a performance-robustness balance problem I
> > > occasionally encounter at work, but I'm mostly interested out of
> > > personal curiosity; If my question seems ambiguous, it's because I'm
> > > not looking for knowledge, not an exact solution.)
>
> >http://en.wikipedia.org/wiki/Copy_on_write
>
> Because Wikipedia takes pains to avoid being too technical, its
> notability policies and its tendency to flag non-statistically-
> aggregated experience as "original research", it doesn't and won't
> have much information on the subject (I checked), and certainly isn't
> the place for active discussion. (And this isn't the place to debate
> Wikipedia's policies, either; I'm just explaining why they don't have
> the information I'm looking for, at the risk of goig offtopic.)

It wasn't my intention to suggest that your post was in any way
inappropriate.  I was just adding a relevant link to the thread.
   -Andrew.
0
Reply andrew3888 (270) 4/26/2009 1:43:29 AM

Michael Mol wrote:
> 
> Let's say I wanted to implement a memory management system where
> I can allocate a block of memory, write some data to it, and then
> clone it in such a way that two separate pieces of code could own
> a copy of the data, write to their copy, and when they read from
> their copy, they saw their own written data there.
> 
> Now let's say that I want the clone operation to not result in an
> increase in my footprint in the system memory until it was
> necessary to write to the copy of the data.

This is routinely implemented in various operating systems.  Look
for "copy on write".

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>
            Try the download section.


0
Reply cbfalconer (19183) 4/26/2009 2:50:26 AM

On Apr 25, 9:43=A0pm, Andrew Tomazos <and...@tomazos.com> wrote:
> On Apr 26, 1:04=A0am, Michael =A0Mol <mike...@gmail.com> wrote:
>
>
>
> > On Apr 25, 6:48=A0pm, Andrew Tomazos <and...@tomazos.com> wrote:
>
> > > On Apr 26, 12:26=A0am, Michael =A0Mol <mike...@gmail.com> wrote:
>
> > > > Let's say I wanted to implement a memory management system where I =
can
> > > > allocate a block of memory, write some data to it, and then clone i=
t
> > > > in such a way that two separate pieces of code could own a copy of =
the
> > > > data, write to their copy, and when they read from their copy, they
> > > > saw their own written data there.
>
> > > > Now let's say that I want the clone operation to not result in an
> > > > increase in my footprint in the system memory until it was necessar=
y
> > > > to write to the copy of the data.
>
> > > > Which operating systems, runtimes, libraries, architectures or
> > > > patterns have facilities which make this less difficult than it wou=
ld
> > > > be without the facilities they provide?
>
> > > > (It's related to a performance-robustness balance problem I
> > > > occasionally encounter at work, but I'm mostly interested out of
> > > > personal curiosity; If my question seems ambiguous, it's because I'=
m
> > > > not looking for knowledge, not an exact solution.)
>
> > >http://en.wikipedia.org/wiki/Copy_on_write
>
> > Because Wikipedia takes pains to avoid being too technical, its
> > notability policies and its tendency to flag non-statistically-
> > aggregated experience as "original research", it doesn't and won't
> > have much information on the subject (I checked), and certainly isn't
> > the place for active discussion. (And this isn't the place to debate
> > Wikipedia's policies, either; I'm just explaining why they don't have
> > the information I'm looking for, at the risk of goig offtopic.)
>
> It wasn't my intention to suggest that your post was in any way
> inappropriate. =A0I was just adding a relevant link to the thread.
> =A0 =A0-Andrew.

My apologies.  I'm used to getting RTFM responses when I've either
already RTFM'd or when TFM is incomplete.  I shouldn't have been so
touchy.

Mike Mol.
0
Reply mikemol (370) 4/26/2009 3:50:46 AM

"CBFalconer" <cbfalconer@yahoo.com> wrote in message 
news:49F3CBF2.CD87DED8@yahoo.com...
> Michael Mol wrote:
>>
>> Let's say I wanted to implement a memory management system where
>> I can allocate a block of memory, write some data to it, and then
>> clone it in such a way that two separate pieces of code could own
>> a copy of the data, write to their copy, and when they read from
>> their copy, they saw their own written data there.
>>
>> Now let's say that I want the clone operation to not result in an
>> increase in my footprint in the system memory until it was
>> necessary to write to the copy of the data.
>
> This is routinely implemented in various operating systems.  Look
> for "copy on write".
>

yes, examples being Windows and Linux...

of course, to use it typically requires creating multiple processes (AFAIK, 
there is no real way to use it explicitly, rather one gets it as a result of 
doing a "fork()" or similar...).


> -- 
> [mail]: Chuck F (cbfalconer at maineline dot net)
> [page]: <http://cbfalconer.home.att.net>
>            Try the download section.
>
> 


0
Reply cr88192355 (1754) 4/27/2009 4:03:58 PM

On Apr 27, 9:03 pm, "cr88192" <cr88...@hotmail.com> wrote:
> "CBFalconer" <cbfalco...@yahoo.com> wrote in message
>
> news:49F3CBF2.CD87DED8@yahoo.com...
>
> > Michael Mol wrote:
>
> >> Let's say I wanted to implement a memory management system where
> >> I can allocate a block of memory, write some data to it, and then
> >> clone it in such a way that two separate pieces of code could own
> >> a copy of the data, write to their copy, and when they read from
> >> their copy, they saw their own written data there.
>
> >> Now let's say that I want the clone operation to not result in an
> >> increase in my footprint in the system memory until it was
> >> necessary to write to the copy of the data.
>
> > This is routinely implemented in various operating systems.  Look
> > for "copy on write".
>
> yes, examples being Windows and Linux...
>
> of course, to use it typically requires creating multiple processes (AFAIK,
> there is no real way to use it explicitly, rather one gets it as a result of
> doing a "fork()" or similar...).
>
> > --
> > [mail]: Chuck F (cbfalconer at maineline dot net)
> > [page]: <http://cbfalconer.home.att.net>
> >            Try the download section.

I would like to have a try at it.
See whenever an area of memory is to be cloned between two processes
( as linux does when a child process is forked )
that area ( specifically the page that contains that area  ) is
declared read only( by setting a bit in the page table entry) by the
operating system and whenever one tries to write to it , this causes a
hardware exception (specifically memory protection violation processor
exception) which returns control to the OS which then creates two
separate copies of the cloned page.

I don't think whether runtime libraries have to play ant role in this!

Mohan
0
Reply mohangupta13 (109) 4/29/2009 6:57:22 PM

7 Replies
30 Views

(page loaded in 0.074 seconds)


Reply: