1833162 Members
3348 Online
110051 Solutions
New Discussion

memory test program

 
SOLVED
Go to solution
Carol Garrett
Trusted Contributor

memory test program

Hi all,

I would like to create a C program to grab a huge chunk of memory to test out that out kernel parameters are right and force our system to swap a bit to check out performance. Does someone have a C program that can do this for me please ? I would be very grateful. Thanks!

3 REPLIES 3
Stefan Farrelly
Honored Contributor
Solution

Re: memory test program


Heres a piece of code that will do it;

#define NULL 0
main()
{
int ptr;
ptr = NULL;
ptr = datalock(2000000000,50000);
sleep(15);
}

Stick it in a file, eg. test.c, and compile with +DA2.0w (64bit);
cc +DA2.0w -o test test.c
Then run test, and from another window running top you will see a 2GB process start - and stop 15 secs later. If you dont have enough free ram or maxdsiz_64bit is too low you will get a not enough space error.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Carol Garrett
Trusted Contributor

Re: memory test program


Thanks Stefan!

But why use datalock, I thought you would use malloc ?

Carol
Stefan Farrelly
Honored Contributor

Re: memory test program


malloc only allocates the space in memory, it doesnt reserve it which means it doesnt actually use up that amount of memory, whereas datalock locks the memory - which means its marked as not useable to the system and thus causes the performance impact you are after. You can see the difference if you run the program and use top or vmstat to monitor memory usage.
Im from Palmerston North, New Zealand, but somehow ended up in London...