The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Moving Swap to another partition, Leopard redux (http://hintsforums.macworld.com/showthread.php?t=81586)

adrinux 11-19-2007 06:34 AM

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"?>
<!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>

WARNING If you're thinking of changing those numbers please read 'man dynamic_pager' first and note the requirements for the relative sizes of those three numbers. If you just want to move swap you can leave those command line options out:
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>

After rebooting we can check where swapfiles are now being written:
Code:

ps -wax | grep dynamic_pager -m1
And check the size:
Code:

ls -al /Volumes/Swap/.vm
which gives this in my case:
Code:

-rw------T  1 root    wheel  163410000 12 Nov 15:55 swapfile0
So I manually cleaned out the old swapfile:
Code:

sudo rm -rf /var/vm/swapfile0
I also checked the logs:
Code:

grep Swap /var/log/system.log | tail
Which gives:
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

What this tells us is that the problem with with the swap partition not being mounted when dynamic_pager is first launched still exists in Leopard, however launchd simply respawns dynamic_pager in 8-10 seconds and the swap partition is found.

Notes
  • I've only tested this on a powerpc machine, however I don't see why this wouldn't work just as well on an intel mac, YMMV, be warned, make a backup etc.
  • I been using this for several days, it works fine across normal restarts and shutdowns.
  • I haven't tested if it works after a forced reboot, for obvious reasons.
  • I have worries about what would happen if the swap partition failed to mount, due to disk failure for instance. Again, I'm reluctant to disconect the disk to see what happens, maybe someone else can test that :D It should be fine if dynamic_pager has a hard coded default, IIRC from Tiger, it does.

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.

cmdavis3rd 11-20-2007 10:47 AM

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

adrinux 11-21-2007 09:36 AM

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...

tokamac 11-29-2007 12:05 PM

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?

tokamac 11-30-2007 09:24 AM

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 :)

adrinux 12-02-2007 08:46 AM

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 :)

adrianchapman 12-13-2007 11:40 AM

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

nihad 12-13-2007 12:46 PM

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)

adrianchapman 01-02-2008 07:47 AM

Problem solved. When I created the Swap partition I made Owner/Group root/wheel. I changed this to root/admin and all is well.

adrianchapman 01-03-2008 04:40 AM

My optimism was premature, for some reason I am back to square one :(

walk_n_wind 01-17-2008 07:35 PM

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 : )

marcushedenstrom 01-26-2008 11:51 AM

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.

marcushedenstrom 01-26-2008 04:26 PM

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

And hey, it works!! I've rebooted numerous times, and every single time I end up with "swap" properly mounted, with one initial swapfile created on it. Having two gigs of memory in this machine, I'll have to wait and see if more swapfiles are created as they become nessecary. But I assume they will.

What do you think? Is this a sensible way of moving the swap files, or have I overlooked any important aspect?

E_James 02-19-2008 03:07 AM

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>

/sbin/dynamic_pager_init:
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 am relatively new to shell scripting and unix commands, so there may be better ways of implementing the shell script. I have a feeling that 'df -H | grep...' command is not the most efficient solution, but it does work on my system.

I would love to get some feedback on this approach.

Anonymous Prime 02-25-2008 07:28 PM

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.

Anonymous Prime 02-25-2008 11:21 PM

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

It just keeps doing that every 10 seconds, until I replace com.apple.dynamic_pager.plist with the original, repair permissions, and restart.

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.

E_James 02-28-2008 01:04 AM

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_init
sudo chown root:wheel /sbin/dynamic_pager_init
The 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_init
Which should return something like:
-r-xr-xr-x 1 root wheel 281 19 Feb 01:38 dynamic_pager_init
I hope that helps. Please let me know if you run into any more difficulties.

Anonymous Prime 03-06-2008 08:58 PM

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_init
I 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 directory
I 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.:)

E_James 03-07-2008 02:55 AM

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?

chmood 03-22-2008 01:31 PM

Quote:

Originally Posted by marcushedenstrom (Post 445912)
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


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].

polypus 05-16-2008 05:39 PM

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

E_James 05-21-2008 12:56 PM

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.

Rob F 10-12-2008 10:09 PM

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.

E_James 10-14-2008 02:18 AM

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 -

johnsawyercjs 02-09-2009 03:20 AM

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.

