Stress testing memory using malloc in linux ??


 
Thread Tools Search this Thread
Top Forums Programming Stress testing memory using malloc in linux ??
# 1  
Old 12-14-2009
Stress testing memory using malloc in linux ??

Hi to all,

Recently i am testing an equipment that runs in i586 fedora linux. I have to test mmap function. For that i determined to fill the memory and run the required application to check whether it throws any mmap error regarding low resources.

This is the line that does the allocation.
p = (long double *) malloc(BUFFSIZE);

In windows process explorer i have noticed that what ever value we give it to BUFFSIZE it will increase the size of "Private Bytes" but not working set memory or actual memory. In linux the memory still remains the same even after allocating about 1000MB. So the system remains stable. The "memset" package is not available and cannot be installed, also there is no swap memory. The equipment runs in its own ram which is about 500MB.


I am looking for a C program to fill the memory and crash the system. Kindly help.

BASIL B.C.SmilieSmilie
# 2  
Old 12-14-2009
Quote:
Originally Posted by frozensmilz
Hi to all,

Recently i am testing an equipment that runs in i586 fedora linux. I have to test mmap function. For that i determined to fill the memory and run the required application to check whether it throws any mmap error regarding low resources.

This is the line that does the allocation.
p = (long double *) malloc(BUFFSIZE);

In windows process explorer i have noticed that what ever value we give it to BUFFSIZE it will increase the size of "Private Bytes" but not working set memory or actual memory. In linux the memory still remains the same even after allocating about 1000MB.
Linux will show memory that is malloced but never used in any way under its' virtual memory stat.

If you want the system to actually run out of memory, and not kill random processes to regain it, you may want to turn overcommit and oom-kill off on your linux system. With overcommit enabled, it will only allocate memory you actually use. I cannot predict the effects of this on a system completely lacking in swap memory however -- why does your system not have it? Was Windows tested under these conditions too?

Code:
echo 2 > /proc/sys/vm/overcommit_memory
echo 0 > /proc/sys/vm/oom-kill

These settings are not persistent. If you reboot the machine, they will be set back to default values. Which are frankly more stable for reasons you're discovering -- it makes it harder for endless memory leaks to kill your machine. Not all versions of linux have /proc/sys/vm/oom-kill, I'm hunting for the alternative. You may find it listed by sysctl -A.
Quote:
The "memset" package is not available and cannot be installed
What memset package? If you mean the C function, it definitely has memset. You need to include <string.h>.

Last edited by Corona688; 12-14-2009 at 01:48 PM..
# 3  
Old 12-14-2009
Thanks a lot for the help. It gave me a start (keywords for googling Smilie )...given below is the code for filling the memory in linux ....yes the swap is unavailable. The vendor installed it that way.

Code:
// blast.cpp - MEMORY STRESS TEST SCRIPT
//
// Note: This allocates huge blocks of memory and fills with 1
//
// MAINTENANCE HISTORY
// DATE         AUTHOR AND DETAILS
// 15-12-09     BAS     TR - ORIGINAL (modified)
//
//----------------------------------------------------------------------------79

 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

 #define MEGABYTE 1024*1024

 int main(int argc, char *argv[])
 {
         void *myblock = NULL;
         int count = 0;
         char ch,*mem;

         if ( argv[1] == NULL ) {
                 printf("usage: blast <memmory space>\n");
                 exit(0);
         }

         int memReq = 0;
         memReq = strtol (argv[1],&mem,10);

         //while (1)
         while (count < memReq)
         {
                 myblock = (void *) malloc(MEGABYTE);
                 if (!myblock) break;
                 memset(myblock,1, MEGABYTE);
                 printf("Currently allocating %d MB\n", ++count);
         }

         do {
                 printf("Hit 'y' to exit...\n");
                 scanf("%c",&ch);
         } while ( ch == 'y' );

         free(myblock);
         exit(0);
 }

