Create and use a swapfile on another disk

I have an 8TB Thunderbolt external drive that I now use

as my boot/system/everything drive. My system is much

faster now even if I am doing video editing etc on it ... it's

pretty amazing.


Since I no longer use the internal 1 TB drive I thought I

would play around with it and try to find a use for it. What

I wanted to do is to create a swap file and configure the

kernel to use it instead of also trying to swap to my

Thunderbolt disk, even though the system does not seem

slow swapping to Thunderbolt.


Typically on a UNIX system, from experience, this is done by

creating a swap file though some means like mkswapfile or

something, and then issuing a command such as swapon to

get the system to recognize and use it. Then when you got

it where you want it and it is working, you put a command or

edit the command already in the rc files to reconfigure your

machine -- of course after backing up the initial files so you

can get back to normal if desired.


However, OSX always throws me for a UNIX loop because it

is so different and so not well documented ... at least as far

as I can find any good documentation on Mac UNIX.


Can anyone help me or point me to some good docs on this

or a good book please?

iMac, OS X Mountain Lion (10.8.2), 24 inch

Posted on Sep 30, 2013 7:32 PM

Reply
16 replies

Oct 1, 2013 1:26 PM in response to nbar

nbar > There are better uses for this drive then using it for your swap space.


Such as?


I admit this is more or less of an experiment. Normally I would keep the system disk internally and add the ThunderBolt drive as the user partition, but since it is so amazingly much faster I don't think that is a win, in any case I am just trying to test it. If I am getting swapping, and I am at times, then if the swapping does not go over the ThunderBolt it would theoretically anyway free up I/O to that disk.


nbar > You will always have a swap file generated upon boot even if you have no page-outs.


That is correct as I understand MacOS.


I envision the solution as consisting of a script I can run after boot that creates or detects a swapfile on my internal drive, turns on swapping to it, stops swapping to the external system drive, and if necessary deletes the swapfile on the external system drive. This used to be really easy in systems like IRIX or Solaris and even Linux.


Swapping has changed a lot in UNIX. It used to be you needed a full partition on your disk as swap, then systems began to be able to swap to files. This should be easier than ever before, but thanks to most computer companies things are instead getting harder to do in the name of "helping" the customers, or making support easier. UNIX has pretty much been ruined by too much designed in complexity and obfuscation and not enough documentation.


michael black > If your device is not swapping to disc in the first place, than having a bigger and/or faster swap area is truly pointless.


Michael, whether what I want to do is pointless or not, if you do not know how, it's fine, you don't need to reply, right? If you want to add value to your reply instead of just being negative you might talk about how to measure this. Clearly the question is about "if or when" the system begins to swap, not about whether it is or not.


--


Maybe I am too sensitive to some of these answers because a long time ago in a galaxy far away I used to do system, network and customer support and when peolpe got questions they had no idea how to answer they would often use the tactic of trying to make the "customer" feel stupid for asking the question. This was something I thought did not help people, did not help the company and in fact made customers dislike the company and not trust them and was not worth of a good support engineer. Here people do not have to answer if they do not know, and they are not being paid, except I guess in point status, so these kind of answers provoke me a little bit.

Sep 30, 2013 8:42 PM in response to Frank Caggiano

Frank, I know it is fashionable to give unsolicited advice instead of answering the question, but this is not a question of paging, which if you cared to read the question you would have caught ... it is a question or redirecting I/O ( i.e. swapping ) away from the system disk which is very fast, but not infinitely so, over to another disk which is not getting any use at all. I've read quite a few answers on this, and many of them go for the don't do that non-answer, and it's not helpful, except as an addenda from someone who knows how to do and qualifies their answer. Thank you.


By the way, I have 16GB RAM on the system. Never enough. ;-)

Sep 30, 2013 7:39 PM in response to bruxxx

The swapfile is automatically generated. If you run out of RAM, the swap file is used by the system as a disk cache. Leave the swap file as is, on the huge block of dedicated flash storage you currently have (your SDD). There would be no point in altering the destination of the swap file to a traditional HDD as it would slow down performance greatly and defeat the purpose of even having a SSD to begin with in the event that any paging out occurs.

Sep 30, 2013 8:55 PM in response to nbar

Nbar ... I wish I did have an SSD, but I don't. My Mac is 27" but several years old now, with only a regular 1TB drive for the system drive. If I could get the system to swap to that drive I think it would be a win as there would be less I/O to the root disk, particularly when doing video or other I/O intensive stuff.


I'm thinking you did not read what I wrote about this you did not acknowlege that I am using an external disk for my system disk ... a Thunderbolt 8TB WD MyBook drive.

Oct 1, 2013 4:50 AM in response to bruxxx

OK I thought you had a legitimate question about the performance of your system. I didn't realize you were wasting everyone's time and had no idea of how modern OS's handle VM.


By the way, I have 16GB RAM on the system. Never enough. ;-)

Of course there is and it is fairly easy to figure out what that number is for any given system. Going above that number only wastes money. But again I thought this was a legitimate post.


Sorry for wasting my time


regards

Oct 1, 2013 6:28 AM in response to bruxxx

Let me try to interpret Mac OS to other unix-like systems. The rc file would be /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist as Andy points out. Here's a link with a solution- http://superuser.com/questions/28414/moving-the-swapfiles-to-a-dedicated-partiti on-in-snow-leopard/42835#42835 .


Personally, I would not mount the swap partition in the Volumes directory. Since the swap file is created early in the boot process, I would consider mounting the root filesystem and the swap partition in /etc/fstab. One caveat is Mac OS unmounts external drives when a user logs out. This link provides a solution- http://apple.stackexchange.com/questions/59057/fast-user-switching-how-to-preven t-volumes-from-being-unmounted .


I've tested none of this. Your mileage may vary.

Oct 1, 2013 6:32 AM in response to bruxxx

bruxxx wrote:




By the way, I have 16GB RAM on the system. Never enough. ;-)

So what are your page outs? If your device is not swapping to disc in the first place, than having a bigger and/or faster swap area is truly pointless. Similarly, if you are not swapping now, then your RAM is clearly not limited, so adding additional RAM will be largely moot as well and be a wasted idle resource.

Oct 1, 2013 11:08 AM in response to bruxxx

"Since I no longer use the internal 1 TB drive I thought Iwould play around with it and try to find a use for it. "



There are better uses for this drive then using it for your swap space. You will always have a swap file generated upon boot even if you have no page-outs. The size of this file is small relative to the size of your disk and there would more beneficial uses for your 1 TB drive. In fact, even if you are paging out and using multiple swap files, which is unlikely with 16 GB RAM, the total swap space is still negligible when we are talking TBs.

Oct 1, 2013 1:43 PM in response to bruxxx

bruxxx wrote:


nbar > There are better uses for this drive then using it for your swap space.


Such as?

1) Back up for vital information on your primary drive

2) Storage for large media files

3) Storage for archived files, or any user data you access sparingly

4) Shared storage drive

5) Alternative boot drive

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Create and use a swapfile on another disk

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.