Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-23-2009, 12:40 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Can't malloc all free physical memory, CommitLimit too low

Hi all. I'm writing some code to make a custom Ubuntu 8.04 Live CD and the code will write the character "x" to all free physical memory. In a shell script, I turn off swapping (swapoff), turn off overcommit (echo 2 > /proc/sys/vm/overcommit_memory), drop_cache, check MemFree in /proc/meminfo and pass the value to a simple C program that malloc's a buffer with the size of that value. But I'm unable to allocate that amount because I think my CommitLimit shown in /proc/meminfo is 700mb out of the 1.4gb MemFree (1.5gb MemTotal). In the C code, the malloc returns a null pointer when I pass it anything greater than the value of CommitLimit, which is consistent with what I think is causing the null pointer.

Is there a way to increase the CommitLimit so I can allocate every bit of the free space? Again the script and C code is being run from a LiveCD environment, so there is no physical hard disk.

Last edited by FEWP; 07-23-2009 at 12:41 AM.
Old 07-23-2009, 09:56 AM   #2
Registered: May 2002
Location: dracut MA
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 109Reputation: 109
In short: no. The design of linux memory allocator is to always be optimistic, and therefore you cannot prevent the OOM killer from running, or from exceeding the commit limit in an allocation. I could be wrong on this, but that is my assumption on how the linux allocation scheme works.
Old 07-23-2009, 12:56 PM   #3
LQ Newbie
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
You can turn off the optimistic allocation as described (echo 2 > /proc/sys/vm/overcommit_memory). This will indirectly prevent the OOM killer from running, in theory, by not preventing memory allocation calls from getting more than they're supposed to. However I'm wondering how the kernel arrives at the CommitLimit value. It seems odd that it would only be about half the amount of MemFree.


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
PCIe dma-able memory location in physical memory for Intel Nehalem / Tylersburg arch robvoo Linux - Kernel 4 07-31-2009 06:21 AM
Free Physical Memory manoj.linux AIX 4 04-04-2008 07:14 PM
increase free physical memory, decrease disk cache efm Linux - Hardware 4 03-30-2006 09:53 AM
Slow to boot and low free memory krisbitner Linux - Software 1 01-15-2006 05:18 AM
free physical memory saavik Solaris / OpenSolaris 7 08-26-2005 12:22 PM > Forums > Non-*NIX Forums > Programming

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

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