(SOLVED)Linux Mint Swap File vs Swap Partition

All Gurus once were Newbies
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. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
1NEWLINUXUSER
Level 2
Level 2
Posts: 88
Joined: Sun Aug 25, 2019 8:58 am

(SOLVED)Linux Mint Swap File vs Swap Partition

Post by 1NEWLINUXUSER » Thu Oct 10, 2019 3:21 pm

Hi all! I know there is a lot of info out there about swap files & swap partitions because I've run across a lot. I think I have at least a basic understanding of one vs the other but, please if you don't mind, below are a coupe of areas I would just like some clarification on:

* It's my understanding that upon installation Linux Mint 19, 19.1 &19.2 will automatically create an area called a swap file of about a 1gb or so and that swap file can be relatively easily turned on, off or resized. However, if 1gb is not enough will LM automatically resize the swap file or is that a manual operation? How would you know if you needed to resize the swap file?

* It's my understanding that a dedicated swap partition is not needed unless you plan on using hibernate mode which then has to be installed because Linux Mint does not include hibernation mode. Is a swap partition more or less difficult to resize? I think I read latter somewhere!

* Does LM also create a swap file in addition to swap partition or does it just default to the swap partition?

I would appreciate any thoughts, comments or questions.

Thanks.
Last edited by 1NEWLINUXUSER on Mon Oct 14, 2019 5:25 pm, edited 1 time in total.

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Thu Oct 10, 2019 4:46 pm

"However, if 1gb is not enough will LM automatically resize the swap file or is that a manual operation? How would you know if you needed to resize the swap file?"
During installation, it will create a swap file size related to the total RAM in the machine. Leaving it at default, should be adequate. How much RAM do you have? If you have 4GB or more you'll probably not even use swap for every day use.
As far as I know hibernation will work the same with a swap file as a swap partition
"Does LM also create a swap file in addition to swap partition or does it just default to the swap partition?"
Since 19x it just creates a swap file if you do a default install.
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

gm10
Level 20
Level 20
Posts: 10178
Joined: Thu Jun 21, 2018 5:11 pm

Re: Linux Mint Swap File vs Swap Partition

Post by gm10 » Thu Oct 10, 2019 4:51 pm

Tune up your LM 19.x: ppa:gm10/linuxmint-tools

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Thu Oct 10, 2019 5:22 pm

I checked a default install of 19.2 Mate with 8GB of RAM and it created a 2GB swap file. I used the terminal to put in hibernation and it went smoothly and woke up. Next I did an offline custom install of Cinnamon 19.2 and created an 8GB swap partition. It too hibernated but even so, the option was not in the shutdown menu and would have to be added. All that said, I never use hibernation or swap. I use suspend or shut down. I always have at least 4GB of RAM. No problems. A few laptops I've done for people that only had 2GB RAM and on those I have a swap file as a life preserver. Even then for every day use, it rarely or never gets used.
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

Petermint
Level 5
Level 5
Posts: 727
Joined: Tue Feb 16, 2016 3:12 am

Re: Linux Mint Swap File vs Swap Partition

Post by Petermint » Thu Oct 10, 2019 7:40 pm

With 4 GB of memory and Microsoft applications in a dual boot, swap was used because Windows actively swaps out stuff that is not used. Linux tends to leave stuff in memory until memory is full then swaps. When you hit swap in Linux, it can be a real slowdown on a magnetic disk. I now have a fast SSD and swap is rarely noticeable.

Simplescan and Google Chrome are big memory eaters. You need a big swap area. It does not matter if it is a partition or file. Swap files are easier to change when you need them. For that one reason, easier enlargement, I recommend swap files. I also recommend more memory if your applications swap on a regular basis. I moved my Simplescanning from my 4 GB machine to a 16 GB machine.

On low cost notebooks, with little 128 GB SSDs, permanently allocating anything to a swap partition is a waste of disk. Better to start with a tiny swap file then expand only when you hit something that needs the space. New notebooks are starting to use bigger SSDs, removing the problem.

