Disable Mac's dynamic_pager?
I read this blog post about the memory management in Mac OS X: http://workstuff.tumblr.com/post/20464780085/something-is-deeply-broken-in-os-x-memory-management
I would like your opinion on the matter.
I have "only" 4GB of memory, so the possibility of a kernel panic exists.
I do have a spinning disk(as opposed to an SSD) and see ocasional beach balls, sometimes even spinning up my external HD before continuing.
It says no swap is used at the moment, does that mean disabling dynamic_pager will do nothing? It does have some page ins.
How safe is it to just try it out? I could maybe write a script that reenables the pager when memory gets low?
[update]: End of the day, 26MB swap, a lot more page ins and outs, and a lot of inactive memory.
Solution 1:
OS X has three problems which contribute to this:
By default, any data written to or read from disk is cached in RAM at a higher priority than recent program data. Applications can disable this on a per-descriptor basis with the
F_NOCACHE
option tofcntl()
, but few do. As a result, large amounts of disk activity cause memory that isn't being used at that very moment to be swapped out. That creates more disk activity both for the swapping out and for reading that memory back in moments later, on top of the original disk activity.HFS+ does not handle concurrent file access well. In particular, opening and closing many different files at once creates tremendous contention and pretty much only one open/close operation can happen at a time.
Lots of OS X applications spread their disk access across lots of little files.
As a result, when two or more applications are trying to access a lot of files at once, the disk I/O load increases exponentially as swap activity competes with the applications for I/O.
Disabling the dynamic pager might prevent the early part of that exponential curve by removing the ability to push private/dirty application pages to disk. Instead, the system will likely scavenge pages from public/clean mapped files (executables, libraries, etc.) and from the cached file data that probably should not have been cached in the first place. Whether or not this actually improves performance would depend heavily on what applications you are using. Safari, for example, is extremely bad about managing its disk I/O so I imagine this would help.
The problem would occur if the amount RAM needed actually exceeds the amount available: a panic crash is a very abrupt way to end your day. But if you are not editing large files or otherwise doing inherently memory intensive things, this might be rare enough to consider risking.
By the way, you can use the lsof
command to see what files are opened by what processes, and the fs_usage
command to see a running log of file operations. Both work better when run as root or via sudo
.