On Fri, Apr 25, 2008 at 6:51 PM, Erik Mouw <[EMAIL PROTECTED]> wrote:
> On Fri, Apr 25, 2008 at 03:01:23PM +0530, sahlot arvind wrote:
> > >Now a new process is loaded to memory, which utilizes a .so already in
> > memory. How does ld.so know if the required .so is already in >memory
> and
> > what is its physical address?
> >
> > I think loader keeps track of which libraries are there in the memory
> and
> > their location. Execuatble file of the program contains dependency
> > information i.e. which libraries this exe depends upon. So while loading
> it
> > can check whether the required library is always there or not if not
> then
> > loader loads the lib into the memory.
>
> No, the loader doesn't need to know anything. It just maps the
> libraries the process needs into its address space. Because linux uses
> on-demand paging, nothing will happen at that point. Only when the
> process starts to access pages from the library the kernel will load
> those pages from disk. If the kernel figures out that particular page
> from that particular library was already mapped in another process, it
> will just create a map for that page into the current process and
> presto: shared mapping of a library.
>
> BTW this is not library specific, it happens with any file that gets
> mapped by two (or more) processes. That includes the binaries
> themselves, but also mmap()ed files.
>
Hi,
Thanks for explanation.
How does the kernel figure out that a particular file/library is already
opened and mmaped to a particular address ? Does it scan through the list of
open files or is there any information kept in the inode for the file or is
there some other way ?
TIA.
Best regards,
Pranav