User avatar
Spearmint2
Level 16
Level 16
Posts: 6880
Joined: Sat May 04, 2013 1:41 pm
Location: Maryland, USA

Re: Linux Mint Swap File vs Swap Partition

Post by Spearmint2 » Fri Oct 11, 2019 1:12 am

swappiness determines when data is sent out of RAM into the swap. Default is 60, which means RAM starts to move data to the swap earlier. Many, like myself set swappiness to 10, which insures the RAM keeps more data in it, before swap happens. On MBR systems there are 3 partitions plus 1 extended partition, if used to it's maximum allowance. Windows has always used a swap file (called pagefile.sys), possibly due to primary partition limits on MBR. As I recall, windows always wanted to be installed into the first partition. Not so with newer versions of windows. Other consideration is if you copy/clone a partition as a backup method which has a swapfile in it, then the backup uses more storage space, even if swap was turned off. If swap is in a different partition, that isn't a problem. Swap works same whether a file or partition.
Last edited by Spearmint2 on Sat Oct 12, 2019 2:31 am, edited 2 times in total.
All things go better with Mint. Mint julep, mint jelly, mint gum, candy mints, pillow mints, peppermint, chocolate mints, spearmint,....

gm10
Level 20
Level 20
Posts: 10178
Joined: Thu Jun 21, 2018 5:11 pm

Re: Linux Mint Swap File vs Swap Partition

Post by gm10 » Fri Oct 11, 2019 5:47 am

Spearmint2 wrote:
Fri Oct 11, 2019 1:12 am
swappiness determines when data is sent out of RAM into the swap. Default is 60, which means when RAM has used 40% it starts to move older data to the swap. Many, like myself set swappiness to 10, which insures no swap from RAM happens until there's 90% of RAM being used.
So setting swappiness to 100 means your system will start swapping at 0% RAM being used? Please think before perpetuating this fairy tale, and don't advise new users about changing a kernel setting without even understanding yourself what it does...
Spearmint2 wrote:
Fri Oct 11, 2019 1:12 am
Only on MBR systems does there exist a reason for a swap file instead of a partition swap, because MBR is limited to 4 partitions, although the last one can be a LVM where extra "volumes" (considered as partitons) can be created. Windows has always used a swap file because of partition limitations on MBR. That has no application to newer GPT configured drives. Other consideration is if you copy a partition for backup which has swapfile in it, then it's that much larger, even if swap is turned off. If swap is in a different partiton, that isn't a problem. Besides that, no difference in type of swap used. In windows, the swap is called "pagefile".
What a load of complete nonsense as well. Ever heard of extended partitions? The choice of swap file vs swap partition has got nothing to do with the partitioning scheme.
Tune up your LM 19.x: ppa:gm10/linuxmint-tools

fabien85
Level 7
Level 7
Posts: 1583
Joined: Tue Mar 11, 2014 4:30 pm

Re: Linux Mint Swap File vs Swap Partition

Post by fabien85 » Fri Oct 11, 2019 8:29 am

gm10 your points are fair, but I think they could be conveyed a bit more smoothly.

There are a few questions from the OP which, it seems to me, have not yet been answered :
1NEWLINUXUSER wrote:
Thu Oct 10, 2019 3:21 pm
However, if 1gb is not enough will LM automatically resize the swap file or is that a manual operation? How would you know if you needed to resize the swap file?

Is a swap partition more or less difficult to resize? I think I read latter somewhere!
I dont know for the first two questions.
For the third one, yes a swap partition (and any partition for that matter) is difficult to resize. Decreasing the size is easy, but for extending you will need contiguous space on the disk, whereas normally the installation takes the full space. So you would need to boot into a live USB, swapoff (because annoyingly the live USB will want to use that swap partition), resize and/or move other contiguous partitions to make space, before finally extending the swap partition.

