Welcome!

The kernel problem with recent updates has been solved. Find the solution here

Important information
-- Required MX 15/16 Repository Changes
-- Information on torrent hosting changes
-- Information on MX15/16 GPG Keys
-- Spectre and Meltdown vulnerabilities

News
-- Introducing our new Website
-- MX Linux on social media: here

Current releases
-- MX-18.3 Point Release release info here
-- Migration Information to MX-18 here
-- antiX-17.4.1 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

<SOLVED> swap partition, swapfile, swappinnes, hibernation and ...

philotux
Forum Regular
Forum Regular
Posts: 428
Joined: Sun Apr 22, 2018 12:57 pm

<SOLVED> swap partition, swapfile, swappinnes, hibernation and ...

#1

Post by philotux » Sat Jan 26, 2019 9:36 pm

I don't have a swap partition on my disk, so the other day I just created a swapfile for just having one, just in case.
I wanted to ask which one is preferable, to have a swap partition or swapfile.

I have 8GB of memory and with my rather modest computing habits, I don't even get close to filling it up. So I am somewhat theoretically interested in this issue. At the same time I ignore the practical advantages of having one (file or partition) even though it seldom will get used.

Another question regarding swapfile is that is it possible to create them with a dynamic size or do they need to have a fixed size? Something else I was thinking about is changing the swappinness. Will it work with swapfile as well, as it does with swap partitions?

Looking forward to your comments.
philotux
Last edited by philotux on Fri Feb 08, 2019 3:00 pm, edited 5 times in total.

User avatar
figueroa
Forum Regular
Forum Regular
Posts: 396
Joined: Fri Dec 21, 2018 12:20 am

Re: swap partition, swapfile and swappinnes

#2

Post by figueroa » Sat Jan 26, 2019 10:04 pm

Better to have a swap partition, forget about swappiness, and just let the OS take care of it. Linux is excellent about this without tweaking.
Andy Figueroa
Using Unix from 1984; GNU/Linux from 1993

skidoo
Forum Guide
Forum Guide
Posts: 1446
Joined: Tue Sep 22, 2015 6:56 pm

Re: swap partition, swapfile and swappinnes

#3

Post by skidoo » Sat Jan 26, 2019 10:10 pm

swappinness. Will it work with swapfile as well, as it does with swap partitions?
Yes.
which one is preferable
Varies, according to your system specs and your usage. The following 2 references explain the gritty nitties:
https://help.ubuntu.com/community/SwapFaq
https://wiki.archlinux.org/index.php/swap#Swap_file
possible to create them with a dynamic size or do they need to have a fixed size
Technically, the declared-in-advance size is fixed.
Below I'm pasting a snippet regarding the possibility of resizing; I recommend reading the entirety of following linked page.
(bolding preserved from the original)

how-do-i-increase-the-size-of-swapfile-without-removing-it

You should add a new swapfile instead of resizing the exist one because it costs you nothing to do so. To resize a swapfile, you must first disable it, which evicts the swap contents to RAM, which increases pressure on RAM and may even summon the OOM killer (not to mention that you could possibly be thrashing your disks for several minutes). Multiple swap files are not a problem, it's trivially easy to setup yet another swap file. There's quite literally no benefit to resizing a swap file over adding another.

User avatar
Moltke
Forum Regular
Forum Regular
Posts: 198
Joined: Tue Dec 19, 2017 6:07 pm

Re: swap partition, swapfile and swappinnes

#4

Post by Moltke » Sun Jan 27, 2019 12:50 am

philotux wrote:
Sat Jan 26, 2019 9:36 pm
I don't have a swap partition on my disk, so the other day I just created a swapfile for just having one, just in case.
I wanted to ask which one is preferable, to have a swap partition or swapfile.

I have 8GB of memory and with my rather modest computing habits, I don't even get close to filling it up. So I am somewhat theoretically interested in this issue. At the same time I ignore the practical advantages of having one (file or partition) even though it seldom will get used.

Another question regarding swapfile is that is it possible to create them with a dynamic size or do they need to have a fixed size? Something else I was thinking about is changing the swappinness. Will it work with swapfile as well, as it does with swap partitions?

Looking forward to your comments.
philotux
My pc has 4GB of RAM and the swap partition is never used. I created and run several VMs in virtualbox and even then swap keeps unused. I don't think there's a problem with no having one with those 8GB. But then I don't know your computing habits, I for one apart from the VMs hobbie also watch videos, listen to music, surf the web, and play this and that videogame in snes9x, just like any other pc user.
Without each other's help there ain't no hope for us :happy:

philotux
Forum Regular
Forum Regular
Posts: 428
Joined: Sun Apr 22, 2018 12:57 pm

Re: swap partition, swapfile and swappinnes

#5

Post by philotux » Sun Jan 27, 2019 4:19 am

@figueroa, skidoo and Moltke

Thank you all for sharing your insights and for the useful suggestions and pointers.
As I said at the outset, with my modest computing habits, I never get anywhere close to hitting the swap. What I would like to know is when and why a swapfile is preferred over a swap partition or vice versa. In other words what are the advantages/disadvantages of having one rather the other, if it is the case that swapping is required.

User avatar
Eadwine Rose
Forum Veteran
Forum Veteran
Posts: 8910
Joined: Wed Jul 12, 2006 2:10 am

Re: swap partition, swapfile and swappinnes

#6

Post by Eadwine Rose » Sun Jan 27, 2019 5:15 am

I have 8Gigs of ram, confirmed ok, and I DO hit the swap sometimes. It really depends what you are doing though. Heavy use or just plain jane browsing and not much else.

