|
|
#1 |
|
Registered User
Join Date: Nov 2007
Posts: 2
|
I was going to submit this as a tip, but it could really do with more testing, and probably more work.
Those of us who used a previous tip to move swap to a different partition http: //www.macosxhints.com/article.php?story=20050601094611565&query=move%2Bswap have found ourselves scratching our heads in Leopard, we can't modify /etc/rc because it doesn't exist any more! So now we have to use Launchd. Swapfiles in OSX are written by dynamic_pager and there's a launchd plist from that in the system folder: /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist It defines the default swap location /var/vm, and we can change that to use our prefered swap partition. Personally I also dislike the exponentially increasing swapfile size Tiger and Leopard use (64, 128, 256, 512, 1024 MB and so on), so I also define a set size swapfile (156MB, remember Panther used 80MB by default) by passing command line options in the plist. My /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist ends up looking like this: Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.dynamic_pager</string>
<key>ProgramArguments</key>
<array>
<string>/sbin/dynamic_pager</string>
<string>-F</string>
<string>/Volumes/Swap/.vm/swapfile</string>
<string>-H</string>
<string>10000000</string>
<string>-L</string>
<string>183000000</string>
<string>-S</string>
<string>163410000</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.dynamic_pager</string>
<key>ProgramArguments</key>
<array>
<string>/sbin/dynamic_pager</string>
<string>-F</string>
<string>/Volumes/Swap/.vm/swapfile</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
Code:
ps -wax | grep dynamic_pager -m1 Code:
ls -al /Volumes/Swap/.vm Code:
-rw------T 1 root wheel 163410000 12 Nov 15:55 swapfile0 Code:
sudo rm -rf /var/vm/swapfile0 Code:
grep Swap /var/log/system.log | tail Code:
Nov 16 10:59:32 localhost com.apple.dynamic_pager[40]: dynamic_pager: cannot create paging file /Volumes/Swap/.vm/swapfile0! Nov 16 10:59:32 localhost com.apple.launchd[1] (com.apple.dynamic_pager[40]): Exited with exit code: 1 Nov 16 10:59:32 localhost com.apple.launchd[1] (com.apple.dynamic_pager): Throttling respawn: Will start in 7 seconds Nov 16 10:59:33 localhost /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow[34]: Login Window Application Started Nov 16 10:59:34 localhost com.apple.launchd[1] (com.apple.dynamic_pager): Throttling respawn: Will start in 5 seconds Nov 16 10:59:34: --- last message repeated 1 time --- Nov 16 10:59:34 localhost kextd[10]: writing kernel link data to /var/run/mach.sym Nov 16 10:59:34 localhost com.apple.launchd[1] (com.apple.dynamic_pager): Throttling respawn: Will start in 4 seconds Notes
I do however feel like this could be a little more robust. Cleaning up old swapfiles in the original location should be automatic. It might be better to wait for the swap partition to mount before running dynamic pager. In theory it should be possible to write a script for this, and create a launchd plist to run the script, and we could disable the dynamic_pager.plist. But because this just works, I'm not so motivated to do further work ![]() * The benefit of moving swap to a different disk partition has been debated before, so please keep your comments useful, we really don't need yet another 'why bother' comment thread :P Hope this helps and I look forward to seeing how other people have dealt with this. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2007
Posts: 1
|
Thank you very much for this. We have several 2.66 MacPros that are going to get upgraded to Leopard. One of our test machines (2.66, 3GB RAM) was crawling to a halt while running several intensive applications, ie. Photoshop, Illustrator, Parallels running Rhino, and a few others. This machine ran just fine in Tiger.
I formatted a 120GB SATA drive, named it Swap, and then used terminal to create a .vm folder on that volume. I changed the .plist to point to the new volume. Things seem to be all well and the system is running at what feels like a normal pace. It is also using more swap space overall, which is fine since it has 109GB of formatted drive space to fill if needed (not likely, but...). Anyhow, after less than a day of testing I would say that things seem fine. I would also say the question of if this works on a intel has been answered. Carl |
|
|
|
|
|
#3 |
|
Registered User
Join Date: Nov 2007
Posts: 2
|
You're welcome
![]() Just answered another of my questions. Opened up my G4 and pulled out the power cable to the disk with my swap partition on. It started up fine - but with no swap! system.log showed launchd repeatedly trying to start dynamic_pager which obviously couldn't find the swap partition, so it just kept re-spawning ad infinitum. Personally I'm happy with this as is. I monitor all my partitions current sizes on the desktop with geektool, so it'd be pretty obvious to me that swap had gone awol before anything went wrong. Maybe I'll get around to putting together a script eventually... |
|
|
|
|
|
#4 |
|
Prospect
Join Date: Nov 2007
Posts: 2
|
Hi,
I tried your method (Mac OS X Leopard 10.5.1 on Power Mac G5 2x2 GHz with two SATA disks) and it seemed to work fine at first. I say "it seemed at first" because in fact the virtual memory was still located on the same disk (Macintosh HD) althoug on a different mount point, labelled exactly like the GUI name of my second partition! I have two separated disks in my Power Mac, each with one journaled HFS+ partition: - The partition of the first disk is named Macintosh HD and has Leopard on it. - The partition of the second disk is named Data. So in the file /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist instead of the line <string>/private/var/vm/swapfile</string> I wrote <string>/Volumes/Data/.vm/swapfile</string> Of course after making the .vm folder on Data. I was careful enough to give correct permissions on the partition Data, the directory .vm and the file com.apple.dynamic_pager.plist. I even auto corrected permissions with Disk Utility before restarting my Mac. After reboot, Terminal told me everything was fine from launchd process to swapfile0 creation in the new location. BUT! Although the name of my second disk still appeared as "Data" in Finder, the name had changed to "Data 1" in Terminal and Disk Utility, and for all System calls. The .vm folder I created on it did not contained any swapfile. I went to /Volumes/ and I saw why. A new mount point named "Data" had been automatically created in the form of a folder containing a new .vm directory, on the first disk Macintosh HD. So it seemed instead of re-spawning, waiting for the Data partition to mount, my Leopard decided to create this mount point on my boot volume. I tried to correct the problem by trashing the false Data mount point, renaming correctly my partition back from "Data 1" to "Data" and assigning a fix mount point and fix mount name for it with its UUID in /etc/fstab. The result was a partition keeping its correct name "Data" after reboot, and no new weird mount point creation anymore. But the Virtual Memory is now disabled. None swapfile is made inside /Volumes/Data/.vm/ although Terminal says everything is fine (dynamic_pager, launchd, system.log). No re-spawing, and a ps -wax | grep dynamic_pager -ml shows the good location where the swap files should be written. If I go back to the default setup (aka /private/var/vm/) the virtual memory works fine again. Do you have any idea about what's going on? |
|
|
|
|
|
#5 |
|
Prospect
Join Date: Nov 2007
Posts: 2
|
Nevermind, It works now.
I have launched the uninstall command of the Perl script swapfile.pl (from Dave Bayer) that I installed previously in Tiger before upgrading to Leopard. Perhaps the AutomountDisksWithoutUserLogin interfered with the Leopard method. While rebooting I zapped the PRAM four times (Command-alt-P-R). I don't know which one made the tip work, but now it works
|
|
|
|
|
|
#6 |
|
Registered User
Join Date: Nov 2007
Posts: 2
|
Glad you got it sorted, I'd say it probably was the old script causing issues...keep an eye on things though
![]() I've got three IDE disks in my G4, it's had to see why the IDA/SATA difference would cause problems though. I always assume having journaling switched on in my swap partition is a bad idea. But then I'm using a separate 5Gi partition purely for swap (on a disk that's used for little else). I also disable spotlight indexing on the swap partition, since it's pointless. Good point about permissions on the new swap location! Since I was just pointing Leopard to the same location I was using in Tiger I didn't have to think about that
|
|
|
|
|
|
#7 |
|
Prospect
Join Date: Dec 2007
Posts: 4
|
I have managed to do this on my Mac Pro with two Seagate SATA drives, but I have only been partially successful. I created a swap partition (called Swap) on the second drive but when I do a cold startup it would seem that this volume isn't mounted soon enough for it to be used as the swap partition, resulting in /Volumes containing an alias to "Swap 1" and a Folder containing the swap file on the boot drive.
If I perform a restart, everything works perfectly,except I now have to delete the folder from /Volumes. This is 100% repeatable and I have even tried changing the physical locations of the two drives. Any ideas? Adrian |
|
|
|
|
|
#8 |
|
Registered User
Join Date: Dec 2007
Posts: 1
|
The same thing is happening to me as well... "Swap 1" is created as partition "Swap" is not mounted at the point dynamic_pager is ran...
I wrote about it couple of weeks ago, but my post never got published... (hopefully this one will. i may be doing something wrong while posting) |
|
|
|
|
|
#9 |
|
Prospect
Join Date: Dec 2007
Posts: 4
|
Problem solved. When I created the Swap partition I made Owner/Group root/wheel. I changed this to root/admin and all is well.
|
|
|
|
|
|
#10 |
|
Prospect
Join Date: Dec 2007
Posts: 4
|
My optimism was premature, for some reason I am back to square one
|
|
|
|
|
|
#11 |
|
Registered User
Join Date: Jan 2008
Posts: 1
|
Move swap to a flash device?
Does anyone think it would be beneficial to move the swap to a USB stick? I've been looking for ways to speed up my iBook G4 (with Leopard), and I was thinking about using this method to place the swap on something small and portable (and hopefully fast)...
I'll give this a try asap : ) |
|
|
|
|
|
#12 |
|
Prospect
Join Date: Jan 2008
Location: Göteborg, Sweden
Posts: 3
|
Actually, I think the issue is in fact NOT that the dedicated swap volume is not yet mounted at the point of dynamic_pager starting up. Rather, the issue is that the mount point directory in '/Volumes/' fails to unmount, or being removed properly, at shutdown.
I've got a separate ATA/100 drive hooked up inside my Powermac G4 MDD, in addition to the main OS drive which sits on a SATA bus (PCI-controller). I've created a 4 GiB volume on the ATA100-drive, and named it "swap". If I do not attempt to change the swap directory at all, i.e. leaving the dynamic_pager.plist unmodified, this volume mounts as '/Volumes/swap' as intended. If I then go ahead and change the swap directory path to '/Volumes/swap/vm/swapfile', everything works after the _first_ subsequent boot process. The swap volume mounts at '/Volumes/swap' with the swapfiles on it. No '/Volumes/swap 1' exists at this point. However, if I reboot once more, the swap volume will mount at '/Volumes/swap 1' instead, and the swapfiles are placed in a regular directory at '/Volumes/swap', and not on the dedicated swap volume. What I think is happening, is that the '/Volumes/swap' mountpoint is not cleared out of the way properly at shutdown, thus forcing the swap volume to mount as "swap 1" ever thereafter. If I manually remove the '/Volumes/swap' directory before rebooting, everything gets setup properly after reboot, with the swapfiles on the swap volume mounted at '/Volumes/swap' and there is no "swap 1" in sight. |
|
|
|
|
|
#13 |
|
Prospect
Join Date: Jan 2008
Location: Göteborg, Sweden
Posts: 3
|
Okay, I tried something else. I removed the dynamic_pager property list from '/System/Library/LaunchDaemons/', to avoid launchd from intefering with the process in any way.
Then I added these two lines to 'rc.common', way down at the end of the file to make it execute as late as possible. Code:
rm /Volumes/swap/vm/swapfile* dynamic_pager -F /Volumes/swap/vm/swapfile What do you think? Is this a sensible way of moving the swap files, or have I overlooked any important aspect? |
|
|
|
|
|
#14 |
|
Prospect
Join Date: Feb 2008
Posts: 11
|
After a little research and experimentation, here is my solution:
I modified the 'com.apple.dynamic_pager.plist' file so that it launches a shell script '/sbin/dynamic_pager_init' instead of simply launching '/sbin/dynamic_pager'. The shell script will not launch the dynamic_pager until the swap volume has mounted properly. This solution makes use of the fact that the Apple's launchd process will keep executing the dynamic_pager_init script every 2 - 10 seconds until the dynamic_pager is running. /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist: Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.dynamic_pager</string>
<key>ProgramArguments</key>
<array>
<string>/sbin/dynamic_pager_init</string>
</array>
<key>OnDemand</key>
<false/>
</dict>
</plist>
Code:
#!/bin/bash
#launch Apple's dynamic_pager only when the swap volume is mounted
if [ "x`df -H | grep /Volumes/Swap`" = "x" ]; then
echo "Waiting for Swap volume to mount";
else
echo "Launching dynamic pager on volume Swap";
/sbin/dynamic_pager -F /Volumes/Swap/.vm/swapfile;
fi
I would love to get some feedback on this approach. |
|
|
|
|
|
#15 |
|
Prospect
Join Date: Feb 2008
Posts: 3
|
E James: You may want to have a way for your setup to "fail gracefully"-- After ten attempts or 30 seconds or so, give up and let dynamic_pager load under its default settings.
|
|
|
|
|
|
#16 |
|
Prospect
Join Date: Feb 2008
Posts: 3
|
Well, I tried it out anyway, and my fears were confirmed. I keep getting this in the system log:
Code:
com.apple.launchd[1] (com.apple.dynamic_pager[446]): posix_spawnp("/sbin/dynamic_pager_init", ...): Permission denied
com.apple.launchd[1] (com.apple.dynamic_pager[446]): Exited with exit code: 1
com.apple.launchd[1] (com.apple.dynamic_pager): Throttling respawn: Will start in 10 seconds
Repairing permissions in Disk Utility doesn't help (although it does fix com.apple.dynamic_pager.plist). I've tried changing permissions in Get Info and with chmod in Terminal, but I have little idea of what I'm doing there. |
|
|
|
|
|
#17 |
|
Prospect
Join Date: Feb 2008
Posts: 11
|
Thank you. I should have made a note of the permissions on that 'dynamic_pager_init' file.
Just execute the following two commands in a terminal window. You will be asked for your password because of the 'sudo' command. sudo chmod a+x-w /sbin/dynamic_pager_initThe first command (chmod) adds the 'execute' permission (+x) to the file so that it can be run as a command, and removes the 'write' permission (-w) so that it can not be edited accidentally. The second command (chown) makes 'root' the owner of the file, and makes 'wheel' its group. This matches most of the other daemons and scripts in the '/sbin' directory. You can verify that the file has been set up properly by typing the following: ls -al /sbin/dynamic_pager_initWhich should return something like: -r-xr-xr-x 1 root wheel 281 19 Feb 01:38 dynamic_pager_initI hope that helps. Please let me know if you run into any more difficulties. |
|
|
|
|
|
#18 |
|
Prospect
Join Date: Feb 2008
Posts: 3
|
Sorry I took so long to respond; I got sidetracked with other things shortly after I made those responses.
Anyway, I got it to work after a struggle. Apparently you can't just make dynamic_pager_init in TextEdit, use Onyx to make Finder show hidden/system items, move D_P_I over to /sbin and change the permissions/owner. Doing that leaves the file with a "@" in the permissions, like this: -r-xr-xr-x@ 1 root wheel 281 19 Feb 01:38 dynamic_pager_initI haven't been able to find out what that means, except that it indicates something that prevents the file from being found: 2008.03.06 08:26:37p com.apple.launchd[1] (com.apple.dynamic_pager[671]) posix_spawnp("/sbin/dynamic_pager_init", ...): No such file or directoryI got around that by creating D_P_I directly in /sbin with pico, and then changing permissions/owner as you specified. All is well, for the moment. Thank you.
Last edited by Anonymous Prime; 03-06-2008 at 09:02 PM. |
|
|
|
|
|
#19 |
|
Prospect
Join Date: Feb 2008
Posts: 11
|
Glad to hear that it is working for you, now!
![]() The "@" symbol in the file permissions has something to do with access control lists (ACLs), which control extended privilege settings. I'm not sure why that would prevent you from finding the initialization script. Perhaps one of those settings prevents spotlight from indexing the file? |
|
|
|
|
|
#20 | |||||||||||||||||||||||
|
Prospect
Join Date: Mar 2008
Posts: 3
|
Very interested in how this turned out - Marcus, can you update? Any glitches or work-arounds you've had to deal with? Also, I'd like very much to know where you put dynamic_pager.plist when you removed it from LaunchDaemons[/i]. |
|||||||||||||||||||||||
|
|
|
![]() |
|
|