1NEWLINUXUSER
Level 2
Level 2
Posts: 88
Joined: Sun Aug 25, 2019 8:58 am

Re: Linux Mint Swap File vs Swap Partition

Post by 1NEWLINUXUSER » Fri Oct 11, 2019 8:48 am

Thanks guys for all the input, all very helpful and pretty much exactly (maybe a little more!) what I wanted to know. I'm a relatively light weight user, just some internet, photos, music and email, etc., but I was mainly concerned about the older HP laptop I'm on now, as it has only 3gb of ram and running win7. It boots into LM Cinnamon 19.1 32bit on a 128gb usb stick set up with a 3gb swap partition because almost everything I ran across indicated using a swap partition of at least the ram size or larger! Then I started finding that LM 19X created it's own swap file and didn't need a swap partition, a little confusing!

In any case I plan on installing LM Cinnamon 19.2 64Bit on another 128gb usb stick for use on a win10 HP laptop. It has 8gb so I think I'll be ok there just letting it do it's thing. However, I will also play around the 64bit version on the this one because I discovered, much too my surprise, it apparently will boot and run 64bit just fine! My goal in all this is to get this one totally away from win7 by the end of the year and possibly eventually dual boot the other one.

As for hibernation, I'm having second thoughts about that now because as it turns out I haven't been using it that much since I put an ssd in this one some time back and almost everything I read recommended not using hibernation with an ssd! So much to remember!

But I do really like the look, feel and operation of Linux Mint, a tremendous effort and a tremendous os alternative to ms windows!

Again, thanks so much!

1NEWLINUXUSER
Level 2
Level 2
Posts: 88
Joined: Sun Aug 25, 2019 8:58 am

Re: Linux Mint Swap File vs Swap Partition

Post by 1NEWLINUXUSER » Fri Oct 11, 2019 9:02 am

fabien85 wrote:
Fri Oct 11, 2019 8:29 am
gm10 your points are fair, but I think they could be conveyed a bit more smoothly.

There are a few questions from the OP which, it seems to me, have not yet been answered :
1NEWLINUXUSER wrote:
Thu Oct 10, 2019 3:21 pm
However, if 1gb is not enough will LM automatically resize the swap file or is that a manual operation? How would you know if you needed to resize the swap file?

Is a swap partition more or less difficult to resize? I think I read latter somewhere!
I dont know for the first two questions.
For the third one, yes a swap partition (and any partition for that matter) is difficult to resize. Decreasing the size is easy, but for extending you will need contiguous space on the disk, whereas normally the installation takes the full space. So you would need to boot into a live USB, swapoff (because annoyingly the live USB will want to use that swap partition), resize and/or move other contiguous partitions to make space, before finally extending the swap partition.
Thanks fabian85, saw this after my response, but in any case since the swap partition is only 3gb I'm not concerned about space, I'll just leave it as is for now as I'll have as about 100gb of space, plenty for me. And if it turns out the the 64bit works well on both I may just reformat & reinstall it on this sick so I'll have a backup, sorta!
Thanks again.

gm10
Level 20
Level 20
Posts: 10178
Joined: Thu Jun 21, 2018 5:11 pm

Re: Linux Mint Swap File vs Swap Partition

Post by gm10 » Fri Oct 11, 2019 10:30 am

