Thursday, April 18, 2019

linux - Swap partition size on a 64 GB RAM computer for memory-intensive work


I have 64 GB RAM and 240 GB SSD on my computer, which I'm going to use for memory-intensive calculations (machine learning, data mining, etc.). Most of the advice I found on the Internet are about 2-4-8 GB RAM computers, and they recommend 2x the size of the RAM swap partition (so 128 GB).


Is it reasonable to make a 128 GB swap partition? what advantages do I get by making a huge swap partition?


Do I understand correctly that, in case I run out of physical RAM:



  1. If I have no swap, I get an 'out of memory' error

  2. If I do have swap, some of RAM pages will be copied to swap partition, and the program will continue to run (although more slowly).


Some people say it's a bad idea to make swap on SSD, since it has limited amount of read/write cycles. How fast using swap will it exhaust SSD read/write cycles (as far as I know, it's about 50000 write IOPS)?


I'm using Linux (Ubuntu 14.04 (Trusty Tahr)).


Going to set a 16 GB swap for now, as it should be surely enough (for example, RedHat suggests 4 GB), and 16 GB of disk space isn't actually a big deal.


Answer



You probably only need a small amount of swap. When you have sufficient RAM for your computer's typical working set, which I'm pretty sure you do, you only need swap for two things:



  1. You need swap to get information that will likely never be accessed out of RAM to free up more space for disk cache. Many applications run on system startup and will never be accessed again. You don't want any pages they dirtied stuck in RAM forever. So you need swap to hold them.


  2. You need swap to cover allocations that will never be filled. This space simply has to be available, even though it will not be used. Without it, the system will have to refuse to allocate memory even when it has plenty of free physical RAM because it has insufficient backing store to permit all of its allocations to be used at once.



Neither of these requires a large amount of swap. 16GB, for example, should be more than enough. The purpose is not to let you run bigger working sets at the cost of speed. The purpose is to let you use your 64GB effectively and not have to clog it with junk or reserve it for edge cases that will never happen.


(I agree with Bert that 4GB is quite likely to be sufficient.)


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...