![]() |
Moving Swap to another partition, Leopard redux
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"?>Code:
<?xml version="1.0" encoding="UTF-8"?>Code:
ps -wax | grep dynamic_pager -m1Code:
ls -al /Volumes/Swap/.vmCode:
-rw------T 1 root wheel 163410000 12 Nov 15:55 swapfile0Code:
sudo rm -rf /var/vm/swapfile0Code:
grep Swap /var/log/system.log | tailCode:
Nov 16 10:59:32 localhost com.apple.dynamic_pager[40]: dynamic_pager: cannot create paging file /Volumes/Swap/.vm/swapfile0!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. |
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 |
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... |
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? |
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 :) |
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 :) |
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 |
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) |
Problem solved. When I created the Swap partition I made Owner/Group root/wheel. I changed this to root/admin and all is well.
|
My optimism was premature, for some reason I am back to square one :(
|
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 : ) |
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. |
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*What do you think? Is this a sensible way of moving the swap files, or have I overlooked any important aspect? |
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"?>Code:
#!/bin/bashI would love to get some feedback on this approach. |
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.
|
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 deniedRepairing 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. |
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. |
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.:) |
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? |
Quote:
Also, I'd like very much to know where you put dynamic_pager.plist when you removed it from LaunchDaemons[/i]. |
updates/experiences/tips
hi all,
first off, thanks for sharing because i don't think there is any other info on this topic (for leopard) anywhere else online. just curious if this solution has been working for all of you since the last post on the topic, and if there have been any improvements? it seems that this is one of those things that apple should really be making easy or at the very least documenting, which begs the question: does anyone know if os x server handles this because maybe there are already scripts or apps which might be officially supported and hence less likely to break on upgrades etc. regards, _c |
Hi polypus.
The solution that I posted in February has been working without a hitch. I have been keeping track of vm usage and the location of my swap files. The script reliably places them on my swap partition, even after software updates and restarts. If you do give it a try, please let me know how it works out for you. |
hello:
i am a beginner to mac's in general having switched over about 3 months ago. i was fortunate to get a great deal on a 20" Intel iMac. I tried to edit dynamic_pager.plist changing the default swap file location to: /Volumes/Data/swap/ (which is a external usb drive) but after rebooting i noticed that the folder "swap" was empty and my system seemed to slow down considerably. I am sure that i need to assign permissions to the folder to make this work but i do know how. I replaced the dynamic_pager.plist with a backup. Could some one give me step by step directions how to move my swap file to /Volumes/Data/swap ? i will need the correct commands as well to assign permissions to the folder as well. Thank you in advance. Rob F. |
Hi Rob,
Welcome to the Mac platform : ) Changing the swap volume in dynamic_pager.plist may not actually work because of the order in which the startup is executed. The dynamic pager will attempt to write swapfiles before your secondary drives and partitions are mounted. If it can't find the swap partition, it has the nasty habit of creating a fake one with the same name and using space on the main partition anyway. Take a look at my posts #14 and #17 in this thread. I use a different method to force my swapfile location. I haven't had any problems, and I have been using it this way since February. If you do give it a try, please let me know how it works out. - James - |
Swapfile success
E James:
If you're still checking in here: your method worked for me--thank you. The other methods described in this thread didn't (neither adrinux's or marcus's). As you know, the trick was to add your dynamic_pager_init file to guarantee the swap volume was mounted before trying to use it. Some people think that moving the swapfiles to another volume doesn't increase a Mac's speed, but that hasn't been my experience--my Mac (dual Mirrored Drive Doors 1.25 GHz G4, 2 gig RAM) is definitely faster, and that's even with the swapfiles being placed on a drive I haven't partitioned for a separate swap volume--the drive is a single volume, 300 gig, mostly full with other files, and it's pretty fragmented, and yet still I can load up dozens of web pages, and I'm not seeing nearly the slowdown I was before, even though I still have a similar number of swapfiles (10 at the moment--apparently some of the websites I view, use a lot of RAM). Now that I know your method works, I'm working on installing another drive, partitioned with a 15 gig volume as the first volume, and putting the swapfiles there, since the first volume on a drive is generally the fastest, due to its location on the drive (starting at the innermost location on the drive's platters). I've been trying to move the swapfiles for some time, with no consistent success. Your method has been working for me for several days, through several restarts. Thanks again. |
johnsawyercjs,
Thank you for the note. This thread doesn't get a lot of traffic; it seems that very few Mac users feel compelled to move their swap partition. I'm happy to hear that it is working for you. I've been using this setup for almost a year now, and I haven't had a problem yet. Here's hoping that the same method works in Snow Leopard. Good idea about setting the swap partition as the first volume. I haven't made it that far down the speed optimization path, but it sounds like something to look into. A dedicated solid-state drive would be an attractive option as well, once the prices become a little more bearable. Good luck with your setup, and please let me know if anything doesn't work out. |
RE: swapfile success
I like to post to threads no matter how old they are, even though the moderators sometimes give me a hard time about it (they prefer for users to start new threads, instead of posting to existing ones that are even just a few months old). I see useful threads, of whatever age, as reference articles that others throughout the world refer to, by finding them, as I do, using search engines, at least just to read, and if there's something that can be added, all the better to expand the thread's usefulness. But I agree that very few Mac users want to move their swap partition--not many are even slightly technically inclined to do anything like that, judging by my experience working with thousands of Mac clients for the past 23 years.
I've also been speculating about putting the swapfiles onto a dedicated SSD, but as you say, prices are still a little high to justify that. I could see putting them onto an external, USB flash drive, since it's a lot cheaper, but only if one were using a latest-model Mac, since Apple optimized (or maybe "fixed") their USB ports to increase their speed noticeably, more in line with the speed of USB ports in PCs. I'll let you know about any relevant problems or further observations. |
E_James,
I would also like to thank you for posting this solution. I'm running OSX on an 8GB SSD drive until my 32GB arrives, and needed to move my swap file off to a flash drive in the meantime. This worked perfectly! |
Xupport utility , and does my plan sound good to you?
Hi all,
I wondered if any knowledgeable folks here can excuse my ignorance and offer some advice:
So yeah, the swap files have to be on the first volume. I'm thinking of cloning my disk to a second partition, checking if ok, (i’ve already backed up to external drive) then wiping the first partition (where everything used to be) and splitting it in two, setting the first half to 16GB , which will be my swap volume. This will leave me with 3 partitions altogether, the first as the swap volume, the 2nd blank and with the OS and apps on the 3rd. My questions are: -Is this a good plan and is it worth the trouble? I use my Macbook Pro (2.2GHz core2duo, 4GB RAM) sometimes quite intensively, working on large files with Adobe apps, Music software, some video editing, etc... and i want to get the best possible performance from my machine. Will the increase in performance be noticeable if i did this? - Will this move mess up the activation/registration on Adobe & other software? -In this scheme, should i use the 2nd partition as a scratch disk for Adobe , Final Cut, etc ? PS This is what Adobe has to say in Photoshop help: Thanks! |
So in the end were you guys successful?
I am considering submitting a hint to partition internal HD's into 2 partitions. Then applying one partition from each internal drive into a Stripe RAID set and using that as SWAP space. In Phtoshop its doable but can it be done reliably with system swap space? Mano |
I would suggest that for all but the most hardcore power users and a few special cases, creating a swap partition is probably not worth the potential problems that it may cause you.
It's just so 1980s. |
Too bad. I was considering Repartitioning my internal drives to have 4x100GB drives striped for the SWAP. It solves the problem of not having data integrity because the rest of the partitions on the drives are not in RAID just the part for SWAP.
I guess I could always just use the RAID SWAP for Photoshop and other software that allows you to select the drive to use for SWAP. It just would have been allot more fun if the whole system SWAP was on a little RAID like that. |
I'm wondering, has anyone tested this setup on Snow Leopard yet?
I just got my OptiBay from MCETech in with an SSD I ordered somewhere else and was planning to install it tnoight, with Snow Leopard of course. This immediately raised the question of the swap files and started Google'ing around some 'till I found this thread which seams to be the only comprehensive one. I had a look at com.apple.dynamic_pager.plist in SL but it is in some compressed form basically spawning lots of garbage and a few recognizable lines but I doubt editing it just like that is a good idea. Anyone got a clue as how this tale goes in Snow Leopard? |
I haven't been able to get it to work in Snow Leopard so far.
I opened a question on SuperUser, but no one has posted a solution. |
In the end, the same solution works perfectly in Snow Leopard, as long as you convert com.apple.dynamic_pager.plist from binary to plain XML before editing it, and then from plain XML back to binary when finished.
I have posted the entire procedure in the SuperUser question, but here is the relavant portion (the plist file conversion): Code:
sudo plutil -convert xml1 com.apple.dynamic_pager.plist |
E James
Thanks for the knowledge sharing. I have been struggling with ram increased needs and VM and SWAP. Can I ask you tho, once this has been done how will i tell were in fact the .vm file/folder is? I have preformed the steps posted in #14 and #17 confirmed as stated in these posts and everything plays out as you say. Now after a few restarts I seem to not have either a .VM file or any SWAP files. Top shows 11g of vm with 350mg in use but I do not see anything in either the old location /var/vm/ or the new /Volumes/swap/ . Any thoughts? Will it build as it needs. Any ways again thanks for sharing |
Quote:
Have a look in the Console app to see if there are repeated messages about "throttling dynamic_pager". If this is the case, there is something wrong with the way things are set up, and launchd is unable to load the dynamic pager. Double-check that all of the files have been properly modified and that the permissions are correct. Note: if you are running Snow Leopard (10.6) be sure to use the instructions in the link I recently posted (#35). |
Thank you very much E_James and all who contributed over the years.
Taking the info from threads on this topic, I came up with the attached script. I have not done any real life testing yet and am glad for any reports. Also I'd like to be clear that this is mainly intended for better security and easier system maintenance rather than performance benefits. Presumably you would get speed increase if the swap volume is attached to a separate bus from the volume on which your data is. features: option to have encrypted swap (looks for $ENCRYPTSWAP which has hopefully been set beforehand) times out and falls back to default after settable amount of retries checks if there is a duplicate volume i.e. "/Volumes/Swap 1" -> falls back to default flushes swap, then launches dynamic_pager checks and outputs finding about where swap is exits with exit-code of /sbin/dynamic_pager (all extra output can be muted) Code:
#!/bin/sh |
changed swap location did not resolve memory issue
I used Xupport to change swap location. A ps -ef reveals:
/sbin/dynamic_pager -F /Volumes/3TB/.vm/swapfile I confirmed that there are many "swapfile*" in the 3TB drive (over 60 swapfiles) and there is nothing in the /var/vm directory. The offending application is using 27.68GB real memory and 76.15GB virtual memory. this is a MacPro 2xQuad core Xeon, OSX 10.5.8. My startup disk has 240/300GB free, I have 32 GB RAM and a second 7200 3Gbit/s SATA drive with 3TB and yet i continue to get the "Your Mac OS X startup disk has no more space ..." message. How is this possible? |
| All times are GMT -5. The time now is 05:45 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.