Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,478
Rep:
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.
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...
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.
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!
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.