How to delete swap file/cache

Quick to answer questions about finding your way around Linux Mint as a new user.
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. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Redit2

How to delete swap file/cache

Post by Redit2 »

I only have 2GB ram and the cache file gets to 800MB+ after an hour or two off use. With my memory already at 80%+ it really slows things down or stops. I did the swap file setting reduction from 60 to 25 and it only helps for the 1st hour and then increases rapidly. Is there a way for me to dump/clear the swap file or cache while I'm still using the computer?
Last edited by LockBot on Fri May 26, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
MiZoG
Level 8
Level 8
Posts: 2217
Joined: Fri Jan 26, 2018 8:30 pm
Location: Athens, Greece

Re: How to delete swap file/cache

Post by MiZoG »

Disable swap
sudo swapoff /path-to-swapfile

or
sudo swapoff -a

You have to wait a lil bit and re-enable it
sudo swapon /path-to-swapfile

or
sudo swapon -a
Hoser Rob
Level 20
Level 20
Posts: 11806
Joined: Sat Dec 15, 2012 8:57 am

Re: How to delete swap file/cache

Post by Hoser Rob »

Redit2 wrote: Sat Nov 26, 2022 1:00 am .... I did the swap file setting reduction from 60 to 25 and it only helps for the 1st hour and then increases rapidly. ....
You mean swappiness, right? WHat you desrcribe is exactly what happens when you lower swappiness like that in a machine with minimal RAM. It works temporarily and then you end up in swap hell, worse than if you hadn't changed it.

Lowering swappiness isn't a magic fix for slowness and/or not really enough RAM. When the system is almost out of memory, all lowering swappiness does is tell the OS to prefer stealing pages from the program cache to paging to swap.

The Linux kernel devs have forgotten nore about Linux memory management than most all those cowboy blog writers know. I leave swappiness at 60, and with minimal RAM you'd be better off actually raising it somewhat.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
Redit2

Re: How to delete swap file/cache

Post by Redit2 »

I changed the swap file setting after I had the issue and it did help. Also turning off the swap file after a lot of use, letting the system clear and then turning it on again also helped. While my computer is fast on LM, the MB is max'd at 2GB so no options there. Few options left for those of us limited on RAM except to really watch how many tabs open at once and if watching a movie, have nothing else open and then clear out the swap file. If what I read about LM21 no longer having a swap file, that will make 2GB systems useless.
Petermint
Level 9
Level 9
Posts: 2981
Joined: Tue Feb 16, 2016 3:12 am

Re: How to delete swap file/cache

Post by Petermint »

Based on using 2 GB and more across various computers. 16 GB makes everything easy. 4 GB makes any version of Linux easy most days. 2 GB makes most things difficult at least once per day. For 2 GB:
* Stop applications when not in use and start them only when needed.
* Shut down when you go to lunch. The clean boot after lunch will help.
* Look at Xfce. If using Cinnamon, switch off effects.
* Delete anything unused. I usually delete the Bluetooth package because I never use Bluetooth. You have to be surgical for 2 GB.

:idea: If your machine has replaceable memory, you can get memory dirt cheap from companies recycling old machines.

Clearing the file cache is not needed as it is automatically adjusted down when needed. If your machine is slow, you have too many files to cache in the available memory. You either clean out unused files or add memory. My machine caches about 300,000 file entries in the 13 GB spare memory. You could count the files in your home directory and work out how much memory you need.
User avatar
zcot
Level 9
Level 9
Posts: 2796
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to delete swap file/cache

Post by zcot »

Redit2 wrote: Sun Nov 27, 2022 2:22 am the MB is max'd at 2GB so no options there.
it is, what it is.
Redit2 wrote: Sun Nov 27, 2022 2:22 am If what I read about LM21 no longer having a swap file, that will make 2GB systems useless.
That is incorrect. Mint 21 is using the same type of /swapfile as Mint 20 was. The activity is the same as before. This is a file included in the / filespace instead of the previous design with a separated /swap partition mechanism. But the functionality is the same, and the management.
Hoser Rob
Level 20
Level 20
Posts: 11806
Joined: Sat Dec 15, 2012 8:57 am

Re: How to delete swap file/cache

Post by Hoser Rob »

Redit2 wrote: Sun Nov 27, 2022 2:22 am I changed the swap file setting after I had the issue and it did help. ....
You said it worked briefly anf then the system clogged up, which is what happens with too low swappiness. Deleting the swap file occasionally isn';t going to solve the problems caused by too little RAM.

If you can't increase the RAM beyond 2G, there are probably other things there slowing things down. How old is that box? I suspect pretty old. This "Linux saves old computers" thing has limits. Neither Mint or its Ubuntu base really make a lightweight version nowadays. I'd suggest Antix. I use MX on my main Linux box, which is sort of prioduced by the same folks, and it's great. But not suited for old/weak hardware like Antix. And they have a decent support forum, which is #1.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
Redit2

Re: How to delete swap file/cache

Post by Redit2 »

Yeah you're right it's an old system. AMD64 X2 5000+ dual-core 1.9GHz, 80GB HD, 2GB ddr2 ram. About 15 years old but runs great until the swap file gets to about 800MB. It's limit is 2GB but never gets there. No doubt the ram is my limiting factory as the cores rarely average above 75%. I tried Cinn but settled on mate with LM20. Never tried xfce but read that by the time you add the stuff you want, there's not much difference. I don't use wifi/bluetooth/printer so its basic but need the option to use wifi. I stayed with mint because I have another computer on it and may make it my daily driver and would like to keep the same distro on all machines if possible. If xfce uses a lot less ram, I may try it. Where to find baseline ram usage? For this computer I need to find a fix to lower my ram use as much as possible and then problem solved. Maybe a new thread or keep it here? Thanks for all the input/
Petermint
Level 9
Level 9
Posts: 2981
Joined: Tue Feb 16, 2016 3:12 am

Re: How to delete swap file/cache

Post by Petermint »

You could list running processes using System Monitor or the commands ps, top, or htop. Find stuff you are not using. Post a list here. Someone with a similar usage might suggest some deletions.

Re the various GUIs. MATE and Cinnamon with effects OFF use about the same in my tests. Xfce uses less. The Cinnamon Xfce is not as light as the Xfce in the Raspberry Pi OS but I do not know the differences in the config.

I found I saved more resources adding NoScript to Firefox to block JS Junk.

An SSD will make swapping faster. At age 15, your machine probably has a SATA disk. I would buy an NVME SSD, put it in a SATA converter, then replace the rotating rust. When your old machine has a heart attack, the NVMe can be transferred to the new machine.
Locked

Return to “Beginner Questions”