Re: memory question

From: Gustavo A. Baratto <gbaratto_at_superb.net>
Date: Thu, 19 Aug 2004 20:25:39 -0700
> It would be rather lame if libraries were exclusive access. :)  There may
> be cases where they do get their own copies.  You shouldn't rely on this
> behavior for any sort of memory-use calculations...

Yes, I think it would be very lame too. But because of the fact you
mentioned about the possibility of one process scribbling on the library
pages, I was not sure the library would be shared between 2 processes in
memory.

Is there a rule of thumb for memory use calculations?

> I suspect the next question is going to be about sharing data between
> these processes :)

Nope, sharing data between two processes is quite clear for me that it
should not be allowed. That would seem very dangerous, as

BTW: is this the correct mailing list for such question?

thank you very much...



----- Original Message ----- 
From: "Doug White" <dwhite_at_gumbysoft.com>
To: "Gustavo A. Baratto" <gbaratto_at_superb.net>
Cc: <freebsd-current_at_freebsd.org>
Sent: Thursday, August 19, 2004 7:25 PM
Subject: Re: memory question


> On Thu, 19 Aug 2004, Gustavo A. Baratto wrote:
>
> > This is a bit off-topic, but I haven't found this information in the
freebsd
> > website nor google... and this seems to be the most programmer oriented
> > mailinglist
> >
> > If I have 2 or more different programs using the same shared library...
The
> > first program loads the .so at startup and keeps running. My question is
> > that when the second program starts, does it have to load the .so again,
or
> > the memory used by the shared library will be shared between all the two
> > programs?
>
> I'm probably off base here, and expect to get clubbed by a developer any
> second.
>
> Technically yes, but from a fairly basic level.  ld.so, the dynamic
> linker, mmap()s the library to "load" it.  As pages in the library are
> read, they are faulted into memory.  When another process mmap()s the same
> file, the Vm system notices the pages for the file are already in core and
> doesn't fault them back in again, assuming the programs access the same
> pages.  For the pruposes of resource utilization, though, both processes
> are charged for the size of the library.
>
> Note that ld.so maps in the pages read-only(*) so there is little danger
> from one process corrupting another by scribbling on the library pages.
> Files mmap()ed read-write are a whole different bag.
>
> (*) There's probably exceptions to this for stuff like static variables.
> Changing the file on disk will cause the changes to propagate to all the
> processes holding mmap()s over the file. This is usually fatal for shared
> libraries.
>
> > I know that different processes started by the same parent share the
.so,
> > but I wanna know if completely different programs started by different
> > parents can share the same shared object.
> >
> >  For example, if perl/DBI started from the shell, and php/mysql started
from
> > apache can share the same libmysqlclient.so in memory.
>
> It would be rather lame if libraries were exclusive access. :)  There may
> be cases where they do get their own copies.  You shouldn't rely on this
> behavior for any sort of memory-use calculations...
>
> I suspect the next question is going to be about sharing data between
> these processes :)
>
> -- 
> Doug White                    |  FreeBSD: The Power to Serve
> dwhite_at_gumbysoft.com          |  www.FreeBSD.org
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
>
Received on Fri Aug 20 2004 - 01:56:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:07 UTC