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

Thanks Jlliagre, My free observation is here

> #free
>         total   used   free   shared   buffers  
    Mem: 106428   66560  39868   0        5240 
> #

" Jlliagre --- Malloc is allocating virtual memory while free is displaying RAM and SWAP usage "

fine, then does it mean that virtual memory for a process is fixed amount so that other processes will also get memory, instead of putting other processes running out of memory.

my concern is even-though free shows 39868 KB, it fails on malloc() of 2.5 MB

asked 02 May '10, 11:14

thinku's gravatar image

thinku
1114
accept rate: 0%

edited 05 May '10, 05:15

Please format free output for readability. Is it missing a Swap line ? What is that portable player in the first place ? malloc shouldn't fail if there is really 39MB available. Try adding system("free"); just before the malloc to make sure.

(04 May '10, 08:03) jlliagre

Please accept an answer so the question/answer can be finished. Or provide more details so we can help.

(20 Apr '11, 13:43) rfelsburg ♦



My understanding of this option is that 110M are given for kernel & user-space and the remaining 146 are wasted as far a Linux is concerned. The BIOS might use it but it's unlikely to be useful in your case. Normally, that's the other way around. This option was created to allow Linux to use all of your memory if for some reason it wasn't able to detect the whole of it at boot time.

As of malloc and free discrepancies. Malloc is allocating virtual memory while free is displaying RAM and SWAP usage. These are not strictly related, especially when overcommitting is enabled. Add "free" output to you question to clarify.

link

answered 03 May '10, 10:07

jlliagre's gravatar image

jlliagre
1513
accept rate: 50%

Thansk Jlliagre,

My free observation is here

free

          total         used         free       shared      buffers

Mem: 106428 66560 39868 0 5240

" Jlliagre --- Malloc is allocating virtual memory while free is displaying RAM and SWAP usage "

fine, then does it mean that virtual memory for a process is fixed amount so that other processes will also get memory, instead of putting other processes running out of memory. my concern is eventhough free shows 39868 KB, it fails on malloc() of 2.5 MB

(04 May '10, 05:15) thinku

How much storage size does you PMP shows when you connect it to a comp. Does it show 256 - 110 = 146MB ?

link

answered 03 May '10, 15:48

Prasad's gravatar image

Prasad
485
accept rate: 33%

mem=0 option enables kernel to boot and use all the available memory. In you case all 256 MB. Now 110 M means,remaining 146 M is wasted.

link

answered 03 May '10, 12:09

Pradeep's gravatar image

Pradeep
1
accept rate: 0%

Specifying "mem=0" is pointless as the kernel will use all available memory by default.

(03 May '10, 13:30) jlliagre

Do you use onboard video? Most onboard GPUs like to take system RAM and convert it to VRAM so they can function properly. That could be what's happening there. Might be good to upgrade to an actual video card.

Then again, most integrated GPUs don't take over 25% of system RAM.

I personally am not suffering this problem as I have a PCI-E video card and I don't see my kernel allocating anything less than what my system actually has.

link

answered 03 May '10, 16:32

Yaro%20Kasear's gravatar image

Yaro Kasear
4914
accept rate: 0%

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)

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

(See also Documentation/vm/overcommit-accounting)

link

answered 05 May '10, 08:48

thinku's gravatar image

thinku
1114
accept rate: 0%

You got it wrong. Out of your 110 MB, "180%" is allocatable. Your successful mallocs are therefore quite unreliable.

(05 May '10, 11:49) jlliagre

jlliagre. i missed to update the one more change that i did.

I changed the overcommit_memory to 2; and set the ratio as 80 %;

(06 May '10, 10:27) thinku

Here is my Observation

# cat /proc/meminfo
****MemTotal:       106428 kB****
MemFree:         76196 kB
Buffers:          5280 kB
Cached:           7076 kB
SwapCached:          0 kB
Active:           6972 kB
Inactive:         5840 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       106428 kB
LowFree:         76196 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:         476 kB
Mapped:            908 kB
Slab:             9584 kB
PageTables:         84 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
**CommitLimit:     53212 kB**
Committed_AS:     1716 kB
VmallocTotal:   262136 kB
VmallocUsed:      7580 kB
VmallocChunk:   253760 kB
# cat /proc/sys/vm/overcommit_ratio
50


# echo 80 > /proc/sys/vm/overcommit_ratio



# cat /proc/sys/vm/overcommit_ratio
80
# cat /proc/meminfo
MemTotal:       106428 kB
MemFree:         76204 kB
Buffers:          5280 kB
Cached:           7076 kB
SwapCached:          0 kB
Active:           6972 kB
Inactive:         5840 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       106428 kB
LowFree:         76204 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:         476 kB
Mapped:            932 kB
Slab:             9600 kB
PageTables:         84 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
***CommitLimit:     85140 kB***
Committed_AS:     1716 kB
VmallocTotal:   262136 kB
VmallocUsed:      7580 kB
VmallocChunk:   253760 k

Further from

Generated by /proc/meminfo.

memused         -  Total size of used memory in kilobytes.
memfree         -  Total size of free memory in kilobytes.
memusedper      -  Total size of used memory in percent.
memtotal        -  Total size of memory in kilobytes.
buffers         -  Total size of buffers used from memory in kilobytes.
cached          -  Total size of cached memory in kilobytes.
realfree        -  Total size of memory is real free (memfree + buffers + cached).
realfreeper     -  Total size of memory is real free in percent of total memory.
swapused        -  Total size of swap space is used is kilobytes.
swapfree        -  Total size of swap space is free in kilobytes.
swapusedper     -  Total size of swap space is used in percent.
swaptotal       -  Total size of swap space in kilobytes.
swapcached      -  Memory that once was swapped out, is swapped back in but still also is in the swapfile.
active          -  Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
inactive        -  Memory which has been less recently used and is more eligible to be reclaimed for other purposes.
                   On earlier kernels (2.4) Inact_dirty + Inact_laundry + Inact_clean.

The following statistics are only available by kernels from 2.6.

slab            -  Total size of memory in kilobytes that used by kernel for data structure allocations.
dirty           -  Total size of memory pages in kilobytes that waits to be written back to disk.
mapped          -  Total size of memory in kilbytes that is mapped by devices or libraries with mmap.
writeback       -  Total size of memory that was written back to disk.
committed_as    -  The amount of memory presently allocated on the system.

The following statistic is only available by kernels from 2.6.9.



  commitlimit     -  Total amount of memory currently available to be allocated on the system.
link

answered 06 May '10, 10:34

thinku's gravatar image

thinku
1114
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×6
×3
×3
×1
×1

Asked: 02 May '10, 11:14

Seen: 5,340 times

Last updated: 20 Apr '11, 13:43

powered by OSQA