1NEWLINUXUSER wrote:
Fri Oct 11, 2019 8:48 am
but I was mainly concerned about the older HP laptop I'm on now, as it has only 3gb of ram and running win7. It boots into LM Cinnamon 19.1 32bit on a 128gb usb stick set up with a 3gb swap partition because almost everything I ran across indicated using a swap partition of at least the ram size or larger! Then I started finding that LM 19X created it's own swap file and didn't need a swap partition, a little confusing!
The swap size mainly depends on whether you're planning to hibernate, and the advice you found was certainly written with that in mind. I explained it a little in my guide that I already linked above:
viewtopic.php?f=42&t=284100&p=1569661#2
1NEWLINUXUSER wrote:
Fri Oct 11, 2019 8:48 am
As for hibernation, I'm having second thoughts about that now because as it turns out I haven't been using it that much since I put an ssd in this one some time back and almost everything I read recommended not using hibernation with an ssd!
I don't think that's a relevant recommendation these days anymore. In the very early days of SSDs there were worries that they might not survive a lot of read/write cycles, so there's a lot of advice floating around trying to minimize read/write access to the SSD, or in other words: actually using it. Which is of course crazy, because you bought it to use it. SSDs will eventually wear down, but so will spinning disks, and in each case likely after you've already replaced the device.
Tune up your LM 19.x: ppa:gm10/linuxmint-tools

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Fri Oct 11, 2019 12:16 pm

gm10 wrote:
Fri Oct 11, 2019 5:47 am
Spearmint2 wrote:
Fri Oct 11, 2019 1:12 am
swappiness determines when data is sent out of RAM into the swap. Default is 60, which means when RAM has used 40% it starts to move older data to the swap. Many, like myself set swappiness to 10, which insures no swap from RAM happens until there's 90% of RAM being used.
So setting swappiness to 100 means your system will start swapping at 0% RAM being used? Please think before perpetuating this fairy tale, and don't advise new users about changing a kernel setting without even understanding yourself what it does...
Spearmint2 wrote:
Fri Oct 11, 2019 1:12 am
Only on MBR systems does there exist a reason for a swap file instead of a partition swap, because MBR is limited to 4 partitions, although the last one can be a LVM where extra "volumes" (considered as partitons) can be created. Windows has always used a swap file because of partition limitations on MBR. That has no application to newer GPT configured drives. Other consideration is if you copy a partition for backup which has swapfile in it, then it's that much larger, even if swap is turned off. If swap is in a different partiton, that isn't a problem. Besides that, no difference in type of swap used. In windows, the swap is called "pagefile".
What a load of complete nonsense as well. Ever heard of extended partitions? The choice of swap file vs swap partition has got nothing to do with the partitioning scheme.
Most certainly I don't profess to know about swappiness, but a couple "respected?" resources claim to cut swappiness:
https://easylinuxtipsproject.blogspot.com/p/ssd.html
https://rudd-o.com/linux-and-free-softw ... o-fix-that
I'm fascinated by this, actually.
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

gm10
Level 20
Level 20
Posts: 10178
Joined: Thu Jun 21, 2018 5:11 pm

Re: Linux Mint Swap File vs Swap Partition

Post by gm10 » Fri Oct 11, 2019 1:19 pm

blueocean wrote:
Fri Oct 11, 2019 12:16 pm
Most certainly I don't profess to know about swappiness, but a couple "respected?" resources claim to cut swappiness:
https://easylinuxtipsproject.blogspot.com/p/ssd.html
https://rudd-o.com/linux-and-free-softw ... o-fix-that
I'm fascinated by this, actually.
Yes, I know Pjotr is part of the problem. ;)

Rather than uninformed speculation, let me refer you to the actual source code that makes use of this setting:
https://git.kernel.org/pub/scm/linux/ke ... an.c#n2306

I'll try to give a short overview (or as short as I can make it):

When more random access memory (RAM) is requested than is currently free, the kernel's memory resource controller checks whether it can reclaim any memory from the page cache and if yes, which type of memory pages to free. To this extent a least recently used (LRU) policy is in use, with separate LRU lists being kept for file pages and for anonymous pages.
  • File pages are cached disk operations, i.e. when the same file gets read several times the kernel tries to cache the file's contents so it only needs to read it from the storage device once and can serve subsequent requests from RAM, which is much faster.
  • Anonymous pages are part of application memory that is not represented by a file on disk.
