Hello RTLinux mail list member, The problem I am about to describe does not apply directly to rtlinux, but it affects the performance of rtlinux indirectly. I have found when I write() to a device, be it disk or a network socket, memory is rapidly gobbled up until the amount of free memory comes within a couple of MB of the total physical RAM, no matter what the size of that RAM is. At that point there is a small amount of disk swapping (~ 0.5 MB) and then things stabilize with the system being almost out of free memory. When the program causing this exits, the memory is not released! Subsequently, running another program does NOT cause memory swapping instantly as you might expect since there is almost no free memory available. So in that sense this problem is benign. However, in a real time environment I want no swapping whatsoever to occur. I equipped the machine with much more memory than would ever be needed, yet here it is swapping (if only a little bit). This has serious consequences for my real time data acquisition program. I have attached an almost trivial C routine that illustrates the problem. I would appreciate if some of you would run this on your machines and report back if it works the way I have just described. I am monitoring memory usage using top. I get the same results under Linux 2.0.36 and the newer 2.2.?. I should also ask if someone can describe the difference between cache memory and buffered memory as reported by top? I'm pretty sure that what is happening is that the system is caching up the data just written (or should I say buffering?) up to nearly the point where it runs out of physical memory. Apparently it miscalculates something and has to do a little swapping to keep things going. The reason I asked about the difference between cache and buffered memory is that under the 2.2.? kernel the "buff" number is quite high, approaching the physical RAM size while the cached memory number is only a few MB. The exact opposite condition occurs under the 2.0.36 kernel. Thanks in advance, Bruce Gotwols --- Bruce L. Gotwols Johns Hopkins University, Applied Physics Lab., Laurel MD 20723 Internet: [EMAIL PROTECTED] Am. Radio: KA3WTM Phone: 240-228-4543 FAX: 240-228-5548 Space Oceanography Group Home Page -- http://fermi.jhuapl.edu
// twrite.c Test write() B. L. Gotwols 4-oct-1999 // This program illustrates a problem with linux where simply writing // to a disk file causes memory to be gradually used up. When memory usage // approaches withn a few MB of the size of physical memory the growth stops. // However there is an associated usage of a few hndred kB of swap space. // According to top, when the program terminates the memory is not released. // Usage: twrite // To compile and link: gcc -O twrite.c -o twrite // Will create file tmp.tmp in the directory where your are sitting. #include <stdio.h> #include <unistd.h> #include <fcntl.h> #define NBYTES 1024*1024*100 // File size (100 MB) #define N2WRITE 1024*50 // Size of output buffer (50 kB) int main() { int fd; int nbytes_out=0; int nwritten; unsigned char buf[N2WRITE]; if((fd = open("tmp.tmp", O_RDWR | O_CREAT | O_TRUNC, 0664)) <0) { printf("Output file = %s failed to open\n", "d.d"); exit(1); } while(nbytes_out < NBYTES) { nwritten = write(fd, buf, N2WRITE); if(nwritten != N2WRITE) { printf("Failed to write to file = %s\n","tmp.tmp"); printf("N2WRITE = %d, nwritten = %d nbytes_out =%d\n", N2WRITE,nwritten,nbytes_out); exit(1); } nbytes_out += nwritten; } close(fd); return 0; }