This question already has an answer here:

I'm very new to Ubuntu, using 14.04. I need to make swap space, so I read, to overcome a garbage collector problem. My RAM is 8 GB, and my code is using big data and uses a lot of RAM.

What is swap space? Does it mean using flash memory or is it a way to use the RAM of the laptop? What should I do (from scratch)?

command lsblk gave

sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0 461.9G  0 part /
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0   3.9G  0 part [SWAP]
sr0     11:0    1  1024M  0 rom 

command free-h gave

        total        used  free  shared  buffers  cached
Mem:      7.6G       7.4G  163M   727M   196M     4.9G
-/+ buffers/cache:   2.3G  5.2G
Swap:      9.9G       0B   9.9G

swapon -s gave me

Filename                Type        Size    Used    Priority
/dev/sda5               partition   4086780     0       -1
/swapfile               file        6291452     0       -2

blkid gave me

/dev/sda1: UUID="bf8fe3ec-1937-458f-be1e-5e1270111217" TYPE="ext4" 
/dev/sda5: UUID="2336032a-d853-4d38-9b2c-c24793586d3c" TYPE="swap"


marked as duplicate by Sergiy Kolodyazhnyy, Eric Carvalho, psusi, Sumeet Deshmukh, karel Jul 2 '17 at 3:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Memory is divided into "pages". when memory fills the system will write some idle pages to disk so that it can use active memory for other programs, this is called paging.

Swap Space is the disk area the system uses for paging. on some systems it is a file. Ubuntu and other linux/unix system use a drive partition for swap space. While a swapfile can grow as needed, it is subject to fragmentation. Since memory pages are all the same size, a swap partition does not have fragmentation issues but is limited to the size of the partition made for it.

Swap space is also used for hibernation. Thus it is recommended that swap space be at least twice the size of your installed memory.

If you can post a screen shot of your partitioning information, I can give more dtailed instructions on adding space if you need to

  • Generalization: RAM x 2 = swap space is good for low memory models. For machines with higher amounts of RAM, the formula looks more like swap = (RAM/2)... hibernation excluded. – heynnema Jul 2 '17 at 0:59
  • @heynnema -- thank you for that. so he should have 12G swap? – ravery Jul 2 '17 at 1:03
  • No, I agree with you... in this case, with only 8G RAM, 16G swap would be fine. I was just cautioning you that the RAMx2 rule really doesn't apply when you have 16G or 32G RAM. – heynnema Jul 2 '17 at 1:06
  • I would disagree. I have 8 GB RAM, 3 GB of swap files in total, which never goes over 1 GB in usage. 16 GB of swap is overkill of average home user. – Sergiy Kolodyazhnyy Jul 2 '17 at 4:02
  • @SergiyKolodyazhnyy but, if you notice, the OP says "not good to my code which is using big data", so their swap usage may be different than yours. Small amount of RAM require larger amounts of swap. Larger amounts of RAM require smaller amounts of swap. – heynnema Jul 2 '17 at 4:10

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