Unfreeable buffer/cache problem in 2.4.17-rc1 still there
Hello!
Below is simple test case which I think is related to "memory disappear" problem.
My real program is doing something like this:
// test.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
int fd;
int r;
char data[10] = "0123456789";
int i;
int end = 30;
for (i=0;i<end;i++) {
fd = open("testfile", O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT, 0644);
if (fd == -1) {
printf("unable to open\n");
return;
}
r = write(fd,data,sizeof data);
if (r == -1) {
printf("unable to write\n");
close(fd);
return;
}
close(fd);
sleep(1); }
}
// end test.c
Each time I run free; ./test; free I see evergrowing memory usage. I mean used memory + buffers. At some point system just starts swapping even if no other processes are running. Tested on 2.4.13 and 2.4.17-pre4aa1. I think something is wrong here because the very same test program does not show such behaviour on 2.2.19. It does not lose any single byte of memory. I've even tested this on freebsd-4.4 with the same result as on 2.2.19.
Example output on 2.4.17-pre4aa1:
bash-2.03$ free; ./test; free
total used free shared buffers cached Mem: 514528 212508 302020 0 7952 150664 -/+ buffers/cache: 53892 460636 Swap: 1028120 0 1028120 total used free shared buffers cached Mem: 514528 212616 301912 0 8000 150664
-/+ buffers/cache: 53952 460576
Swap: 1028120 0 1028120
bash-2.03$ free; ./test; free
total used free shared buffers cached Mem: 514528 212616 301912 0 8008 150664 -/+ buffers/cache: 53944 460584 Swap: 1028120 0 1028120 total used free shared buffers cached Mem: 514528 212700 301828 0 8056 150664
-/+ buffers/cache: 53980 460548
Swap: 1028120 0 1028120
The results are very consistent. I lose 30-40 byte per run.
Signature · 1 line
DV
Quoted 35 lines · Dmitry Volkoff
Hello!
Below is simple test case which I think is related to "memory disappear" problem.
My real program is doing something like this:
//
test.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>int main(void)
{
int fd;
int r;
char data[10] = "0123456789";
int i;
int end = 30;for (i=0;i<end;i++) { fd = open("testfile", O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT, 0644); if (fd == -1) { printf("unable to open\n"); return; } r = write(fd,data,sizeof data); if (r == -1) { printf("unable to write\n"); close(fd); return; } close(fd); sleep(1);
Quoted 3 lines
}
}
// endtest.c
I removed sleep(1). Is it needed?
After 10000+ runs of this proggy swap usage isn't changed on 2.4.17-pre7. top reports constant 2304K of swap usage.
--
vda
Quoted 11 lines · vda
Quoted 10 lines
if (r == -1) { printf("unable to write\n"); close(fd); return; } close(fd); sleep(1);}
}
// endtest.c
Quoted 2 lines
I removed sleep(1). Is it needed?
Yes, you need it in order to see the memory leakage.
Quoted 2 lines
After 10000+ runs of this proggy swap usage isn't changed on 2.4.17-pre7. top reports constant 2304K of swap usage.
I know. You'll notice this effect only after 1000000+ runs. Try it again with sleep(1).
Quoted 3 lines
--
vda
Signature · 1 line
DV