1752861 Members
3992 Online
108790 Solutions
New Discussion юеВ

testing memory

 
SOLVED
Go to solution
Jason Berendsen
Regular Advisor

testing memory

I am looking for a process that is memory intensive but not CPU or disk intensive, so I can simulate a high memory load on a machine. Is there a better way to do this besides running multiple instances of a memory intensive process?
4 REPLIES 4
Uday_S_Ankolekar
Honored Contributor

Re: testing memory

Hi,

Use Glance for realtime system statastics. You can install trial version of it incase you havn't purchased the product.

Also sar is a useful utility sar -q

use vmstat 5 30 and look for page out activity .High sustained page _out_ rates; paging in is normal

Goodluck.

-USA..
Good Luck..
Stefan Farrelly
Honored Contributor
Solution

Re: testing memory

Heres a program to consume tons of memory;

#define NULL 0

main()
{
int ptr;
ptr = NULL;
ptr = malloc(1024*1024*1024);
if (ptr)
perror("Malloc successful");
else
perror("Malloc unsuccessful");
}


Save it as a .c file and compile it.
cc -o

Then execute the file. This program will try to grab 1GB of memory. You can then put a sleep in if you want it to stay in memory for a while. Run top from another window and you will see this process use up the 1GB of ram. You can adjust the 1024*1024*1024 to whatever you want. You will need to ensure your maxdsiz kernel variable is set large enough (to the size of physical ram).
Im from Palmerston North, New Zealand, but somehow ended up in London...
Stefan Farrelly
Honored Contributor

Re: testing memory


Oops, malloc only allocates the space, doesnt initialize it. You want to use instead;

#define NULL 0

main()
{
int ptr;
ptr = NULL;
ptr = datalock(1000000000,50000);
if (ptr)
perror("datalock successful");
else
perror("datalock unsuccessful");
sleep(30);
}

This will grab 1GB of ram which and hold for 30secs which you will be able to see from running top. You will need to do the following on your binary first;
chatr +q3p enable
or compile it as 64 bit;
cc +W2.0
but you will need the full ANSI compiler installed for this.

Im from Palmerston North, New Zealand, but somehow ended up in London...
Jason Berendsen
Regular Advisor

Re: testing memory

Stefan,

I would imagine if I want to change the 1gig datalock to a smaller amount I would change the 1000000000 to a smaller number. What is the 50000, and do I need to change this if I change the other number?