Hatena::ブログ(Diary)

<s>gnarl,</s>技術メモ”’<marquee><textarea>¥ このページをアンテナに追加 RSSフィード

2011-06-19

MacBook Airで「意味ある」RAMディスクを作る

この間、SSD寿命対策としてMacBook AirにRAMディスクを作ったことを書いたら、すごいお得情報を頂いた。

404 Blog Not Found:tips - MacBook、特にAirではRAMディスクは無駄な理由

要するに、スリープ開始後4200秒=70分経つと、/var/vm/sleepimageが使われるというわけです。別の言い方をすると、RAM 2GBなら2GB、RAM 4GBなら4GB、SSDに書き出されると。

ワハハ、無意味!!!

というわけで、なんとかしようと試みた。


$ man pmset
SAFE SLEEP ARGUMENTS
     hibernatemode takes a bitfield argument defining SafeSleep behavior.
     Passing 0 disables SafeSleep altogether, forcing the computer into a reg-
     ular sleep.

     0000 0001 (bit 0) enables hibernation; causes OS X to write memory state
     to hibernation image at sleep time. On wake (without bit 1 set) OS X will
     resume from the hibernation image. Bit 0 set (without bit 1 set) causes
     OS X to write memory state and immediately hibernate at sleep time.

     0000 0010 (bit 1), in conjunction with bit 0, causes OS X to maintain
     system state in memory and leave system power on until battery level
     drops below a near empty threshold (This enables quicker wakeup from mem-
     ory while battery power is available). Upon nearly emptying the battery,
     OS X shuts off all system power and hibernates; on wake the system will
     resume from hibernation image, not from memory.

     0000 1000 (bit 3) encourages the dynamic pager to page out inactive pages
     prior to hibernation, for a smaller memory footprint.

     0001 0000 (bit 4) encourages the dynamic pager to page out more aggres-
     sively prior to hibernation, for a smaller memory footprint.

     We do not recommend modifying hibernation settings. Any changes you make
     are not supported. If you choose to do so anyway, we recommend using one
     of these three settings. For your sake and mine, please don't use any-
     thing other 0, 3, or 25.

     hibernatemode = 0 (binary 0000) by default on supported desktops. The
     system will not back memory up to persistent storage. The system must
     wake from the contents of memory; the system will lose context on power
     loss. This is, historically, plain old sleep.

     hibernatemode = 3 (binary 0011) by default on supported portables. The
     system will store a copy of memory to persistent storage (the disk), and
     will power memory during sleep. The system will wake from memory, unless
     a power loss forces it to restore from disk image.

     hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The
     system will store a copy of memory to persistent storage (the disk), and
     will remove power to memory. The system will restore from disk image. If
     you want "hibernation" - slower sleeps, slower wakes, and better battery
     life, you should use this setting.

     Please note that hibernatefile may only point to a file located on the
     root volume.

ということは、hibernatemode=0にすればメモリイメージをディスクに書き出さなくなるということでは???

私のユースケース的には、バッテリで長時間スリープさせたいという需要もないのでデメリットないし。

ということで、

$ sudo pmset hibernatemode 0
$ sudo rm /var/vm/sleepimage

してみた。

ちゃんと検証したわけじゃないんですが、半日スリープさせておいても/var/vm/sleepimageが復活してなかったのでディスク書き込みは無効化されてるんじゃないでしょうか。バンザイ!成せば成る!!!