4 ms·
> Also doesn’t the OS lie? I thought the memory wasn’t really physically assigned until first use. That depends on the OS. Linux lies (overcommits), Windows do
by wongarsu 6y ago
> Also doesn’t the OS lie? I thought the memory wasn’t really physically assigned until first use.
That depends on the OS. Linux lies (overcommits), Windows doesn't. In embedded it's more typical to have a special OS like VxWorks or FreeRTOS that don't lie to you, or to have no OS at all (like basically every arduino project)
- lmilcin 6y agoLinux doesn't lie, it is just probably not doing what your simplified view of memory allocation is. On Linux memory allocation is basically assigning range of address that may or may not be backed by pages in physical memory. This allows doing a lot of interesting and useful stuff. If you really want the memory for some reason (for example you need to guarantee your operation finishes without running out of memory), you need to touch the pages or force them in some other way (for example using mlock()). It is just that developers are mostly oblivious how memory management works on Linux and then are surprised that it doesn't exactly do what they want. Most people I work with can't tell how much memory is available on a Linux box if their life depended on it.
- remexre 6y agoOn my machine, which to my knowledge hasn't had this setting changed, ulimit -l reports each process can only lock 64KiB of memory... I feel like "you should use mlock()" isn't really practical advice.