10

I found a file of size 1 GB in /vm/swapfile0, that has not been accessed in a long time, according to last access date value in ls -l.

My assumption is, that this file is left over from an older macOS version. The last access was probably before I upgraded to 10.12. Can I safely remove it?

I also found some files of size 1 GB in /private/var/vm. These have recent access times; both sleepimage and swapfile1 today and swapfile0 two weeks in the past. I think these are in active use.

One side question though: sleepimage has a size of 1 GB, although I have 4 GB RAM installed. How is that possible? Other threads on the topic of sleepimage suggested that the size would match that of the RAM installed in my Mac.

bmike
  • 235,889
  • 2
    See this question here at AskDifferent for more info about these types of files, especially the sleepimage file. – IconDaemon Jun 04 '18 at 19:16
  • 2
    This is unused, /vm was used during some upgrade or install. Some people report that after a supplemental update it disappeared. If you're running on the latest macOS version, it's safe to delete. – mspasov Jun 05 '18 at 00:38

2 Answers2

11

Boot up in Recovery mode and use the Terminal to remove the swapfile0 file. That is fully safe to do.

jksoegaard
  • 77,783
  • This is a great answer. The downsides I mention are not even close to the level of “unsafe” so a clear answer seems best to me here. +1 – bmike Jun 05 '18 at 01:40
  • @bmike, "downsides I mention are not even close to the level of unsafe" meaning? – Pacerier Apr 23 '20 at 18:43
  • @Pacerier My answer questions whether it’s safe to remove this. Since the OP didn’t specify how they intend to prune - there are some concerns I have to effectiveness and safety of removing a system file from under a running system. If they rm - it’s pointless, since the file doesn’t actually get deleted until the file is closed. And they have to assume macOS won’t attempt to close the file in some cases. – bmike Apr 23 '20 at 20:52
  • /vm/swapfile0 doesn't show up for me in my terminal when in opening in recovery mode for some reason - in fact there's no /vm dir at all. Is there a way to find it in recovery mode, or make it possible to see? – RyanQuey Dec 23 '21 at 05:28
  • You’re probably on a recent macOS version - then you haven’t got the problem in this question, and thus you do not need to do anything. – jksoegaard Dec 23 '21 at 06:29
5

The system reserves that file and cleans excess on restart. I'd leave it alone whether it's safe or not to prune (or attempt to prune). The system compresses memory and needs to have this space to offload any memory that's paged out so there's not a need for 1:1 RAM to swap allocation.

There are many other files you will want to focus on if you feel storage is growing out of check or you want to free up space on a boot drive. Deleting a file that will just be recreated, likely less contiguously than when you had more space available isn’t a sustainable clean up activity. Consider moving photos, music and movies to external storage or deleting apps if you have no large user files you can clean or move.

bmike
  • 235,889