Now in the determination from which of those two LRU lists memory pages should be reclaimed first, the swappiness setting come into play. At a swappiness setting of 0 or when there is no swap space available, only file pages will be reclaimed, whereas at a swappiness setting of 100 and swap space being available, file pages and anonymous pages are considered at equal weights for reclamation. The swappiness setting is not the only factor, however, for the kernel also takes cache pressure into account, which I shall very inaccurately describe as your current system usage, because that it what it comes down to at the end of the day. And I've also been glossing over some other details, but I linked the source code so you can check it all out if you want.

So should you change the swappiness setting? If you understood what I explained above you'll know that this depends entirely on your particular system usage and its available RAM (with enough RAM you'll never swap, anyway). Pjotr is certainly wrong in suggesting that the default of 60 is meant for servers - in fact your typical web or database server will want to set swappiness to 0 or sometimes 1, for application latency is key and these types of server use their own caching solution rather than relying on the kernel's file page cache, anyway.
Last edited by gm10 on Fri Oct 11, 2019 2:10 pm, edited 1 time in total.
Tune up your LM 19.x: ppa:gm10/linuxmint-tools

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Fri Oct 11, 2019 2:04 pm

So gm10, for an average user with say 4GB RAM, it sounds like just leave swappiness alone? Myself, I have at least 4GB RAM (laptop -barely use) and 8GB in my Desktop (use all day) don't have swap partition at all. I use Btrfs (have since it was included in Mint) -not that the file system would be a deciding factor. I never see over 3GB used for my use and rarely even 2GB.
No problems with Btrfs - luv it.
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

gm10
Level 20
Level 20
Posts: 10178
Joined: Thu Jun 21, 2018 5:11 pm

Re: Linux Mint Swap File vs Swap Partition

Post by gm10 » Fri Oct 11, 2019 2:22 pm

blueocean wrote:
Fri Oct 11, 2019 2:04 pm
So gm10, for an average user with say 4GB RAM, it sounds like just leave swappiness alone? Myself, I have at least 4GB RAM (laptop -barely use) and 8GB in my Desktop (use all day) don't have swap partition at all.
Without swap space the setting won't have any effect, so it won't matter. But for the average user, I won't make any statements as to what is best for I honestly do not know what the average Linux user does on their computer.

Also the impact of the setting is hard to measure since I'm thinking that psychologically a slow-down when restoring a running application's memory from swap may be considered more problematic than a slow down when starting an application or performing other disk accesses, even though the first one is a one-time thing whereas disk accesses repeat all the time so the total productivity loss caused by the latter may be bigger.

Either way, the best advice to give is to simply add enough RAM to your device and thus avoid the question from even posing itself. ;)
Last edited by gm10 on Fri Oct 11, 2019 2:49 pm, edited 1 time in total.
Tune up your LM 19.x: ppa:gm10/linuxmint-tools

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Fri Oct 11, 2019 2:48 pm

gm10 wrote:
Fri Oct 11, 2019 2:22 pm
blueocean wrote:
Fri Oct 11, 2019 2:04 pm
So gm10, for an average user with say 4GB RAM, it sounds like just leave swappiness alone? Myself, I have at least 4GB RAM (laptop -barely use) and 8GB in my Desktop (use all day) don't have swap partition at all.
Without swap space the setting won't have any effect, so it won't matter. But for the average user, I won't make anyway statements as to what is best for I honestly do not know what the average Linux user does on their computer.

Also the impact of the setting is hard to measure since I'm thinking that psychologically a slow-down when restoring a running application's memory from swap may be considered more problematic than a slow down when starting an application or performing other disk accesses, even though the first one is a one-time thing whereas disk accesses repeat all the time so the total productivity loss caused by the latter may be bigger.

Either way, the best advice to give is to simply add enough RAM to your device and thus avoid the question from even posing itself. ;)
Yes an average user is a enigmatic phrase. I'm visualizing non-gamer, light use, surfing net with a few tabs open , watching hulu movie, and playing majhong or solitaire. My take on it is most newer systems have 4GB or more of RAM and seems to make most sense just to leave swappiness at default - no worries. A few cheap laptops with 32GB drives only have 2GB,. I'm thinking even those leave default swappiness. When I have Put Mint on those I use 1GB Swap.
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

jglen490
Level 5
Level 5
Posts: 766
Joined: Sat Jul 15, 2017 9:57 pm

Re: Linux Mint Swap File vs Swap Partition

Post by jglen490 » Fri Oct 11, 2019 3:42 pm

gm10 wrote:
Fri Oct 11, 2019 2:22 pm
blueocean wrote:
Fri Oct 11, 2019 2:04 pm
So gm10, for an average user with say 4GB RAM, it sounds like just leave swappiness alone? Myself, I have at least 4GB RAM (laptop -barely use) and 8GB in my Desktop (use all day) don't have swap partition at all.
Without swap space the setting won't have any effect, so it won't matter. But for the average user, I won't make any statements as to what is best for I honestly do not know what the average Linux user does on their computer.

Also the impact of the setting is hard to measure since I'm thinking that psychologically a slow-down when restoring a running application's memory from swap may be considered more problematic than a slow down when starting an application or performing other disk accesses, even though the first one is a one-time thing whereas disk accesses repeat all the time so the total productivity loss caused by the latter may be bigger.

Either way, the best advice to give is to simply add enough RAM to your device and thus avoid the question from even posing itself. ;)
The "enough RAM" solution is the best, by far, since RAM is a lot faster than disk, although solid state drives - of all kinds - are different in that respect. But that's probably another discussion.

Anyway, as an illustration of the RAM solution: my desktop unit has 16GB RAM. I'm no power user, and do not game, but I wanted enough RAM to do what I do. So, anyway, the last time I setup some new drives on that system, I selected an SSD for the / partition (along with an ESP and a SWAP partition). Typically, I'll setup the SWAP equal to RAM, and I went through the usual setup with the "something else" install option, and everything ended up just fine. The machine just hums right along. It wasn't until later that I was looking at a USB in gparted and did a double-take at what gparted was showing for SWAP on the / partition/drive. So there is a big difference between typing in "16" when defining a partition size and typing in "16,000" when defining a partition size, when the installer defaults to MB rather than GB in that little box. So for the past several months, I've been running my system with 16MB of SWAP instead of 16GB. Well, slap my fingers with wet noodles :lol:

So, with 16GB of RAM, apparently SWAP doesn't matter at all because I've never seen anything written to SWAP when using top or htop, and I never paid attention to the SWAP size being shown. Interesting lesson, stupid reason for having that lesson, "sigh".
I feel more like I do than I did when I got here.
Toshiba A135-S2386, Intel T2080, ATI Radeon® Xpress 200M Chipset, 2GB RAM, 500GB

Petermint
Level 5
Level 5
Posts: 727
Joined: Tue Feb 16, 2016 3:12 am

Re: Linux Mint Swap File vs Swap Partition

Post by Petermint » Fri Oct 11, 2019 5:42 pm

surfing net with a few tabs open
That would be a few megabytes of memory with a good Web browser but would be a few gigabytes with Chrome opening every link in the background. And then there are 4K videos.

My average use is 1.6 GB but the peak use reaches 12 GB, the reason I had to increase my page file. Luckily page files are easy to increase.

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Fri Oct 11, 2019 6:42 pm

With Chrome:
Attachments
Tabs-Open.jpg
Idle.jpg
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

User avatar
blueocean
Level 5
Level 5
Posts: 932
Joined: Sun Jul 08, 2018 11:50 pm

Re: Linux Mint Swap File vs Swap Partition

Post by blueocean » Fri Oct 11, 2019 6:56 pm

With Firefox same tabs
Not much different. What is this "good browser" :?:
Firefox-same-Tabs.jpg
To mark this issue solved, go to your original 1st post and click the edit pencil and add [Solved] at the beginning of the title and click Submit.

Post Reply

Return to “Newbie Questions”