41

How is vm.memory_pressure's value bounded / calculated on OS X 10.10.2 - Yosemite?

I've researched several answers to this question and am trying a few things on the command line to get exact values rather than looking at the graphs in Activity Monitor.

With the system under light load:

~ ❯❯❯ sysctl -a vm | grep page_free && sysctl vm.memory_pressure && sysctl kern.memorystatus_vm_pressure_level
vm.vm_page_free_target: 4000
vm.page_free_wanted: 0
vm.page_free_count: 2683717
vm.memory_pressure: 0
kern.memorystatus_vm_pressure_level: 1

The kern.memorystatus_vm_pressure_level looks right, and appears to be what it uses to color the graph (green for 1-NORMAL, yellow for 2-WARN, red for 4-CRITICAL). However, vm.memory_pressure is 0 and the graph has some amount of green to it, and it's jagged, meaning the value is clearly changing over time, not just sitting at 0.

Under heavy load it looks like this:

❯❯❯ sysctl -a vm | grep page_free && sysctl vm.memory_pressure && sysctl kern.memorystatus_vm_pressure_level
vm.vm_page_free_target: 4000
vm.page_free_wanted: 0
vm.page_free_count: 32572
vm.memory_pressure: 1693
kern.memorystatus_vm_pressure_level: 4

Or this...

~ ❯❯❯ sysctl -a vm | grep page_free && sysctl vm.memory_pressure && sysctl kern.memorystatus_vm_pressure_level
vm.vm_page_free_target: 4000
vm.page_free_wanted: 0
vm.page_free_count: 5431
vm.memory_pressure: 277
kern.memorystatus_vm_pressure_level: 4

Or this...

~ ❯❯❯ sysctl -a vm | grep page_free && sysctl vm.memory_pressure && sysctl kern.memorystatus_vm_pressure_level
vm.vm_page_free_target: 4000
vm.page_free_wanted: 3220
vm.page_free_count: 805
vm.memory_pressure: 1
kern.memorystatus_vm_pressure_level: 4

Here's where I'm confused. None of these values alone could possibly be the Y value of the graph for a couple of reasons.

First, vm.memory_pressure just sits at 0 almost all the time under normal load, and the graph doesn't sit at 0.

Second, they are not consistent with one another. Looking at the memory_pressure value, it is lower when it actually had wanted pages (3220 wanted and pressure of only 1) than when it had 5431 free and none wanted (pressure was 277). And somehow that's even lower pressure than when it had 32572 free (and had 1693 pressure).

So, when it plots that graph, what's the calculation for the Y value, and how can I get the data I need to calculate it from the command line? I'm looking to make a command line tool that will spit out a percentage of how high the current line would be on that graph, so I need to know how to calculate the value at any given time, as well as what the range of possible values are.

  • 7
    Great question. The Activity Monitor shows pressure on a scale from 0% to 100% but I've not found any reference on the command line comments of this. I'll see if I can dig up enough for an answer this week. Can we presume you are interested in 10.10.x only? – bmike Feb 2 '15 at 22:35
  • 3
    Thank you. And yes, I'm on 10.10.2, so that's the only one I'm concerned with for this. – Raugturi Feb 2 '15 at 22:48
  • 5
    Fascinating data points. It's still not clear to me how the algorithm is designed or coded - or even if it's remaining the same from version to version. See apple.stackexchange.com/questions/107126/… for some nice commentary and more data on this. – bmike Dec 15 '15 at 18:57
  • 1
2

This is currently only a partial answer. This answer not complete until this sentence removed.

The thing about this question is that on the face of it, the Memory Pressure graph doesn't quite make sense when comparing it with what's reported in Terminal when using the command outlined by the OP:

sysctl -a vm | grep page_free && sysctl vm.memory_pressure && sysctl kern.memorystatus_vm_pressure_level

However, the problem here is that this command limits the vm values it's reporting back. In fact, there's actually 105 values in total but this command only reports the following five values:

vm.vm_page_free_target:
vm.page_free_wanted:
vm.page_free_count:
vm.memory_pressure:
kern.memorystatus_vm_pressure_level:

NOTE: Numerical values would normally appear after the colon (:), however I have not included these.

Obviously, the overwhelming majority of the 105 vm values are not part of the actual calculation that determines memory pressure, but the problem here is that the five values above are not the only ones used to calculate memory pressure.

For example, while the above output provides some of the various free values, it's not providing any of the inactive values, etc.

These values are important because the memory pressure algorithm calculates a ratio between those values, and the relationship between those values isn't apparent from the output produced by the command in the OP's question.

I think I may have some technical information that can shed more light on this. I will update this answer either way within the week.

[STATUS UPDATE]

I've been unable to find the technical information I was looking for. However, I am fairly certain I do still have it - probably on some old CDR/DVDR backups. I will update this answer once I've found it, or after I'm certain I won't find it.

You must log in to answer this question.

protected by Community Apr 5 '16 at 0:00

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .