On Sat, Jan 24, 2004 at 14:11:14 +0000, shyam jith wrote: > >>>Let's say you've got a process like inetd that forks off several copies > >>>of the same program, each of which forks several copies of some other > >>program, as follows:>>>> > Inted -> Program X -> Program Y > -> Program Y > -> Program X -> Program Y > -> Program Y > -> Program X -> Program Y > -> Program X -> Program Y > /* > So at any one time the system process table will show four instances of > Program X and eight instances of Program Y. Let's say this is on a > Redhat AS 2.1 system running kernel 2.4.9-e.3. > > What's the total system RAM consumed by these programs? Is it simply the > sum of the amount of RAM required by Program X and Program Y multiplied > by four and eight respectively? Or is there something more complicated > in the way the Linux kernel manages memory? > > The practical reason for the question is to determine the maximum number > of Program X that we can allow (based on the amount of free system RAM) > in order to prevent the system from swapping to disk when too many > Program Xs are running. Generaly, there are too many factors affecting memory performance. The best way to determine the number is probably to put a test load on the system and slowly increase the number of processes allowed until CPU time spent in user mode starts to drop and there cut it off. To get some qualified guess: - Binary files and shared libraries are loaded only once no matter how many processes use them. Moreover, they are never copied to swap -- instead, they are discarded and reloaded from the binary when needed. - The same is true for files mapped by processes using the mmap call. - Process data are private to each process. But after fork, they are not copied until they are modified. AFAIK there is no way to count pages shared in this way. - Files accessed by read/write will be cached. - Linux does not make any differnce between pages with different origin and different use. If it's accessed often, it will be in memory, no matter if it's a code, data or a cached file. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/