Ady Wicaksono Daily Activities

How much memory space we could allocate for single process in linux?

leave a comment »

Try this C code

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

int main(){
	size_t siz = 100 * 1024 * 1024 ;
	size_t idx = 1 ;
	void *ptr;

	for (;;){
		ptr = malloc ( siz * idx );
		if(!ptr)
			break ;
		free(ptr);
		idx++;
	}
	printf ("Max malloc %d * 100 MB \n", idx - 1 );
	return (0);
}

On my linux 2.4 the limitation is 2000 MB ~ 2 G
On my linux 2.6 the limitation is 2800 MB ~ 2.8 G
No matter how big your RAM is, 1 process could only occupied 2.8 G on kernel 2.6 (in my case I have 4 Gbytes), next I will share you how to reconfigure the kernel to allow us use bigger memory. This is very important, especially if you run a database like MySQL that handle huge transaction and data, but your mysqld process itself is limited to use 2.8 Gbytes memory, you buy more memory but impact nothing🙂

$ free
             total       used       free     shared    buffers     cached
Mem:       4149288    4026472     122816          0     108004    1277016
-/+ buffers/cache:    2641452    1507836
Swap:      4192924        836    4192088

$ uname -a
Linux x 2.6.11-1.1369_FC4smp #1 SMP Thu Jun 2 23:08:39 EDT 2005 i686 i686 i386 GNU/Linux

$ ./a.out
Max malloc 28 * 100 MB

Written by adywicaksono

November 8, 2007 at 5:25 am

Posted in Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: