Why is swap space required
When the main memory is full, the overflow space can be used for additional memory. There's a downside to using a swap partition. Generally, the swap partition is further away from the regular memory, and data must move further, which is time-consuming. You can create a swap partition that is used by Linux to store idle processes when the physical RAM is low.
The swap partition is disk space set aside on a hard drive. It is quicker to access RAM than files stored on a hard drive. If you find that you constantly run out of memory and your hard drive is whirring, it is likely that your computer is excessively using swap space. If you have a computer with a small amount of memory, a swap partition is highly recommended. As a test, we set up a virtual machine with 1 gigabyte of RAM and no swap partition and installed Peppermint Linux, which uses the LXDE desktop, and overall, it has a low memory footprint.
Peppermint Linux comes with Chromium pre-installed, and every time you open a Chromium tab, a decent amount of memory is used. We opened a tab and navigated to linux. We kept repeating this process until, eventually, the memory ran out. Then, Chromium displayed a message stating that the tab stopped working and was probably due to a lack of memory.
Then, we set up a new virtual machine with 1 gigabyte of RAM and an 8-gigabyte swap partition. We were able to open multiple tabs, and although the physical RAM had run low, the swap space started to be used, and we were able to continue opening tabs. If you have a machine with 1 gigabyte of RAM, you're more likely to require a swap partition than if you have a machine with 16 gigabytes of RAM.
It is highly likely that you will never use the swap space on a machine with 8 gigabytes of RAM or more unless you do serious number crunching or video editing. Now you can perform the final step in creating the swap partition. Use the mkswap command to define the partition as a swap partition. Your new swap partition is now online along with the previously existing swap partition. You can use the free or top commands to verify this. If your disk setup uses LVM, changing swap space will be fairly easy.
Again, this assumes that space is available in the volume group in which the current swap volume is located. By default, the installation procedures for Fedora Linux in an LVM environment create the swap partition as a logical volume. This makes it easy because you can simply increase the size of the swap volume. First, verify that swap exists and is a logical volume using the lvs command list logical volume.
You can see that the current swap size is 8GB. In this case, we want to add 2GB to this swap volume. First, stop existing swap. You may have to terminate running programs if swap space is in use. Now verify the new swap space is present with the list block devices command. Again, a reboot is not required. You can also use the swapon -s command, or top , free , or any of several other commands to verify this. Note that the different commands display or require as input the device special file in different forms.
This article was originally published in September and has been updated with additional information by the editor. It used to be that swap space was something you did need to think about with some memory-intensive processes. Nowadays, with computers have a lot of RAM, and fast processors, it's of no great concern.
You can see this by running some application that monitors your system and watch the swap usage under heavy load. It's hard to see a dent in swap. I see heavy swap usage even on systems with large amounts of RAM when doing nightly backups based on rsync. Many other times the swap usage is minimal but still present. It depends in large part upon your environment whether you see heavy swap usage or not. My opinion - yes, I have a lot of those - is that from a technical standpoint swap was never intended to be a long-term substitute for having enough RAM.
It was intended to eliminate the possibility of a hard crash when RAM was used up. So it just became normal to run with lots of swap space. If you don't add swap soon, the server will crash. You can't use "swapoff -a" since this command will move all swap data to RAM. The command will fail because RAM can't accommodate the all memory contents of swap. On this situation you can add a swap file or partition.
You are correct; you can add swap space without turning off the existing swap space. Also, preallocating the swap file as you have makes the swap file a bit faster than allocating it when it is needed.
The scenario I used is a bit more ideal than yours. As with almost everything Linux there are many options for everything you might need to do. The one that works best for you is clearly the one you should use.
If data is requested a second time, it is available from the cache. Now we start processes, writing to more RAM. The kernel will now sacrifice the RAM used for disk caching and hand it out to the processes. Once the processes are requesting more memory than we have physically available, the kernel starts to utilize the swap. The process itself sees no difference - just that the swap is by orders of magnitudes slower than physical RAM.
If processes attempt to write to more memory than available including swap, the Out of Memory OOM handler has to decide for a process, and kill it. Once the physical memory is used up, swap gets used.
As the swap disk is much slower than RAM, the performance goes down, and thrashing occurs. At this point, even logins into the system might become impossible. As more and more memory gets written to, eventually both physical- and swap memory are completely exhausted and the OOM killer kicks in, killing one or more processes.
In our case, quite a lot of swap is available, so the time of poor performance is long. Now, let us imagine the above situation with no swap configured. As the system runs out of RAM, it has no swap to hand out. There is almost no time frame of reduced performance - the OOM kicks in immediately. So in this case:. The admins have no timeframe to react and possibly take countermeasures to maybe solve the issue without the application losing data.
They might decide to reset the system themselves. The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it. Swap is generally associated with a swap partition, perhaps because the user is prompted to create a swap partition at the time of installation. In fact, any file can be used as a swapping device, be it a partition or a conventional file.
Swap can be added by increasing the size of the swap partition or by adding a swap file. Keep in mind that when creating a swap file that it may not necessarily be using contiguous disk blocks as a swap partition will , and this could have a negative impact on performance as disk access times may be longer, and the more your system uses swap, the worse it will be. The Linux kernel also accesses swap disk block IO directly bypassing all caching, metadata and filesystem code, so a swap file should have no ill effect on the stability of your base filesystem.
Since kernel 2. The advantages of a swap file are many, but it is problematic for using the default swsusp hibernation method for powerless sleep. The best solution for maintaining hibernate capability after adding RAM is to increase the size of the swap partition.
If by some miracle you're able to resize your swap partition from here, I imagine your life will be a lot easier than mine. Now you need to find what partition your swap is on and what its UUID is.
Well that's the Universally Unique IDentifier for the partition so you can reference it even if it's on a different mount point from boot-to-boot due to adding disks, etc. Keep this open for further reference. It should be the third column, separated by spaces or tabs.
I recommend UUID because it'll stay constant even if you move the partition around or the disk somehow becomes sdb instead of sda or something like that. Make the appropriate edits and save the file. Enable the new swap partition with this command. If not chances are something went wrong in the steps above. Save the file! Now you should be able to hibernate and resume! Note: btrfs does not support swap files at the moment.
0コメント