LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-23-2021, 12:02 AM   #1
sofasurfer
Member
 
Registered: Oct 2003
Posts: 252

Rep: Reputation: 20
swap file and swap partition


I have Ubuntu 20.04. When I installed it a swap partition was created, I also have a swap file. I can tell by the 'free' command that my swap file is being used. How can I tell if my swap partition is being used? Since I have a swap file, should I delete my swap partition? Why do I have both? I am short on RAM, so should I increase the size of my swap file or swap partition or both?

Last edited by sofasurfer; 04-23-2021 at 12:05 AM.
 
Old 04-23-2021, 01:01 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
With zero useful info, how can any of us say to any of those questions ?.
"swapon -s" will list your swap extents in use. Read the manpage.
I'm surprised Ubuntu created both - I thought I'd read they'd gone away from using swap partitions because their user base got too confused. You can activate it (permanently) by adding it to fstab. There is no detriment to using a combination.
 
Old 04-23-2021, 01:26 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,790

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
the command free is used to check if swap is being used.
How do you know you are short on RAM?
probably you will find it interesting: www.linuxatemyram.com
 
Old 04-23-2021, 08:43 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,251

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
I am not inclined to go over 4G in normal everyday stuff and I think most people are similar. Massive CAD or FPGA designs, or complex graphics or games will eat more, as will VMs. But my first RazPi only came with 1G and ran X, and a browser, etc.

Unix started in the days of 14 or 16 pin ram chips, with a few KB of (x1) ram in each, so once you got above a few KB, hardware got very messy. Linux inherited the tidy memory habits that were necessarily developed.

I'd advise to stop worrying. The one time I ran out of memory was in the 1990s. I was low on memory (as always), had many things open, and tried compiling this dodgy verilog package. It was written as 15 libs statically compiled into one executable. I watched with 'free' as it used my ram (at the linking stage), then filled my swap, & crashed. It compiled when I shut everything. And after all that, it was useless.
 
Old 04-23-2021, 12:48 PM   #5
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,478

Rep: Reputation: Disabled
Swap is seldom used on a regular basic use Linux/BSD machine.

If you have at least 2GB ram, most web browsers will work OK, with a few tabs open.

I seldom bother with any swap these days, it doesn't get used with what I do on a computer, just basic stuff, internet/music/videos/image viewing, etc.
 
Old 04-23-2021, 01:37 PM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,790

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
there are two related links. The first is the well known www.linuxatemyram.com and the second is about "why do we need swap". Unfortunately I can't find it right now. But it explain why is it still useful. Probably someone can post that link...
 
Old 04-23-2021, 03:55 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,973

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
I tend to just use top or htop.

Most distro's don't seem to care a lot between swap partition and swap file. In a way the use is almost identical. Swap files may be easier to manage after installs is usually one reason to consider.
 
Old 04-23-2021, 04:16 PM   #8
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
They are easier to manage. I recall once I was compiling Chromium, it takes hours, you do not want to terminate it and then start all over again. However, the new version I was building was a little more RAM hungry than I expected and filled my existing small swap. Believe or not, I managed to create a 2 GB swap file and turn it on before the OOM killer kicked in, saving my compilation. Easier to manage, indeed!
 
Old 04-23-2021, 04:21 PM   #9
Jan K.
Member
 
Registered: Apr 2019
Location: Esbjerg
Distribution: Windows 7...
Posts: 773

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
If the kernel thinks something is swapable - or swapworthy - by all means, swap ahead.

It will free up ram.

Always used dedicated swap partion, size 1.5 times amount of ram.


Too little or no swap may lead to mysterious, untraceable issues. There's enough info on the web...
 
1 members found this post helpful.
Old 04-23-2021, 04:28 PM   #10
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
The concept of 1.5 times size is from old times when RAM was expensive. Nowadays a small swap is enough, unless you want to hibernate. Everyone can see it for themselves, if your swap usage is noticeable then adding more RAM makes sense. Up to 200 MiB of swap usage is normal, no reason for RAM upgrade.
 
Old 04-23-2021, 07:59 PM   #11
sofasurfer
Member
 
Registered: Oct 2003
Posts: 252

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by pan64 View Post
How do you know you are short on RAM?
[/url]
Because I am running 20.04 with 2g ram (4g recommended) and I am freezing up with many tabs open.
 
Old 04-23-2021, 08:05 PM   #12
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Two grams of RAM? That's lightweight ...
 
1 members found this post helpful.
Old 04-23-2021, 10:28 PM   #13
sofasurfer
Member
 
Registered: Oct 2003
Posts: 252

Original Poster
Rep: Reputation: 20
Here is my 'free' results. How do these numbers look? I would like to check them when my pc freezes up but that is not possible because the pc is frozen up. Is there any way to accomplish that?

Code:
 $ free
              total        used        free      shared  buff/cache   available
Mem:        1832644     1120432      128984      241104      583228      251276
Swap:       2097148      354048     1743100
 
Old 04-24-2021, 03:04 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,790

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
Quote:
Originally Posted by sofasurfer View Post
Here is my 'free' results. How do these numbers look? I would like to check them when my pc freezes up but that is not possible because the pc is frozen up. Is there any way to accomplish that?

Code:
 $ free
              total        used        free      shared  buff/cache   available
Mem:        1832644     1120432      128984      241104      583228      251276
Swap:       2097148      354048     1743100
that is ok, at least acceptable. probably you can see that out of memory issue somewhere in /var/log.
 
Old 04-24-2021, 08:35 AM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,675

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Just as a reference how many is many tabs. In addition what other programs are running at the same time?

Increasing swap probably will not help. There are a few tweaks to firefox ( I assume ) that might help but opening many tabs takes memory.

Its easy to add or increase swap files if you want to try.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions on Swap Partition, How did Anyone Pass This Along? Next Ubuntu No Swap Partition happydog500 Linux - Software 18 12-25-2016 12:37 PM
Would a Linux swap partition work as a FreeBSD swap partition? Froggy192 *BSD 11 07-27-2013 02:06 PM
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 08:49 PM
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 02:16 PM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 10:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration