Swap Partition or file and where?

For interesting topics. But remember this is a Linux Forum. Do not post offensive topics that are meant to cause trouble with other members or are derogatory towards people of different genders, race, color, minors (this includes nudity and sex), politics or religion. Let's try to keep peace among the community and for visitors.

No spam on this or any other forums please! If you post advertisements on these forums, your account may be deleted.

Do not copy and paste entire or even up to half of someone else's words or articles into posts. Post only a few sentences or a paragraph and make sure to include a link back to original words or article. Otherwise it's copyright infringement.

You can talk about other distros here, but no MX bashing. You can email the developers of MX if you just want to say you dislike or hate MX.
Message
Author
User avatar
JesusLinux
Posts: 76
Joined: Fri Aug 16, 2024 4:47 pm

Swap Partition or file and where?

#1 Post by JesusLinux »

Hello,

Just some general advice here:

I'm planning on installing MX Linux on another laptop.
This machine has on 120GB SSD and a 500GB HDD also 8GB RAM.
It has Win10 currently installed. Still don't know if I want to dual boot with MX Linux or ditch Win 10 completely.
Since the SSD is not that big, should I have a Swap Partition or Swap File?
And for performance where should it be located? On SSD or HDD?
The other laptops that I have MXL installed I only have one SSD with swap partition.

So check if this is ok:

120GB SSD:
/boot.efi - 200MB or 500MB?
/root - 111 GB (average)
/swap partition - 8GB (same has RAM)?

500GB HDD:
/home - most of the space
/swap partition 8 GB?

Thanks for any advice...

User avatar
j2mcgreg
Global Moderator
Posts: 6962
Joined: Tue Oct 23, 2007 12:04 pm

Re: Swap Partition or file and where?

#2 Post by j2mcgreg »

MX requires some type of swap space because a number of our applications expect it to be in place and may crash when it's absent. In normal operation it likely will never be used, but it has to be there. Under these conditions, I think that for most users a swap file is sufficient.
HP 15; ryzen 3 5300U APU; 500 Gb SSD; 8GB ram
HP 17; ryzen 3 3200; 500 GB SSD; 12 GB ram
Idea Center 3; 12 gen i5; 256 GB ssd;

In Linux, newer isn't always better. The best solution is the one that works.

User avatar
CharlesV
Global Moderator
Posts: 7613
Joined: Sun Jul 07, 2019 5:11 pm

Re: Swap Partition or file and where?

#3 Post by CharlesV »

You are going to hear LOTS of differences on this one :-)

My two cents...

- Definitely on the SSD
- Personally, with that size ssd... I would do a file. (ie you can easily decrease / increase size if you need more or want to experiment!
- Size is going to matter as to what / how your going to run. With 8gb of ram, if your doing anything 'real' with images, videos, VM's.. then you will need more... and it will come from the swap. I would suggest starting with an 8gb of ram. ( almost twice that if your going to hibernate! )

Exp: My 'normal operating' means I have around 12gb in use. ( 4 to 12gb is my 'normal usage' ) .. but if I get really busy or video editing.. then it is pretty easy for me to gobble up 16 to 20gb)
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

User avatar
JesusLinux
Posts: 76
Joined: Fri Aug 16, 2024 4:47 pm

Re: Swap Partition or file and where?

#4 Post by JesusLinux »

CharlesV wrote: Thu Feb 20, 2025 6:56 pm You are going to hear LOTS of differences on this one :-)

My two cents...

- Definitely on the SSD
- Personally, with that size ssd... I would do a file. (ie you can easily decrease / increase size if you need more or want to experiment!
- Size is going to matter as to what / how your going to run. With 8gb of ram, if your doing anything 'real' with images, videos, VM's.. then you will need more... and it will come from the swap. I would suggest starting with an 8gb of ram. ( almost twice that if your going to hibernate! )

Exp: My 'normal operating' means I have around 12gb in use. ( 4 to 12gb is my 'normal usage' ) .. but if I get really busy or video editing.. then it is pretty easy for me to gobble up 16 to 20gb)
I don't use hibernate ever.
This laptop is old from around 2011. My oldest laptop is from 2007 (running MX with 3 GB RAM and 6GB Swap partition), my newest is from 2017 with 16 GB RAM running Win10.
I have 5 laptops 2 of them are running MX. The other 3 I plan to install MX. On my newest laptop I intend to upgrade to W11 (the "unsupported way" because of CPU) if I can or ditch it entirely.
These laptops some have SSD+HDD some only SSD.
All my linux installations I've used swap partition. Never swap file.
I'm a casual user browsing web, streaming apps 99%. I don't use heavy stuff on image/sound editing. And no games. Still playing on PS3 lol.

User avatar
Pierre
Posts: 323
Joined: Thu Apr 19, 2007 9:23 am

Re: Swap Partition or file and where?

#5 Post by Pierre »

the Swap Partition is the traditional way.
however, an swap file is easier to adjust - size wise.

you do need an swap area that is at least equal in size to the PCs memory,
- if you plan to use hibernation at all.

my PCs do seem to be using the traditional methods
- of separate partitions for / home, /swap, /root, etc etc
Please use the check-mark icon to include [SOLVED] - when your problem is solved!
and DO LOOK at those Unanswered Topics - - you may be able to answer some!.

User avatar
DukeComposed
Posts: 1450
Joined: Thu Mar 16, 2023 1:57 pm

Re: Swap Partition or file and where?

#6 Post by DukeComposed »

JesusLinux wrote: Thu Feb 20, 2025 7:37 pm
CharlesV wrote: Thu Feb 20, 2025 6:56 pm You are going to hear LOTS of differences on this one :-)
I don't use hibernate ever.
This laptop is old from around 2011. My oldest laptop is from 2007 (running MX with 3 GB RAM and 6GB Swap partition), my newest is from 2017 with 16 GB RAM running Win10.
I'll side with Charles on this one and say that swap advice is a very diverse, and divisive, subject. I'll stop short of calling it a holy war, but ordinary folks get strangely attached to their swap opinions in ways that just don't happen with Linux kernel schedulers.

I'll try to stick to the facts.

It's a fact that swap files are easier to resize than swap partitions. This comes from the fact that partitions exist in a partition table and swap files exist within existing partitions. If you make a 500 MB swap partition and decide later on you want 1 GB of swap, you will probably need to move partitions around and shrink the space you're already allocated, if you can[0]. If you have a 500 MB swap file and you want to make it a 1 GB swap file, you just delete the one file and make a bigger one.

If you do not hibernate, you don't need the 1x, 1.5x, or 2x total system DRAM swap suggestions. Gigantic swap files are for people who hibernate because hibernation quickly dumps system memory to disk so you can unthaw the system faster. If you never hibernate, you can probably get away with a modestly-sized swap file. On a machine with 16 GB of DRAM I have a swap dataset[1] of 512 GB and performance is fine. Granted, I don't do a lot of real-time weather system modeling, password cracking, or high-end gaming, but 1/32nd of my total DRAM is a good ratio for swap in order for me to avoid system lock ups while not wasting huge swaths of disk space I'll never actually use. According to htop, this laptop's been on for 41 minutes using terminal, Thunar, and Remmina and it's still at zero bytes of swap used. Not even starting my bespoke Emacs[2] config makes that number budge.

And that's the weird thing about swap space. You almost never need it. But on those rare occasions you need some, boy do you ever need it. You may not need much, but when you need it, you need it.

So your choices are these:
  1. Set your swap space for, say, 512 MB and forget about it until it becomes a problem
  2. Set your swap space for, say, 1 GB and forget about it until it becomes a problem
  3. Set your swap space for, say, 2 GB and forget about it until it becomes a problem
  4. Et cetera
You can worry about optimizing this and finding that one perfect, magical number or you can make a decision you're comfortable with today and, as long as it's not 0 bytes of swap, you can always revisit the situation later. Either with a lot of effort using partitions or a lot less effort using files.

[0] XFS is a common Linux file system that does not permit shrinking. If you make a 1 GB XFS file system, you can grow it to 2 GB, but you cannot make it 999 MB or smaller. You'd have to copy the data off of the partition, delete it, and recreate a new, smaller XFS partition. Then you'd have to copy the data back.

[1] It's not quite a file. It's not quite a partition. It's ZFS.

