Increase Swap/Page File? Change it's place on another drive?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
SyncroScales
Level 4
Level 4
Posts: 369
Joined: Thu Jul 20, 2017 4:30 am
Location: Canada

Increase Swap/Page File? Change it's place on another drive?

Post by SyncroScales »

Hi,

Linux Mint xfce 20.2. Swappiness is set to 30.

Is there a way to increase the swap/page file? Or change it's place on another drive? When using Windows you can increase the swap/page files size. The rule seemed to be double the RAM. You can also put the swap/page file on another drive instead of only C drive, if there are multiple HDD's or SSD's.

I notice with 4 GB of RAM that the swap/page file is only half of that. If multiple tabs are open or YouTube links are open in multiple tabs, the page file starts to fill up as does the RAM. But the system can hang.

I understand that with Windows you can put a swap/page file onto D Drive, and double the RAM. But if that OS needs to, it still puts swap/page file onto C Drive or other drives and D Drive if needed.

Yes the solution is more RAM. I don't know how Linux handles this part of the system though.

Thanks.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Desktop:ASUS M3N78-VM, AMD Phenom II 965 3.4GHz, 3.5GBRAM(4GB), XP SP3/Vista SP2/LinuxMintCinnamon64-bit, nVidia GeForce GT 430. Laptop:AMD Athlon 64 X2 DualCore 3800+ 2GHz(AMD QL-62), 3GB RAM, Vista SP2/LinuxMintCinnamon64-bit, ATI 3100.
dave0808
Level 5
Level 5
Posts: 986
Joined: Sat May 16, 2015 1:02 pm

Re: Increase Swap/Page File? Change it's place on another drive?

Post by dave0808 »