Actual source:
When Linux Runs Out of Memory - O'Reilly Media

BASIL B.C.

Last edited by pludi; 12-15-2009 at 02:32 AM.. Reason: code tag
# 4  
Old 12-14-2009
Glad you found what you needed, but please put that code in code tags..

Also, I see nothing in there that needs C++ libraries or even a C++ compiler, it'll compile as pure C.
Quote:
Originally Posted by frozensmilz
yes the swap is unavailable. The vendor installed it that way.
So install it. If you're concerned about low-memory, you need swap. You don't even need a partition to add swap, you can just make a big empty file, run mkswap on it, and mount it as swap.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

3rd party stress testing services

Hi all, bit of a forum newb here, so apologies if this has been covered else where, but I wonder if any of you has any experience with stress testing servers, specifically using 3rd party services. We run a very busy production system, and just haven't been able to simulate the user activity while... (1 Reply)
Discussion started by: dare99
1 Replies

2. Programming

*** glibc detected *** ./a.out malloc() memory corruption

I am facing a problem of memory corruption. The loop runs for the first time but does not go through the second time. What could be the problem? for(int z=0;z<2;z++) { fp=fopen("poly.dat","r"); /*do something which reads this file into a 2D array*/ fclose(fp); ... (10 Replies)
Discussion started by: dare
10 Replies

3. Programming

glib detected: malloc() memory curruption

I am using libxml2 library for XMl parsing and libxml++ is C++ wrapper over that. So I am using API of libxml++. I am creating my class and composing instance xmlpp::Node *pNode in that. my class also have funciton prepareXPathQuery() which creates query string and have other fucntion... (2 Replies)
Discussion started by: sharadwagh
2 Replies

4. Programming

./match_pattern.out: malloc(): memory corruption: 0x0000000013a11600 ***

Hi All, I have a simple code which does some computation by matching string patterns. In brief: 1. The code reads .dat and .txt files. 2. .dat files are huge text files and .txt files contain some important words. 3. I am just doing strstr to find the patterns. 4. The function returns the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Shell Programming and Scripting

Stress testing php files at Unix/Linux Command line

Hi, Your great help is very appreciated. I am looking for any Unix command or tool for doing Stress/Load test of php files at command prompt. I tried torture.pl but it is not working after20 concurrent threads/users. as it is very urgent for me..please suggest ur ideas asap. thanks (5 Replies)
Discussion started by: Malleswari
5 Replies

6. Programming

Regarding the maximum memory allocated by malloc() function on HP-UX B11.11

In a 'C' program,when I am trying to allocate memory with the help of malloc () function, it is allocating the memory up to a certain limit for e.g. in my case, it is 670 MB (approx). malloc() returns NULL if I allocate more than this amount of memory.When I tried to allocate memory in chunks of... (1 Reply)
Discussion started by: vipinsachan
1 Replies

7. Programming

Why memory allocated through malloc should be freed ?

Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory. Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies

8. UNIX and Linux Applications

Solaris & Linux memory stress test?

I'm looking for a script or some other application that will use up a lot of memory on a Solaris or Linux server, in order to test a monitoring application. So far I have found a script that's good for CPU usage but it does nothing for memory. I have also tried the application called 'stress'... (0 Replies)
Discussion started by: Kraas
0 Replies

9. Solaris

how to stress the memory

Hi All, Is there way to stress memory on Solaris 10? If yes, how do I monitor the memory usage? (3 Replies)
Discussion started by: samnyc
3 Replies

10. Programming

malloc gives the same memory to two different nodes. How to deal with it?

When allocating memory for two different nodes, the resulting memory are the same. Clearly, this will lead to a mistake. This happened in a function. And the process must be in a function. (gdb) p tree->list $43 = (node *) 0x8be4180 (gdb) p tree->list $44 = (node *) 0x8be4180 At the... (2 Replies)
Discussion started by: cdbug
2 Replies
Login or Register to Ask a Question