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)

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.