E_James 02-09-2009 03:37 AM

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.

johnsawyercjs 02-09-2009 04:04 AM

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.

clayhinson 03-18-2009 12:25 AM

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!

Panoramix 05-02-2009 07:34 AM

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:


The utility Xupport (www.xupport.ch) seems pretty good, and offers the option to change the location of the virtual memory swap files to a different volume, citing performance benefits:

• Virtual Memory Optimizer:

• Change the swap files location
• In Mac OS X the virtual memory information are stored in the so called "Swapfiles". Because the swapfiles are the most interactive system files, it makes sense to put them on a separate partition. It is recommended to store the swap files on the first partition of your fastest internal hard disk. The recommended minimum partition size should be about 3 or 4 times lager than the physical built-in memory size (e.g 1 GB physical memory = 4 GB swap partition).
• Recommendations and instructions for an optimal system performance:

• 1.Re-partition your hard disk with a swap volume as FIRST partition (using the Mac OS X Install DVD).
• WARNING: RE-PARTITIONING A HARD DISK WILL ERASE ALL EXISTING DATA!
• 2.Restore your system data or install new system on the system partition.
• 3.Boot from the system partition.
• 4.If you want your swap volume to be invisible to the Finder:
• • Launch Xupport and choose "Settings"
• • Enable "Show hidden files and folders" and restart the Finder
• • Rename the swap volume from "swap" to ".swap" (The dot makes it invisible to the Finder)
• • Disable "Show hidden files and folders" and restart the Finder again
• 5.Select the new swap partition under "Swap Storage Volume". Then, press the "Set" button to apply the new swap file location settings (Restart required).



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:

• The following guidelines can help you assign scratch disks:

• For best performance, scratch disks should be on a different drive than any large files you are editing.
• Scratch disks should be on a different drive than the one used for virtual memory.
• RAID disks/disk arrays are good choices for dedicated scratch disk volumes.
• Drives with scratch disks should be defragmented regularly.
Thanks!

MVasilakis 09-02-2009 10:04 AM

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

benwiggy 09-02-2009 11:42 AM

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.

MVasilakis 09-02-2009 12:54 PM

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.

daenney 09-03-2009 09:06 AM

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?

E_James 09-16-2009 12:55 PM

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.

E_James 09-18-2009 04:58 PM

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
...
sudo plutil -convert binary1 com.apple.dynamic_pager.plist


frankbonatelli 10-06-2009 10:26 AM

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

E_James 10-06-2009 01:07 PM

Quote:

Originally Posted by frankbonatelli (Post 556063)
...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?

frankbonatelli:

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).

SwissalpS 11-24-2009 03:15 PM

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
# this script is designed to alternate the default behavior of
# /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
# thus it's owner must be root and run by root to work
# requires OS X 10.5.x (or 10.6.x if you save plist as binary after changing)
#
# Author: SwissalpS@LukeZimmermann.com
# Version: 20091124_162425
# Copyright: public domain
# Thanks to hundreds of postings on macosxhints.com that have accumulated over
# the years and have helped me do this since OS X 10.3 (when it was a lot more
# complicated than after OS X 10.5 imho)
# It would be useless to list all the links of all the posts I read to get to
# this point, so here just two
# http://www.macosxhints.com/article.p...50601094611565
# http://forums.macosxhints.com/showthread.php?p=452409
#
# WARNING: I am not responsible for any damage you make to your system.
#                Don't apply this to machines of users who don't have a certain flair
#                for this kind of 'low-level' system modification. User should be
#                experienced enough to save himself should something go wrong.
#
# HOW TO: edit then copy this script to a location on boot volume
#        make it executable
#        also owner and group should match those of /sbin/dynamic_pager
#        backup /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
#        edit with Property List Editor.app for simplicity sake
#        change the first argument of ProgramArguments from /sbin/dynamic_pager
#        to /path/to/this/script
#        remove the last two arguments i.e. -F and /private/var/vm/swapfile
#        save the .plist (on OS X 10.6.x make sure you save as binary)
#        make sure the permissions are same as original
#
# HINT: to convert binary plist to xml
#        sudo plutil -convert xml1 com.apple.dynamic_pager.plist
# and back to binary
#        sudo plutil -convert xml1 com.apple.dynamic_pager.plist