With the large harddrives these days (I have a 1T drive) I can spare the 8Gigs I chose to assign for a swap partition easily. Last year I checked how much of the harddrive I had used of my then 500G drive and I laughed. It was like I was working on this small desk in the corner of a ballroom, that is all the room I had eaten up. Now I laugh even harder with this 1T, so.. if you can spare it easily, just get the partition whenever you install anew and never look at it again ;)
MX-18.3_x64 May 26 2019 * 4.19.0-5-amd64 ext4 Xfce 4.12.3 * 8-core AMD Ryzen 7 2700
Asus TUF B450-Plus Gaming UEFI * Asus GTX 1050 Ti Nvidia 390.116 * 2x16Gb DDR4 2666 Kingston HyperX Predator
Samsung 860EVO * Samsung S24D330 & P2250 * HP Envy5030

User avatar
BitJam
Forum Veteran
Forum Veteran
Posts: 3345
Joined: Sat Aug 22, 2009 11:36 pm

Re: swap partition, swapfile and swappinnes

#7

Post by BitJam » Sun Jan 27, 2019 7:16 am

philotux wrote:
Sun Jan 27, 2019 4:19 am
What I would like to know is when and why a swapfile is preferred over a swap partition or vice versa.
It used to be that a swap partitions were more reliable back when swapfiles were new-fangled. You may still be unable to use a swapfile on btrfs. A swap partition can be shared between distros. A swap file is easier to add and to re-size. I use a swap file and I'm happy with it. It's on a shared /data partition so it can be easily shared as well. I'd recommend using a swapfile because I think it is a little more convenient. IOW, space on a partition is more fungible than the partitions themselves. If I want that space back I can easily add a swapfile to a different partition. Resizing partitions is trickier. The Linux Volume Manager (lvm) makes space on your partitions fungible which is very cool but it adds a extra layer and complication. For me, doing something with a file instead of a partition is usually a win. Imagine if virtual machines each needed their own partition instead of a file on an existing partition.

On the live system we originally had a separate partition for home persistence and for root persistence. This turned out to be massively inconvenient. Now they are files (homefs and rootfs) on the main live partition and this works much better. In theory it is less efficient because there is an extra, unneeded layer of the file system on the main live partition. In practice, the limiting factor is the physical device.

In general, I'll have small boot partitions at the front of my drives that hold OSes. Then the root file system of each OS has its own partition, usually between 30G and 60G. I like to keep my data on large partitions (or a single large partition) that can be shared. This may not sound like it but I believe less partitioning is usually better because it creates fewer restrictions. Back in the early 90s I was humping around a lot of scientific data and I got a "massive" 2G drive for my Sun. The sysadmin asked me how I wanted it divided up. I said I wanted one large partition mounted at /data so I could figure out how to divided it up as I went along. They thought this was strange but it worked out great and I've been doing it like that ever since.
Will I cry when it's all over?
When I die will I see Heaven?

philotux
Forum Regular
Forum Regular
Posts: 428
Joined: Sun Apr 22, 2018 12:57 pm

Re: swap partition, swapfile and swappinnes

#8

Post by philotux » Sun Jan 27, 2019 8:01 am

BitJam wrote:
Sun Jan 27, 2019 7:16 am
It used to be that a swap partitions were more reliable back when swapfiles were new-fangled. You may still be unable to use a swapfile on btrfs. A swap partition can be shared between distros. A swap file is easier to add and to re-size. I use a swap file and I'm happy with it. It's on a shared /data partition so it can be easily shared as well. I'd recommend using a swapfile because I think it is a little more convenient. IOW, space on a partition is more fungible than the partitions themselves. If I want that space back I can easily add a swapfile to a different partition. Resizing partitions is trickier.
Thank you so much for taking your time replying. This is what I needed to know, and yet in your post I got so much more. Thanks for that. I really like the idea of a shared swapfile put on a shared /data. I think, I prefer this rather than having a shared swap partition and you gave some good arguments for that. I never knew if that was possible. So I guess what I need to do is

Code: Select all

fallocate -l SIZE /path/to/shared_data/swapfile
and then the dd, the chmod and the rest of the commands (I did follow an Arch wiki page to make a swapfile before for experimenting).
BitJam wrote:
Sun Jan 27, 2019 7:16 am
Back in the early 90s I was humping around a lot of scientific data and I got a "massive" 2G drive for my Sun. The sysadmin asked me how I wanted it divided up. I said I wanted one large partition mounted at /data so I could figure out how to divided it up as I went along. They thought this was strange but it worked out great and I've been doing it like that ever since.
Nice story! What a long way we have come from a "massive 2G" to nowadays' soon common for everyone 2TB. And you still stick with your partitioning scheme!
:happy:

Thanks again!

philotux
Forum Regular
Forum Regular
Posts: 428
Joined: Sun Apr 22, 2018 12:57 pm

Re: swap partition, swapfile and swappinnes

#9

Post by philotux » Sun Jan 27, 2019 8:05 am

Thank you all for your replies!
With your contribution, I have got a more complete picture. Now I am off to to experiment!

philotux
Forum Regular
Forum Regular
Posts: 428
Joined: Sun Apr 22, 2018 12:57 pm

Re: swap partition, swapfile and swappinnes

#10

Post by philotux » Sun Jan 27, 2019 8:34 am

It looks I was wrong about:

Code: Select all

fallocate -l SIZE /path/to/shared_data/swapfile
This is what I get:

Code: Select all

sudo fallocate -l 2048M /media/Storage/swapfile
fallocate: fallocate failed: Operation not supported
Edit: I got it, that's an NTFS-partition 9_9

Post Reply

Return to “Hardware /Configuration”