RE: PROBLEM:: irreversible Memory growth of process in mmap()-munmap() calls

From: Kumar, Rajneesh (MED)
Date: Wed Mar 10 2004 - 07:45:27 EST


Hello Frank

Here is the "pseudo code" for the program

create 4 files of different sizes.Then wrote a program , as below:

while ( for arbitrary time)
{
fopen ( first file )
mmap ( first file )
Note the memory-size of process

munmap ( the file)
Note the memory-size of process again
fclose ( first file)

//Repeat the above Sequence for 2nd File
//Repeat the above Sequence for 3rd File
//Repeat the above Sequence for 4th File
}


Full code is here :

#include <sys/mman.h>
#include <iostream.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define MEM_MULTIPLIER 1

int main()
{
char *mapAddress = NULL;
int length = 10000526;
int status =0 ;
sleep(10 ); // start top on other terminal with this pid to watch size growth
int fd = 0;
for( int i = 0 ; i<6 ; i++) //arbitrary number of iterations
{
{

fd = open("./a.txt", O_RDONLY);
if (fd == -1)
{
cout<<" Could Not open a.txt"<<endl;
return 1;
}
mapAddress = (char*) mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (mapAddress == (char*)-1)
{
cout<<" Map Failed for a.txt "<<endl ;
mapAddress = NULL;
return 1;
}
cout<<"Watch out the size now after mapping a.txt"<<endl;
sleep(4);
close(fd);
st = munmap(mapAddress, length);
if (status != 0)
{
cout<<"Failed Unmap: "<<endl ;
return 1 ;
}

cout<<"Watch out the size now after unmapping a.txt"<<endl;
sleep(4);
mapAddress = NULL;
}
{
int fd = open("./b.txt", O_RDONLY);
if (fd == -1)
{
cout<<" Could Not open b.txt"<<endl;
return 1;
}
mapAddress = (char*)mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (mapAddress == (char*)-1)
{
cout<<"Failed Mmap: "<<endl ;
return 1;
}
cout<<"Watch out the size now after mapping b.txt"<<endl;
sleep(4);
close(fd);
status = munmap(mapAddress, length);
if (status != 0)
{

cout<<" Unmapped faild "<<endl;
return 1;
}
cout<<"Watch out the size now after unmapping b.txt"<<endl;
sleep(4);
mapAddress = NULL;
}
{
length = length* MEM_MULTIPLIER ;
int fd = open("./c.txt", O_RDONLY);
if (fd == -1)
{
cout<<" Could Not open c.txt"<<endl;
return 1;
}
mapAddress = (char*)mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (mapAddress == (char*)-1)
{
cout<<" Map Failed for a.txt "<<endl ;
return 1;
}

cout<<"Watch out the size now after mapping c.txt"<<endl;
sleep(4);
close(fd);
status = munmap(mapAddress, length);
if (status != 0 )
{
cout<<" Unmapped faild "<<endl;
return 1;
}
cout<<"Watch out the size now after unmapping c.txt"<<endl;
sleep(4);
mapAddress = NULL;
}
{
length = length* MEM_MULTIPLIER ;
cout<<"Watch out the size now before mapping d.txt for size "<<length <<endl;
sleep(4);

int fd = open("./d.txt", O_RDONLY);
if (fd == -1)
{
cout<<" Could Not open d.txt"<<endl;
return 1;
}
mapAddress = (char*)mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
if (mapAddress == (char*)-1)
{
cout<<" Map Failed for d.txt "<<endl ;
return 1;
}
cout<<"Watch out the size now after mapping d.txt"<<endl;
sleep(4);
close(fd);
st = munmap(mapAddress, length);
if (st != 0)
{
cout<<" Unmapped faild "<<endl;
return 1;
}
cout<<"Watch out the size now after unmapping d.txt"<<endl;
sleep(4);
mapAddress = NULL;
}
}
sleep(10);
}







Regards
Rajneesh Kumar

GSP, GEMS-GTO
GE Medical Systems
John F Welch Technology Center
#152, EPIP. Phase 2
Whitefield, Bangalore.560 066

Ph : (080) - 2503 3412
Dialcom: *901 3412
mail: rajneesh.kumar@xxxxxxxxxx


-----Original Message-----
From: Michael Frank [mailto:mhf@xxxxxxxxxxxxx]
Sent: Wednesday, March 10, 2004 11:31 AM
To: Kumar, Rajneesh (MED)
Subject: Re: PROBLEM:: irreversible Memory growth of process in
mmap()-munmap() calls


On Wed, 10 Mar 2004 10:48:32 +0530, Kumar, Rajneesh (MED) <rajneesh.kumar@xxxxxxxxxx> wrote:

> Hi Frank,
> I suspect two things:
> 1. Either map() unmap() has an issue
> 2. top in linux does not give exact memory size of process.
>
> whats u'r opinion
>

Please post a short program which demos the problem on LKML. This is
the only way to get help from the kernel developers to track down
the problem.

Regards
Michael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/