[2] Emacs has been fairly called "Eighty Megs And Constantly Swapping" by fans and detractors alike. These days it's closer to 800.

User avatar
Eadwine Rose
Administrator
Posts: 14879
Joined: Wed Jul 12, 2006 2:10 am

Re: Swap Partition or file and where?

#7 Post by Eadwine Rose »

"and forget about it until it becomes a problem" <-- to me that IS a problem, 'cause I would not sit easy with that. But YMMV of course.

That swap partition is easiest, and if it is big enough (I have 8gb, I don't use hybernate or stuff like that, all is fine) it will never become a problem.
My harddrive is 500Gb, before that had 250gb. My partitions are like so:

500mb efi
80gb root (40 on the 250 drive)
8Gb swap
the rest is home


Standard user here, nothing fancy, been using this install for quite a while now. 1mb in use on the efi, 26gb used on root, nothing on swap that I have ever seen, and the home has about 1/3rd in use.

Just my 2 cts. :smile:
MX-23.6_x64 July 31 2023 * 6.1.0-37amd64 ext4 Xfce 4.20.0 * 8-core AMD Ryzen 7 2700
Asus TUF B450-Plus Gaming UEFI * Asus GTX 1050 Ti Nvidia 535.247.01 * 2x16Gb DDR4 2666 Kingston HyperX Predator
Samsung 870EVO * Samsung S24D330 & P2250 * HP Envy 5030

User avatar
AK-47
Developer
Posts: 1220
Joined: Sun Mar 24, 2019 7:04 pm

Re: Swap Partition or file and where?

#8 Post by AK-47 »

One thing to be mindful of is security. Swap files store the raw contents of your memory in disk, which could leak keys and such that have not been cleared by applications upon exit (either due to bugs, or due to them crashing, etc). Normally keys tend to be stored in special memory which the kernel marks as non-swappable, but there are a variety of reasons that this may not be the case.

If you are concerned about this (and this especially is important for SSD users as it is impossible to erase just the swap file with 100% certainty), you should look into zram, which needs no swap file. Fedora has this enabled by default, and it actually works extremely well, due to the excellent compressibility (even with a mediocre algorithm) of raw memory content. Especially with hibernation, where even the special non-swappable memory will get swapped out.

You are better off making your root partition 20GB and let MX create the swap file there. On a modern system there should be negligible difference in performance, if your system swaps so often as for that to be noticeable, you need to download more RAM.

rambo919
Posts: 223
Joined: Sat Sep 24, 2022 1:32 pm

Re: Swap Partition or file and where?

#9 Post by rambo919 »

I have experience with the OS slowing down to a crawl because the /swap was not on an SSD. It does not always use it but when it does it wants speed over space.

I don't even remember what the problems were but I had headaches when I used a swapfile instead of a /swap partition... maybe those are fixed now I dunno.

At the end of the day its best even if you dont want to to either experiment or just do what feels easiest or best.

Another thing to consider though is if the firmware does not already do so you might wanna leave 10-20% of the SSD capacity un-allocated to any partition, this provisioning prevents it from getting so full it starts to damage it. SSD's (especially the early one's) are flakey like this.

User avatar
JesusLinux
Posts: 76
Joined: Fri Aug 16, 2024 4:47 pm

Re: Swap Partition or file and where?

#10 Post by JesusLinux »

rambo919 wrote: Fri Feb 21, 2025 3:38 am I have experience with the OS slowing down to a crawl because the /swap was not on an SSD. It does not always use it but when it does it wants speed over space.

I don't even remember what the problems were but I had headaches when I used a swapfile instead of a /swap partition... maybe those are fixed now I dunno.

At the end of the day its best even if you dont want to to either experiment or just do what feels easiest or best.

Another thing to consider though is if the firmware does not already do so you might wanna leave 10-20% of the SSD capacity un-allocated to any partition, this provisioning prevents it from getting so full it starts to damage it. SSD's (especially the early one's) are flakey like this.
That's my concern.
I want the best performance possible. And putting Swap Partition on HDD may slow down the system.
Also I have been reading about swap partition location on SSD has excessive wear on the storage...

Post Reply

Return to “General”