2

I'm wondering if in MacOS there are parameters equivalent to the Linux ones:

vm.dirty_background_bytes
vm.dirty_background_ratio
vm.dirty_bytes
vm.dirty_ratio
vm.dirty_expire_centisecs
vm.dirty_writeback_centisecs

By mean of them one can change the behavior of buffer/cache of the filesystem, e.g. how much RAM to use to caching files' blocks, after how much time flush the cache to disk, etc. Those parameters, in linux, are modified by the sysctl command. In the MacOS documentation I cannot find equivalent parameters.

Any hint ?

Thanks in advance.

user1131951
  • 141
  • 7

1 Answers1

4

Yes, almost the same as linux.

You can configure manually each one using the sysctl command, after success it shows the old and the new value (see image)

enter image description here

You can check current values:

> $ sudo sysctl kern.vm_page_free_min
kern.vm_page_free_min: 147456


> $ sudo sysctl kern.vm_page_free_reserved
kern.vm_page_free_reserved: 16384

And you can configure them to be used on every boot.

  1. Just create a new file: sudo vim /etc/sysctl.conf

  2. Put the configured values on it. (the values below are very good ones, I am currently using them with huge memory/cache/swap management performance gains)

kern.vm_page_free_target=163840
kern.vm_page_free_min=147456
kern.vm_page_free_reserved=16384
kern.vm_page_speculative_percentage=1
vm.vm_page_background_exclude_external=0
vm.vm_page_background_mode=1
vm.vm_page_background_target=163840
vm.compressor_timing_enabled=1

I suggest you use them.

Reboot after saving them on /etc/sysctl.conf

Performance gain is noticeable on the next login after booting and during normal usage. (if your machine freezes because lack of memory, it will not freeze anymore with those, try to freeze it as a challenge ;)

PS: To list all parameters, execute sysctl -A. Those specific vm.dirty.* linux parameters you mentioned doesn't exist on MacOS, those I posted to you are the equivalents one for that purpose (except the last one for timming compression, but I put together because it is better to have the timming enabled [default is disabled] and it is related to memory management, specifically about the memory compression mechanism). If you need others or any other info, or any questions, fell free to ask me.

Prado
  • 522
  • 2
  • 4
  • Thanks Pedro, that's pretty nice. I wonder where we can find information on these and other parameter... Is the a Apple developer page/doc dedicated to them ? – user1131951 Aug 30 '19 at 11:33
  • 1
    All those parameters that Apple use comes from the BSD kernel subsystem of MacOS, search for them on the OpenBSD documentations, and/or source code. The source code of MacOS kernel is open and it the same as the BSD kernel, with just a few add-ons. The source of the Apple kernel is here (all versions) https://opensource.apple.com/source/xnu/ if you want to look at it, it contains all those setting, but I suggest you also get the OpenBSD and compare/read at the same time. – Prado Aug 30 '19 at 16:26
  • 1
    @user1131951 For documentation as you asked: use the OpenBSD man pages and technical docs for understanding the descriptions of each command. – Prado Aug 30 '19 at 16:32