OSDev.org
https://forum.osdev.org/

Memory size limit of malloc per process in Linux (no swap)
https://forum.osdev.org/viewtopic.php?f=13&t=38195
Page 1 of 1

Author:  clementttttttttt [ Sat Dec 05, 2020 12:43 am ]
Post subject:  Memory size limit of malloc per process in Linux (no swap)

title

Author:  bloodline [ Sat Dec 05, 2020 2:00 am ]
Post subject:  Search StackOverflow for questions like this.

title

Author:  kzinti [ Sat Dec 05, 2020 2:06 am ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

title

Author:  bzt [ Sat Dec 05, 2020 6:15 am ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

google $title

Author:  iansjack [ Sat Dec 05, 2020 6:36 am ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

32-bit title or 64-bit title?

Author:  Octocontrabass [ Sat Dec 05, 2020 12:52 pm ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

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.

Author:  nullplan [ Sat Dec 05, 2020 1:36 pm ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

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.

Author:  Thomas [ Sat Dec 05, 2020 1:51 pm ]
Post subject:  Re: Memory size limit of malloc per process in Linux (no swa

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/