LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-03-2010, 01:08 AM   #1
nilathinesh
Member
 
Registered: Nov 2006
Distribution: Fedora 7 & 9, Ubuntu
Posts: 41

Rep: Reputation: 15
Post Memory allocation in Linux


I got a doubt with memory allocation in Linux

I am having 256 MB of RAM in my portable player and the linux kernel is given with parameter "MEM=110M" while booting,

Can any one explain what does that mean

Is it a ...

1) 110 M is given for Kernel memory and remaining 146 is for user-space memory

or 2) 110M is given for kernel & user-space and remaining can be configured as per requirement (may be... say, driver memory)

Also, when i start a application that has many malloc in it., at some point the malloc() function returns null., whereas i parallely checking through Telnet for the "free memory space" through "free" cmd, it returns 39 MB as unused (ie., free)

I am little confused now (may be i am not knowing the memory partitions), can any one explain on this

Thanks in advance
 
Old 05-03-2010, 01:18 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
That means
3) Linux & applications get 110M, the remaining 146 lie inaccessible.



Cheers,
Tink

Last edited by Tinkster; 05-03-2010 at 05:00 AM. Reason: fat fingers
 
Old 05-03-2010, 04:47 AM   #3
nilathinesh
Member
 
Registered: Nov 2006
Distribution: Fedora 7 & 9, Ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks Tinkster,

Yes, i confirmed it by experiement; now i increased the MEM=128M and i DIDN'T found the malloc() fail.,


But still i wonder, eventhough the "free" shows 39 MB, why malloc was failed in the case of MEM=110M

The reason may be
1. Does "free" command shows something different or
2. Is the memory is got fragmented and not able to get the memory of my requested size..

Please clarify me. Thanks again
 
Old 05-03-2010, 08:10 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by nilathinesh View Post
1. Does "free" command shows something different or
free generally shows something different from what a beginner would think he understands by looking at its output. But that isn't a factor in this case.

Quote:
2. Is the memory is got fragmented and not able to get the memory of my requested size.
Fragmentation occurs in the virtual space, not physical and on a much bigger system running much bigger problems it could be a reason malloc fails when there is plenty of ram. Not so in this case.

Linux reserves part of the free memory for "more important" uses than ordinary user programs. On a system with very little ram (relative to whatever you're trying to run) more might be reserved that way than is beneficial. I'm not sure what parameters manage that feature.
 
Old 05-04-2010, 01:33 AM   #5
nilathinesh
Member
 
Registered: Nov 2006
Distribution: Fedora 7 & 9, Ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Smile

Quote:
free generally shows something different from what a beginner would think he understands by looking at its output. But that isn't a factor in this case.
Yes i thought, it shows the HEAP memory. but seems not. then.. how HEAP size alloted ? please explain and why my malloc() fails

Thanks johnsfine

Quote:
Linux reserves part of the free memory for "more important" uses than ordinary user programs. On a system with very little ram (relative to whatever you're trying to run) more might be reserved that way than is beneficial. I'm not sure what parameters manage that feature.
,

Experts, can you please give your comments on this

Thanks
 
Old 05-04-2010, 09:30 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,183

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I would try starting without the "MEM=" parameter in place, because you probably don't need (or want) it at all.

The "boot loader," which loads Linux itself, ought to provide some way for you to override that parameter at startup-time, i.e. "just this once," so that you can see if it works for you.

I once worked with a little box that, for some reason, didn't report the memory-size correctly. This parameter allowed me to impose my knowledge of what the correct value should be.
 
Old 05-05-2010, 04:53 AM   #7
nilathinesh
Member
 
Registered: Nov 2006
Distribution: Fedora 7 & 9, Ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Smile

Yes; now i got some more information, i could allocate memory without any issues by setting

80 on /proc/sys/vm/overcommit_ratio

Further on googling and on some discussion
Since Kernel version 2.5.30 the values for

/proc/sys/vm/overcommit_memory

0 (default): as before: guess about how much overcommitment is reasonable,
1: never refuse any malloc(),
2: be precise about the overcommit - never commit a virtual address space larger than swap space plus a fraction overcommit_ratio of the physical memory.

Here /proc/sys/vm/overcommit_ratio (by default 50) is another user-settable parameter.

so out of my 110 MB 50 % is allocatable and remaining are for left "free" for other operations..(i guess for other processes too .. need to experiment on this)

hence by changing this to 80 %; now i am getting successive malloc() operation

(See also Documentation/vm/overcommit-accounting)

Thankyou all and Thanks to LQ, LinuxExchange.org
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Application Virtual address space memory allocation - memory does not get free chamara82 Linux - General 4 01-01-2011 09:19 PM
static kernel memory allocation in Linux niceguyad Programming 1 03-31-2008 04:29 PM
linux frontend memory/cpu allocation, is it possible? matticus Linux - Hardware 1 09-19-2006 02:22 AM
how does linux handle memory allocation? nodger Programming 4 04-17-2004 11:10 PM
Linux memory allocation to programs mlaudu Linux - Software 1 03-29-2004 05:25 PM


All times are GMT -5. The time now is 08:30 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration