Hacker News new | ask | show | jobs
by The_rationalist 1950 days ago
What do you mean? If it's allocated to chrome it cannot be reused by other software. Even if it's allocated but unused
2 comments

You absolutely can allocate memory without using up any backing resources. On Linux (which is where I have experience, but I assume macos works similarly), even after mapping some memory, it won't be backed by any physical memory (e.g. RAM) until you actually write there. And you can mmap files into your address space, meaning you can place a huge file you can access through memory, but it's not actually taking any RAM, the kernel is just doing the reading of each "chunk" of the file as you access them, unloading the old bits once you stop using them for a while.

Measuring memory usage is hard.

And that doesn't even get into decommitting and related things, where you mark memory that you have used as no longer needed but still "there" in a variety of different senses. Not to mention the extra fun on OSX where you can mark something as unused, but OSX makes you pinkie-promise to let it know before you start using it again. If you don't, it works, but the accounting becomes inaccurate. "Fun".
So can you allocate more memory than what is available in this way?
Yup! Processes see/use virtual memory, not the literal physical RAM address spaces. The kernel maintains mappings between virtual-physical and will allocate/free physical memory as needed. All of this is invisible to the process.

Pretty neat huh?

In fact, this is the entire premise of virtual memory! More memory is/can be allocated than physical memory exists. Each process has its own isolated address space with (from the process perspective) "unlimited" size.