4 ms·
This barely scratches the surface of what a complicated topic memory usage is. No mention of shared memory (which is very important for Android because everythi
by hinoki 5y ago
This barely scratches the surface of what a complicated topic memory usage is. No mention of shared memory (which is very important for Android because everything is forked from zygote), no mention that Windows separates address space allocation from “committing” to provide pages (so you can’t OOM on a page fault like with Linux, but you can fail more often on allocations).
So you can have virtual address space “usage”, commit “usage”, and physical page “usage” (which can be shared between processes).
And that’s just anonymous memory, file backed gets even more complicated. Are pages that are in file cache but no longer mapped into a process counted as “usage”?
Anyways, for an introduction to a topic I would expect more links to background information, and you can go very deep trying to answer the question of how much memory an application is using. And the first step is to carefully define “memory” and “using”.
- rageoholic 5y agoLinux actually will let you allocate address space without allocating pages. You just disable all access and the OS knows that it doesn't actually need to give you any pages. You then commit by using mprotect to enable access to the page. There are madvise hints you can use to tell the OS that you no longer care about what's in the page, although they're a bit misnamed for compatibility reasons(MADV_DONTNEED will immediately free the pages while MADV_FREE will lazily free the pages) Edit: Actually it looks like the behavior might have changed. hmmm. I guess read the man pages tied to the kernel you're using Edit 2: Nope, I misread the most recent manpage. I should not read manpages when I'm tired. It does zero fill specifically for anonymous mappings
- dataflow 5y agoOn Windows I always look at the commit charge. I think it's the most intuitive metric. While shared memory etc. do complicate things, I've found they're also not really relevant whenever I'm looking at the memory usage of a process.