OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 10, 2021 7:08 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Memory size limit of malloc per process in Linux (no swap)
PostPosted: Sat Dec 05, 2020 12:43 am 
Offline
Member
Member

Joined: Tue Jul 14, 2020 4:01 am
Posts: 60
title


Top
 Profile  
 
 Post subject: Search StackOverflow for questions like this.
PostPosted: Sat Dec 05, 2020 2:00 am 
Offline
Member
Member
User avatar

Joined: Tue Sep 15, 2020 8:07 am
Posts: 218
Location: London, UK
title

_________________
Building a single address space Microkernel, as used in embedded applications, for the desktop... Download latest build bootable Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 2:06 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 675
title

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 6:15 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1482
google $title


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 6:36 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4168
Location: Chichester, UK
32-bit title or 64-bit title?


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 12:52 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3000
No single call to malloc() can allocate more than PTRDIFF_MAX - 1 bytes. This is a limitation of GCC, Clang, and any C library designed to work with them. Multiple calls to malloc() can be used to allocate more than that as long as you don't hit one of the other limits.

Different CPU architectures have different user address space limits. For example, on 32-bit MIPS, a user program can never address more than 2GiB of memory. Some of this address space is already in use by your program and your C library.

Typical malloc() implementations use the kernel's lazy allocation, which may overcommit. Linux allows the overcommit strategy to be configured at runtime. If you attempt to use lazy-allocated memory and no memory is available to back it, the OOM killer will start killing processes. I'm not sure if there are any malloc() implementations that use eager alloction, or if it would be possible to make one using the available Linux system calls.


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 1:36 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 966
Octocontrabass wrote:
I'm not sure if there are any malloc() implementations that use eager alloc[a]tion, or if it would be possible to make one using the available Linux system calls.
No, it is not. mmap() has flags that provide hints as to whether there should be memory behind the maps, but those are nonstandard and are only hints, so they don't force anything. The keyword is "memory overcommit". By default, Linux uses a heuristic overcommit, where it will allow up to 50% more memory to be mapped than is actually available (IIRC, writing this from memory and being slightly inebriated). The other settings are "full overcommit", where it will just allow anything that fits into virtual memory, and "strict overcommit", where it will not allow a single page beyond what fits into physical memory and swap. These settings are only selectable on a systemwide basis with a proc pseudo-file.

_________________
Thou hast outraged, not insulted me, sir; but for that I ask thee not to beware of Starbuck; thou wouldst but laugh; but let Ahab beware of Ahab; beware of thyself, old man.


Top
 Profile  
 
 Post subject: Re: Memory size limit of malloc per process in Linux (no swa
PostPosted: Sat Dec 05, 2020 1:51 pm 
Offline
Member
Member
User avatar

Joined: Thu Jun 04, 2009 11:12 pm
Posts: 280
Octocontrabass + 1.
If you are talking about the user level malloc api, then this usually relies on the library runtime. If I remember correctly some unix libraries used sbrk system call to implement malloc. But I am not completely sure if that is the case anymore and I feel lazy to look that up.

--Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group