Date: Thu, 19 Aug 2004 20:25:39 -0700 From: "Gustavo A. Baratto" <gbaratto@superb.net> To: Doug White <dwhite@gumbysoft.com> Cc: freebsd-current@freebsd.org Subject: Re: memory question Message-ID: <099201c48665$5da6ae00$6400a8c0@chivas> References: <087b01c48635$d3ebc850$6400a8c0@chivas> <20040819191709.Q66276@carver.gumbysoft.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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@gumbysoft.com> To: "Gustavo A. Baratto" <gbaratto@superb.net> Cc: <freebsd-current@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@gumbysoft.com | www.FreeBSD.org > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?099201c48665$5da6ae00$6400a8c0>