LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-22-2014, 07:21 AM   #1
ddsglq
LQ Newbie
 
Registered: Apr 2014
Posts: 18

Rep: Reputation: Disabled
Question mmap is failing. Is there a setting to correct this.


I have a new linux mint system with 32 GB of ram.

The following program fails with message
commit failed i=32758
However if I try to allocate 16 GB directly it succeeds. Is there a limit on the number of mmapped pages and where can I increase this limit.
I am using something like below to allocate a separate page for each pointer in my program followed by a non committed page so that I can track down a buffer overflow in my program. So I need to do separate commits and not allocate a single 16 GB block.

Code:
#include <stdio.h>
#include <sys/mman.h>

int main()
{
        char* pt = (char*)mmap( 0, 2*2*1024LU*1024LU*4096LU, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0 );
        for( int i=0;i<2*1024*1024;i++ ){
                if( mmap( pt, 10, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, 0, 0 )==(void*)-1 ){
                        printf( "commit failed i=%u\n", i );
                        return 0;
                }
                *pt = 1;
                pt += 4096*2;
        }
        return 0;
}
 
Old 05-22-2014, 08:36 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
I ran across this:

http://www.enchantedage.com/node/235

This indicates the limit is in /proc/sys/vm/max_map_count

On my system (I have only 8GB ram), the default value is 65530.

You should be able to change the limit permanently in sysctl.conf (parameter would be vm.max_map_count)

BTW, just a nit, but index "i" is declared to be an int, yet in the format you used it is treated as unsigned int.

Last edited by jpollard; 05-22-2014 at 08:37 AM.
 
1 members found this post helpful.
Old 05-22-2014, 08:56 AM   #3
ddsglq
LQ Newbie
 
Registered: Apr 2014
Posts: 18

Original Poster
Rep: Reputation: Disabled
It worked.
Thank you jpollard. You are such a great help.
Thanks for the nit also.
 
  


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
[SOLVED] 3 ways of setting the time, which is correct? veeruk101 Linux - Newbie 1 10-24-2011 11:17 PM
DHCPD failing to serve correct lease expiration TheGorf Linux - Server 1 02-18-2009 11:16 AM
Python failing to find correct Subversion libraries HowitZer Linux - Software 2 11-21-2008 04:35 PM
correct DISPLAY setting mathfeel Linux - Software 2 05-26-2006 02:15 PM
Setting correct permissions for my ~/ ShadyCharacter Linux - General 2 04-14-2004 11:06 PM


All times are GMT -5. The time now is 08:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration