LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2009, 01:21 PM   #1
Premraja
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
How much memory can all the processes allocate all together?


I wrote the following program and ran 3 instances of the same program concurrently.
================================
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned long int i =0;
while(1)
{

if(malloc(100000) == NULL)
{
printf("Failed \n");
return 0;
}
i++;

}// end while
}// end main

=================================

When I ran the program, each instances terminated as
Failed 32031
Failed 32022
Failed 32027

Which means each instances can allocate around 3GB of memory successfully at the same time, which is totalling to 9GB.

But the actual RAM is 512 and swap is 1GB.

How is this possible?
From where could it allocate 9GB, when the available space is 1.5 GB( RAM + SWAP)?
 
Old 05-16-2009, 05:38 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
The kernel does lots to magic to protect you from yourself.
Try touching the memory and see what happens.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIOCSIFFLAGS: cannot allocate memory spage0506 Linux - Software 11 07-17-2015 09:43 PM
Cannot allocate memory simha Linux - Newbie 4 01-23-2008 09:19 AM
Cannot allocate memory Terroth Linux - General 13 02-09-2005 05:22 AM
allocate more memory? sockknitter Debian 3 11-06-2004 05:23 PM
unable to allocate memory vedant Linux - Hardware 0 07-15-2003 07:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration