I'm planning to install Ubuntu 9.04 version. How much space should I dedicate for swap partition. I remember setting it to double the RAM size when I installed long back. At that time my RAM was 256 MB. So I had set the swap partition to 512 MB.
darthvaderdarthvader1,7892020 gold badges5454 silver badges8383 bronze badges
7 Answers
I would say a good rule of thumb is indeed just as was mentioned above. 2 times the physical memory. Something to consider here, while it is possible to use a smaller swap partition, and it will suffice under most normal circumstances, if you want this system to be rock solid stable, I would indeed follow the 8 GB recommendation. In fact I recommend 2 * RAM + 1 MB so that there is absolutely room to swap out 2 entire copies of memory. This avoids the 'shell game' scenario which can have negative performance repercussions. What this will do for you is guarantee a level of resiliency should you encounter an extraordinary event with your system.
I've seen scenarios where applications behave badly in unattended environments and before you know it, your system starts slowing down to a crawl.
Depending on what you are doing, you might even be able to dispense with the swap file entirely. The extra space for the OS is handy when running many applications at once. However if you only intend to run a few processes, do not intend to interact with the GUI disabling the swap file might be appropriate.
But if you are going to have a swap file I always use the sizing formula below.
I also recommend putting your swap file on a seperate disk whenver possible as this will increase performance as the OS can swap in and out at the same time as read/writes from the data disk.
I hope this is helpful.
AxxmasterrAxxmasterr6,82366 gold badges3535 silver badges5757 bronze badges
Linux can operate quite happily with no swap if you have enough RAM for everything you ask it to do, though it is still a good idea to have some swap as it can sometimes gain better performance when close to filling memory by pushing some not-recently-used stuff out to disk freeing up RAM to use as cache/buffer for currently active IO operations.
Also, having some swap, no matter how much RAM you have, does allow a little extra safety net should an app misbehave and need more RAM than usual, or you choose to do something unusual that needs a lot of memory.
In general I don't agree with 2xRAM on modern machines. If you have enough going on to end up with 8Gb worth of pages to swapped out to disk then your system is likely to have ground to a completely unusable speed by that point anyway. Even 1xRAM can be overkill in many cases IMO. Remember that you can add swap space in the form of a file at any time, so you can add more swap later if you find you need to. for example, to add an extra GB of swap:
and to remove it (once no longer needed):
(remember though that swapping to files is a little slower than direct to to a partition or logical volume as you have filesystem overhead and greater potential for fragmentation to consider)
Hibernation, i.e. on laptops/netbooks, may complicate things a little as IIRC Linux stores memory state in the swap space, so you definitely need more then your RAM size as swap if you plan to use hibernation (and I don't know if that needs to be partition/volume based swap or if file based can be used - it will certainly need to be something mentioned in
fstab
that can be seen very early in the boot process whic the inital ram disk is in use and your real root not yet mounted).These points may all be moot though. If you have terabytes of disk storage, allocating 8Gb to swap is likely to be very little hardship!
David SpillettDavid Spillett
According to the Ubuntu SwapFAQ here the calculation is 2*MB of RAM. So in this case 8GB. Realistically however you should not need more then 2GB.
BinaryMisfitBinaryMisfit19k1010 gold badges6262 silver badges7676 bronze badges
Is it still necessary to reserve a partition for swapping? I thought nowadays this also works on a file on the system partition. And then I suppose you can easily change the size if you would insert more memory or if you think you don't need that much swap space.
Edit: Here's how that can be done (starting from linux 2.6 kernel).
fretjefretje10.4k55 gold badges3232 silver badges6262 bronze badges
first of all, if you want to use hibernation etc, you'll need a swap partition at least the size of your RAM.
secondly, remember that RAM is sized in multiples of 2 and not multiples of 10, so declaring 1GB of space for 2 sticks 512MiB of RAM (each
536870912 bytes
) is not enough, as this is only 1000MB (1000000000 bytes) and not 1024MiB (1073741824 bytes
) as required.. instead you'll need to take a calculator, and do 1024 * 1024 * 1024 * # of GiB
read also: http://en.wikipedia.org/wiki/Binary_prefix and
man 8 units
on your linux boxso, for four GB of RAM your swap needs to be at least
4294967296 bytes
or 4295 MB
to use all the features.as this is pretty big, it probaly should be enough for all your needs
alexanderpasalexanderpas
From my personal experience with Linux, I came to know that the conventional formula of 2X the size of RAM suits only older systems with 1 GB - 2 GB of RAM.
However for newer systems, having more Gigs of RAM, I suggest the following
If RAM < 2 GB, then Swap space = 2 x RAM
If RAM = 2 GB - 8 GB, then Swap space = RAM
This will not have any impact on system performance even while running high performance calculations and applications.
Although I recommend to use the original amount of RAM if your memory is atleast 4 GB. That should keep the system stable and efficient.
If RAM = 8 GB - 64 GB, then Swap space = 0.5 x RAM
In this case, I would recommend to use maximum 4 GB of RAM as that is more than enough, except for multimedia applications.
Michael.StarkMichael.Stark
The Ubuntu SwapFaq will probably answer a lot of your questions. With larger amounts of RAM you may benefit from changing the default 'swappiness' as outlined in this article.
JoshJosh37222 gold badges77 silver badges1818 bronze badges
Not the answer you're looking for? Browse other questions tagged linuxinstallationswap or ask your own question.
how to increase the partition /dev/sda2 partition.
df -h :
fdisk -l :
I've also edited the virtual machine settings to make hard disk size from 8GB(initially allocated) to 40GB, now how should i increase above mentioned partition? searched over Google but didn't get how to do this?
EDIT:
Created new partition /dev/sda3. fdisk -l after creating new partition
But when used resize2fs /dev/sda3. It showed below error
Pradi
prad
pradprad
2 Answers
Make sure that you have
psusipsusiparted
version 3.2, then run parted /dev/sda
and use the resizepart
command to resize sda2, moving the end of the partition to the end of the disk. Then run resize2fs /dev/sda2
to enlarge the filesystem to use the additional space. Reboot not required.14k22 gold badges2626 silver badges3939 bronze badges
1) Boot this virtual machine from livecd.iso of any distr (example ubuntu)
2) find disk what you want resize (probably /dev/sda)
3)
fdisk /dev/sdad - remove partition2 - number partitionn - create newp - type primary2 - number2056192 - start on same block, that started deleted partition<press enter to save default value> - max avaible sizew - write changes and exit
4) after that resize you filesystem with
resize2fs /dev/sda2
or other utils (depends your filesystem. resize2fs - for ext2/3/4)mr_tronmr_tron
Not the answer you're looking for? Browse other questions tagged partitionhard-diskvmwaresuse or ask your own question.
In this article, we will learn how to increase the swap space, which will solve the memory errors in applications. This will cover how to add a swap file to an Ubuntu Linux.
Anyway, this is recommended to utilize the spinning hard disk drivers for swap as SSD can cause issues with hardware degradation over time. Due to this reason, do not enable swap on Cloud where the SSD storage is provided.
What is Swap file?
The Swap is a place where the OS can store temporary data as it can no longer holds in RAM. Basically, this will increase the ability of the amount of data that a server can hold during its working memory. The swap space on the hard disk drive will be used mainly when sufficient space is available in the RAM to hold the data.
The data written on the disk will be slower than the RAM, but the OS will prefer to keep the running applications and data in memory and keep the old data in the swap.
Check the System for Swap Information
We will first check the system which already has the swap space. We can have multiple swap files or partitions.
Please note that, we can see the swap available in the system by using the below command –
Or we can use free -h command to display the swap space.
We can see the Swap row in the output of the machine. Here in this machine we have 1.0 G swap space allocated.
Checking the Available Space on the Hard Disk Partition
The most common way of allocating the swap space on the Linux is to use the separate partitions allocated for the swap. We cannot alter the partition scheme which is impossible, but we can easily create a swap file that resides on the existing partition.
Before we do this we will check the current disk space by using below command.
Increase Swap File Windows 10
The device under the /dev is the hard disk drives here we have 15 G space available.
In general, the amount equal to or double the amount of RAM on the machine is recommended for a good starting.
Creating a Swap File
As we know the available hard disk space, we can go head by creating a swap file within our filesystem. Also, note that, a file of the swap size which we are calling as ‘swapfile’ is in our root partition / directory.
The best way to create a swap file is by using a file called ‘fallocate’ program, this command will creates a file of a pre-allocated size instantly.
Ubuntu Increase Swap File Size
As we have 1 GB RAM allocated to our machine we will create more 2 GB file to meet the minimum requirement of the Linux.
Increase Swap File Size
We can verify that using the below command.
Enabling the Swap File to Use
We have created the swap file of our requirement but it needs to be turned on in this swap space. Before we turn on the swap file, we needed to lock the permissions of the file to only root users privileges who can read the contents of the files which will prevents the normal users from being able to access the file.
We can do this using the below command
To verify the permissions we can see using the below command
We have to verify that the swap is available with the amount of space allocated. For this, we can use below command –
OR Use the following command –
Making the Swap File Permanent
As we have changed in swap file for the current session, we also need to reboot the server that will not retain the swap settings to this permanant setting. Also, automatically we can add this swap file settings to ‘/etc/fstab’ file.
We can use the above steps to increase the swap space using a swap file, where we can fix the issues related to the memory exceptions. If we are running out of memory on any Linux servers then the above content will be specially be useful.