Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Can I delete the swapfiles?

I've had slowdowns lately (80 GB HD, 1.25 GB RAM)...lots of beachballs (esp. with Safari...always esp. with Safari. Restarting Safari temporarily helps the situation).

My HD free space was down to about 3 GB. Deleted some big items I didn't need, and now have 4.8 GB free. However, when I added up the size of the root folders, I should have about 8 or 9 GB free. Used TinkerTool to show invisible files and found 3+ GB of swapfiles in private\var\vm (two 1 GB ones, a 512 MB, a 256 MB, etc. The latest is dated 4 July, which may be the last time I restarted my machine). I'd like to get rid of the swapfiles, but don't want to mess things up.

thanks

EB

15-inch Alum PowerBook 1.25 MHz, Mac OS X (10.4.6)

Posted on Jul 29, 2006 2:39 PM

Reply
5 replies

Jul 29, 2006 3:04 PM in response to EZ-E

Hi, EB.

Do not delete the swap files. They are managed dynamically, i.e. created and destroyed based on Mac OS X's management of Virtual Memory (VM). A fresh, nearly empty initial swap file is created when you restart your Mac and will at first be the only swap file. Mac OS X then manages swap files as needed based on how much RAM you have installed and other characteristics of the activities performed by your Mac.

For the general performance problems you are experiencing, as well as an understanding of VM and swap files, see my "Problems from insufficient RAM and free hard disk space" FAQ.

You also need to free up space on your startup disk: 3 GB is far too little, even 5 GB can be too small. See my "Freeing Space on your Mac OS X startup disk" FAQ.

Good luck!

😉 Dr. Smoke
Author: Troubleshooting Mac® OS X

---
Note: The information provided in the link(s) above is freely available. However, because I own The X Labâ„¢, a commercial Web site to which some of these links point, the Apple Discussions Terms of Use require I include the following disclosure statement with this post:

I may receive some form of compensation, financial or otherwise, from my recommendation or link.

Aug 8, 2006 11:32 AM in response to EZ-E

The problem here is that OSX's virtual memory implementation is broken. It is SUPPOSED to release memory in the swap files as applications close, but for some reason, on some installations, it does not. Instead, more swap files are added, first another 64MB file, then a 128MB, then a couple or more 512MB files, then huge 1GB swap files. You can verify this is true once you start getting low on system resources and having multiple swap files by quitting every running application and unused system process. Theoretically, the data in your swap files should no longer be needed, and it should be released, and you should see your performance pick back up, and your disk space return to more appropriate levels. For some reason, this is sometimes NOT the case.

It is also clear that OSX is NOT using the older swap files for anything. If you have had a system running for several months at low usage, some of the original swap files will have last modified dates that are just as old. Please do not tell me that there is useful page info in those files. They CAN be safely deleted, no matter what any particular pundit tells you. You will be very unlikely to experience any adverse effect. At most some odd application behaviour that can be cured by quitting and restarting the app, although I have never personally had any problem whatsoever.

HOWEVER (and it is a big however) there ARE two problems:
1) You can not delete these files by trashing them, Instead you have to run terminal and sudo rm them. (You can also use a number of utility apps. like Cache Out X or Tiger Cache Cleaner.)
2) Removing them does NOT free up the space on your disk.

This last caveat is the killer, since it makes the whole procedure, while benign, non-productive. As of now, the only solution is to reboot after deleting. Swap files are supposed to be deleted at boot time (although, again, this is sometimes not the case.) Since I often have processes running that I do NOT wish to quit in order to reboot, I am actively searching for a method to circumvent this.

Aug 8, 2006 6:31 PM in response to DeusExMachina

Swap files are easily misunderstood. They will disappear when no longer needed, but they go away in reverse order, i.e., newest first. There is no way to know what is in a given file, so it is unpredictable when a file will be deleted.

Note that if an application allocates a lot of memory, and a new swap file is created, it is because the system is moving other stuff out of the way to make room in RAM for the active application. Active memory is always allocated in RAM. So if you quit that application, the swap file will generally not disappear right away. The swap space is being used for something else.

Once a swap file is created, it doesn't move or change size until it is deleted. The system has direct access to the the internals of the file. From the point of view of the file system the file doesn't change until it is deleted. The modification time will not change. It is meaningless for judging when the file was last used.

You can not delete a swap file. sudo rm does not delete the file. It "removes" the directory entry. In Unix terminology, it "unlinks" the file. As long as the file is in use it will not be deleted. That is why the disk space is not released. The file is still there and still in use. By removing the directory entry, you can no longer see the file. You can not monitor whether it is still there (except indirectly, by watching disk space). You, as a user, no longer have any link to the file. But the system does have a link to it, and the file can not be deleted until the system releases it. Various "cache cleaners" that claim to delete swap files are almost certainly bogus. No doubt they do the equivalent of sudo rm.

The mere existence of swap files has no effect on system performance. The performance hit only comes when memory is being moved in or out of RAM. If something in the swap file is needed, it is moved into RAM. There will be a temporary lag as the swapping takes place, but then the memory remains in RAM as long as it is active. If the disk space used by swap files is an issue, then you need more disk space, more RAM, or probably both.


Aug 9, 2006 1:01 AM in response to Jeffrey Jones2

"Swap files are easily misunderstood. They will disappear when no longer needed, but they go away in reverse order, i.e., newest first. There is no way to know what is in a given file, so it is unpredictable when a file will be deleted."

I am sorry, but that is just plain incorrect. Again, while this is how vm is SUPPOSED to work, there is a bug in its implementation in OSX, and in some installations, swap files will NOT disappear. EVER. Instead, new ones are continually created until all free disk space is consumed, the system thrashes, and eventually crashes. It does no good for you to insist it is otherwise, as empirical evidence indicates this indeed occurs. I have almost 1 Gig of physical memory. With 0 user processes running, I have been in situations with dozens of swap files totaling many gigabytes. In addition, any number of people have reported swap files that do NOT even get removed at boot time, and simply hang around taking up space after each reboot.
In fact, on my dual G4, I have NEVER observed a swap file "going away." That is why these utilities that delete the unused swap files exist.
Also, they are not necessarily removed in reverse order, even when operating as designed. They are removed as needed, which can occur in any order.

"Active memory is always allocated in RAM. So if you quit that application, the swap file will generally not disappear right away. The swap space is being used for something else."

However, after quitting ALL applications, the swap space should not be being used for anything, and yet I still often have 7, 8, or more swap files, taking up several gigabytes of disk space. I can let the machine sit overnight running nothing, and no swap files are deleted. I can go away for the week, and still they sit there. Which leads to:

"From the point of view of the file system the file doesn't change until it is deleted. The modification time will not change. It is meaningless for judging when the file was last used."

Except that after you delete all running applications, you can pretty much guess that swap files created first are doing NOTHING.

None of this addresses the central problem. After all, there is a reason why this question is still marked "unanswered" after all this time.

Can I delete the swapfiles?

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