So are you saying that this "pure" code is still re-read from disk, or can it be sometimes available for use directly from a previously loaded "pure" copy in RAM? I. e., is a RAM copy ever available for re-use after a program has finished, or is it always re-loaded from disk (whether from swap or from the file copy itself)? As I had mentioned before, the text section of a program contains the instructions (and some initialized read-only data, such as strings). When a
On Friday 29 July 2005 10:05 am, Greg Wallace wrote:
program is loaded, the text section is mapped into virtual memory from the
place where it resides (eg. /usr/bin). For instance, if you run multiple
instances of a program at the same time, only 1 physical copy of the text
section will reside in physical RAM, and will not ever be swapped out to
backing store (eg. swap space).
Additionally, data is mapped in read-only using a technique called
copy-on-write which means that when written to, the page is then marked as
dirty, and will be paged out to the swap area if necessary. The third
section of a program is uninitialized data. Pages are not allocated for
uninitialized data until the program uses them. At that time, generally the
using page is zeroed and allocated to the program, and marked dirty.
Additionally, libraries used in Linux are called shared objects (.so).
So, in addition to multiple instances of the same program sharing the text
section, all code in a Linux and Unix system using shared libraries will
share the same physical libraries in memory.
Also, note that Randall mentioned that the linker must properly align the
sections. The initial alignment of the sections is performed first by the
compiler. There is usually a "calling standard" that defines some of these
things. It is the calling standards that allow C, C++, Fortan, and other
languages to call eachother and to call functions in the libraries.
--
Jerry Feldman