スワップザッパー

dankogai御大様々より。Mac OS X の dynamic_pager をほげるという荒技。

このあたりは他のUnixも同じなのだけど、 Mac OS X の場合、専用のパーティションではなく通常のファイルシステムスワップファイルを作るところが違う。これのおかげで専用パーティションなしでも仮想記憶が使える一方、一度出来たスワップファイルは滅多なことでは削除されないということになってしまう。

でも、メモリーを何GBも積んでいても、スワップがありうるというのはやはりいやだ。

404 Blog Not Found:Mac OS X Leopard - dynamic_pager を骨抜きに

まぁ、そうなんですが。

If like me you cannot deal with the swapping in OS X, and if you have tried everything possible, even not to launch dynamic_pager (and you've seen that you're system is not usable anymore (on my mac the 2Gb was detected but the system was refusing to use more then 1Gb :-( )), then I have the solution : create another dynamic_pager that fits your needs :-P

http://cestdelamerde.com/archives/22-Killing-Mac-OS-X-Swapping-How-To-Disable-dynamic_pager.html

だからって dynamic_pager.c を hack するのはアレゲすぎると思う今日この頃。
とりあえず、この dynamic_pager.c を軽く読んでみてから試してみます。怖いから!


なお、読めばおわかりの通りこいつは 10.5.2 の darwin ソースから作られてるので一応注意を。
でも、なんで MacOSX10.5u.sdk じゃなくて MacOSX10.4u.sdk を include してるんだろう。headers は変わってない? 読まないと判らないなぁ。

余談

ちなみに、

Then (after having done a backup of the regular dynamic_pager) copy your brand new dynamic_pager to /sbin. Reboot and enjoy : it will only create a single swap file (64Mb), no less, no more.

http://cestdelamerde.com/archives/22-Killing-Mac-OS-X-Swapping-How-To-Disable-dynamic_pager.html

とあるとおり dynamic_pager は 64MB開始で倍々に swapfileNを増やしていくので、こんな感じで増えます。

 $ ls -lh /var/vm/
total 4194304
-rw------T  1 root  wheel    64M  8 24 08:02 swapfile0
-rw------T  1 root  wheel    64M  8 24 15:39 swapfile1
-rw------T  1 root  wheel   128M  8 25 00:03 swapfile2
-rw------T  1 root  wheel   256M  8 25 02:00 swapfile3
-rw------T  1 root  wheel   512M  8 25 09:57 swapfile4
-rw------T  1 root  wheel   1.0G  8 26 20:13 swapfile5

だからどうだと言われてもアレですが。