I would like to understand the difference of MAC OS X "Virtual Memory" and Linux/Unix Swap.

I ask this because I observed that MAC OS X "Virtual Memory" seems to work way more efficient (in desktop use cases) than Linux/Unix Swap does.

In my understanding, MAC OS stores unused (RAM)Data in "Virtual Memory". In manner, it keeps the RAM free for current used Data/ current running Programs.
So for example, if I have watched a movie and then start to render some images, MAC OS will move the movie into the "Virtual Memory" and remove it into the RAM only when I re-access it.

Swap to the contray will only use the swap if the current running programs demand more RAM than available. And will immediately write the data stored in swap back to the RAM as soon as possible.

  • 1
    @garethTheRed It's not really a duplicate of that. His question is how he can put the swap area on an SSD instead of the system disk. – Barmar Nov 27 '14 at 8:52
  • 1
    Linux has "virtual memory", too. It's been a standard feature of Unix for decades. – Barmar Nov 27 '14 at 8:57
  • 1
    @Barmar - I read it as "Does Linux support Virtual Memory"? If the OP means "Does Virtual Memory work on Ubuntu and Fedora when using a SSD" then the question should be edited to say that (or similar). – garethTheRed Nov 27 '14 at 9:05
  • 1
    Ok, my fault I wrote the question wrong. Gonna edit it. – Harrys Kavan Nov 27 '14 at 10:00
  • 1
    @derty - Indeed. I've voted to re-open the question. – garethTheRed Nov 27 '14 at 10:29

You can create a swap file on the SSD. An example for a 4GB swap file:

# fallocate -l 4G /swapfile
# chmod 600 /swapfile
# mkswap /swapfile
# swapon /swapfile

To make it permanent, add this to the fstab.

/swapfile   none    swap    sw    0   0

From: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04?

| improve this answer | |
  • I see that the SSD ref relates to the original version of the question. But I wonder if it's wise to use SSD for swap. Sure it's bound to be incredibly fast compared to using a magnetic disk, but it could also put a lot of wear & tear on the SSD. If I were doing this I'd be inclined to put the swap file (or partition) on a separate SSD, not my main drive. OTOH, modern SSDs do have a much longer reliable lifetime than earlier models, so I guess using SSD for swap is feasible these days. – PM 2Ring Nov 27 '14 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.