logoalt Hacker News

drdexebtjlyesterday at 10:53 PM3 repliesview on HN

I don’t understand the part about using heuristics and deciding what counts as used memory…

Used memory for the system is always total minus available.

Heuristics? I would hope that the system knows precisely what is using every single byte of physical and virtual memory. Is this a reporting problem? Why do we have to settle for heuristics and not the exact number?


Replies

toast0yesterday at 11:21 PM

> I would hope that the system knows precisely what is using every single byte of physical and virtual memory.

Of course the system knows what is using every page. The difficulty is really in how to account for pages that are backed by disk.

If you count all of those as free, that's not accurate. If you count all of those as used, that's not accurate either. Additionally, FreeBSD (at least) doesn't have separate queues for disk backed pages, so there's not really a good way to know how much of your active (or inactive) memory is disk backed.

As an additional caveat that measuring active/inactive has costs. In the past, FreeBSD wouldn't really do the work for that until it needed to... I know some stuff changed, but I don't remember where it ended up; it wasn't great when it bulk marked a ton of pages as inactive and then the active ones would fault back in.

show 2 replies
CrociDByesterday at 11:10 PM

The thing is it's easy to define free, unused memory. But a lot of the used memory is your system caching stuff that would be free if you needed more than what's actually free. So you can see you have 1g of free memory out of your 4g, but then you allocate 3g and it will do without a sweat and you'd be confused. So you have to go and dig for what those caches are and report that they're effectively free too.

show 1 reply
man8alexdyesterday at 11:16 PM

You will be surprised by how inaccurate memory measurements are.