# max retries
export MAX_RETRIES=10;

# interval between tries in seconds
export RETRY_INTERVAL=10;

# be verbose '-TRUE-', anything else silences output
export AM_VERBOSE='-TRUE-';

# set drive label
export SWAP_VOLUME='.SwapA';

# set full path to vm directory
export SWAP_DIRECTORY="/Volumes/$SWAP_VOLUME/.vm";

###############################################################################
# no more changes required bellow this point.
# if you do need to change bellow, please email the author about it and post on macosxhints.com

# init counter
export COUNT_ATTEMPTS=0;

# set encryption option
if [ ${ENCRYPTSWAP:=-NO-} = '-YES-' ]; then

        export ENCRYPTION_OPTION='-E ';

else

        export ENCRYPTION_OPTION='';

fi;


echo_if_verbose() {

        if [ '-TRUE-' = "$AM_VERBOSE" ]; then

                echo $@;

        fi;

}


launch_with_default_value() {

        echo_if_verbose 'launching dynamic_pager with default setting';

        /sbin/dynamic_pager ${ENCRYPTION_OPTION}-F /private/var/vm/swapfile;

}


launch_with_my_value() {

        echo_if_verbose "Launching dynamic pager on volume $SWAP_VOLUME to directory $SWAP_DIRECTORY";

        /sbin/dynamic_pager ${ENCRYPTION_OPTION}-F "$SWAP_DIRECTORY/swapfile";

}


flush_swap() {

        if [ -d "$SWAP_DIRECTORY" ]; then

                echo_if_verbose 'flushing old swap';

                rm -rdf "$SWAP_DIRECTORY";

        fi;

        echo_if_verbose 'creating vm dir with 755 permissions';

        mkdir -p -m 755 "$SWAP_DIRECTORY";

        echo_if_verbose 'making sure owner and group are correct';

        chown root:wheel "$SWAP_DIRECTORY";

}


check_ps() {

                # check if done ok
                # --> good if found 1
                export CHECK_OK=`ps -wax | grep -c "[0123456789] /sbin/dynamic_pager $ENCRYPTION_OPTION-F $SWAP_DIRECTORY/swapfile"`;

                # --> bad if found --> default location
                export CHECK_BAD=`ps -wax | grep -c "[0123456789] /sbin/dynamic_pager $ENCRYPTION_OPTION-F /private/var/vm/swapfile"`;

                if [ 1 -eq $CHECK_OK ]; then

                        echo_if_verbose 'swap seems to be used in correct location.';

                fi;

                if [ 0 -lt $CHECK_BAD ]; then

                        echo_if_verbose 'oops, swap is at default location in /private/var/vm/swapfile.';

                fi;
}


# loop until we have launched pager or timed out
while [ $MAX_RETRIES -gt  $COUNT_ATTEMPTS ]; do

        # increment counter
        let COUNT_ATTEMPTS++;
        echo_if_verbose "attempt No: $COUNT_ATTEMPTS";

        # check if swap partition/volume has mounted
        export COUNT_VOLUMES=`mount | grep -c "/Volumes/$SWAP_VOLUME ("`;

        # check duplicate mount
        export COUNT_DUP=`mount | grep -c "/Volumes/$SWAP_VOLUME 1"`;

        if [ 0 -lt $COUNT_DUP ]; then

                echo_if_verbose 'double trouble! Fix manually from rescue partition.';

                launch_with_default_value;

                exit $?;

        elif [ 1 -eq $COUNT_VOLUMES ]; then

                echo_if_verbose 'one mounted, good :-)';

                flush_swap;

                launch_with_my_value;

                export LAUNCH_RESULT=$?;

                check_ps;

                # let launchd know dynamic_pager's exit code
                exit $LAUNCH_RESULT;

        fi;

        echo_if_verbose 'waiting for Swap partition to be [checked and] mounted...';

        sleep $RETRY_INTERVAL;

done;

echo_if_verbose "maxtries: $MAX_RETRIES  counter: $COUNT_ATTEMPTS";

# retried often enough, fall back to default: what the original .plist was commanding...
echo_if_verbose 'timed out, reverting to default location';

launch_with_default_value;

again: this code must still prove itself under rl stress situation. Reports are welcome.

wbsimey 04-21-2011 02:55 PM

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.