There are 2 types of swap available to us. The first is a dedicated swap partition on the disc. The second is through swap files, which I guess is analogous to the Windows pagefile.sys (though I'm no Windows expert).

You can add more if you need to.

If you have a normal hard drive, they're obviously slow, and the read/write time is going to be frustrating - better to close some tabs :D

If you had SSD, then it'll be quicker than a HDD of course, but clearly won't match RAM for speed.

The following links should prove useful and can show you have to add more, whether it be through a file or additional partition... Note that if you are encrypting your HOME or disk, then you should ensure that the swap file(s) is/are encrypted too, else you risk leaking information.
Aztaroth
Level 5
Level 5
Posts: 764
Joined: Mon Jan 11, 2021 1:48 am

Re: Increase Swap/Page File? Change it's place on another drive?

Post by Aztaroth »

SyncroScales wrote: Mon Nov 29, 2021 7:07 am Hi,

Linux Mint xfce 20.2. Swappiness is set to 30.

Is there a way to increase the swap/page file? Or change it's place on another drive? When using Windows you can increase the swap/page files size. The rule seemed to be double the RAM. You can also put the swap/page file on another drive instead of only C drive, if there are multiple HDD's or SSD's.

I notice with 4 GB of RAM that the swap/page file is only half of that. If multiple tabs are open or YouTube links are open in multiple tabs, the page file starts to fill up as does the RAM. But the system can hang.

I understand that with Windows you can put a swap/page file onto D Drive, and double the RAM. But if that OS needs to, it still puts swap/page file onto C Drive or other drives and D Drive if needed.

Yes the solution is more RAM. I don't know how Linux handles this part of the system though.

Thanks.
There are 2 ways to set your swap :
- swapfile in your system disk
- swap partition where you want

In the Hibernation Guide of this Forum :
viewtopic.php?f=42&t=284100#3
Chapters 3 and 4 are dedicated to create a custom swapfile and setting the kernel to be able to use it.
If your goal doesn't include using the hibernation feature, you can stop after these.
dual boot LMDE4 (mostly) + LM19.3 Cinnamon (sometimes)
User avatar
SyncroScales
Level 4
Level 4
Posts: 369
Joined: Thu Jul 20, 2017 4:30 am
Location: Canada

Re: Increase Swap/Page File? Change it's place on another drive?

Post by SyncroScales »

Thanks Aztaroth.

Is there a different guide to having multiple swap files, as mentioned in that [GUIDE] you posted?

When do multiple swap files on different drives become useful?
Desktop:ASUS M3N78-VM, AMD Phenom II 965 3.4GHz, 3.5GBRAM(4GB), XP SP3/Vista SP2/LinuxMintCinnamon64-bit, nVidia GeForce GT 430. Laptop:AMD Athlon 64 X2 DualCore 3800+ 2GHz(AMD QL-62), 3GB RAM, Vista SP2/LinuxMintCinnamon64-bit, ATI 3100.
Aztaroth
Level 5
Level 5
Posts: 764
Joined: Mon Jan 11, 2021 1:48 am

Re: Increase Swap/Page File? Change it's place on another drive?

Post by Aztaroth »

SyncroScales wrote: Mon Dec 06, 2021 9:59 am Thanks Aztaroth.

Is there a different guide to having multiple swap files, as mentioned in that [GUIDE] you posted?

When do multiple swap files on different drives become useful?
Hi,
Here is the tuto to hibernate from a swap partition :
viewtopic.php?f=42&t=273202

IMHO, multiple swap files have no real interest. In your case (4Gb RAM), one is almost mandatory because you may run out of memory. Swap partitions are the old type, swap files are the modern way because they're simpler to manage.
However if you want to use hibernation, you should have a file or partition twice the size of your RAM because, as it is low, you may already have "things" in your swap at the moment you decide to hibernate. An 8Gb swapfile may dramatically decrease free space in your system partition.
My conclusion would be : if you have a large system partition with a lot of free space, go for the swap file. If you may run out of space on the system partition, go for a swap partition.
dual boot LMDE4 (mostly) + LM19.3 Cinnamon (sometimes)
User avatar
SyncroScales
Level 4
Level 4
Posts: 369
Joined: Thu Jul 20, 2017 4:30 am
Location: Canada

Re: Increase Swap/Page File? Change it's place on another drive?

Post by SyncroScales »

Thanks Aztaroth,

I am not really interested in Hibernation. Just the swap files or partition.

When watching the swap exchange with RAM, it's 1MB or 2 MB per second. I thought that having 4 GB swap or the swap on a different HDD would speed it up a little bit. Does higher cache on HDD's or different types of HDD's affect the swap speed? E.G.: Western Digital (Green, Blue, Black, Red, Purple, etc)

Does the other HDD or SSD have to be ext3 or ext4 file system? Can it be FAT32, extFAT or NTFS, etc? Is this when a swap partition would be used with a different file system?

Will the swap file or partition make fragmentation? How do Linux OS's handle this?

Gparted - It seems there is not a dedicated swap partition. /dev/sdh1 fat32 /boot.efi, /dev/sdh2/extended, /dev/sdh5/ext4
Desktop:ASUS M3N78-VM, AMD Phenom II 965 3.4GHz, 3.5GBRAM(4GB), XP SP3/Vista SP2/LinuxMintCinnamon64-bit, nVidia GeForce GT 430. Laptop:AMD Athlon 64 X2 DualCore 3800+ 2GHz(AMD QL-62), 3GB RAM, Vista SP2/LinuxMintCinnamon64-bit, ATI 3100.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Increase Swap/Page File? Change it's place on another drive?

Post by Termy »

Generating, loading, and making swap space persistent can be done via the terminal, and is fairly straightforward. Nowadays, we use swap files, which, as someone else has stated, is like the pagefile you get in Windows (I used to change that, too), at least as I knew it back in Windows 8.1. To generate a new swap file in Linux, it can be done with:

Code: Select all

# Generates empty file of 128MiB in size.
sudo dd if=/dev/zero of=/new_swapfile bs=1M count=128

# Changes file's mode for security reasons. 
sudo chmod 600 /new_swapfile

# Sets up file for use as swap space.
sudo mkswap /new_swapfile

# Adds file to system's swap space for immediate use.
sudo swapon /new_swapfile
Which I ran just now in a couple of seconds. I always set up my own swap files, and have done so for years (before it became the norm), so I'm familiar with the process. Where it gets a little interesting is when you want to make it persistent, as it involves editing '/etc/fstab', but even that's straightforward once you know what the fields are and enter things carefully.

The above commands generate a 128MiB (134MB) swap file in '/' called 'new_swapfile', then immediately adds it to the system's swap space for use. If you run swapon you can see the currently assigned swap space, or for more general feedback, you can run free -h.

Before editing '/etc/fstab', I recommend backing the file up, just in-case you bork it; you can do so with:

Code: Select all

sudo cp /etc/fstab{,.bak}
For setting up that 'new_swapfile', in the above example, in '/etc/fstab', the process can be as simple as running this only once:

Code: Select all

sudo sed -i '$a/new_swapfile none swap sw 0 0' /etc/fstab
Or editing the file manually and entering in the values yourself. I recommend that you at least read: man fstab

You can have multiple swap files assigned, BTW, and can even mix and match between swap files and swap partitions.

It gets only a little bit different when it comes to placing a swap file or partition on another drive, but I'll bow out now, as this took long enough to type out.
I'm also Terminalforlife on GitHub.
Locked

Return to “Beginner Questions”