How to clear swap on ubuntu and improve RAM usage

When I am working with my Ubuntu laptop swap memory takes too much space and machine became slower.

I want to make ubuntu as fast as possible. I love speed.

swap memory linux clear with linux and Operating systems|lower


TO CLEAR SWAP ON UBUNTU WITHOUT RESTART

SWAP MEMORY

1. What is swap? Swap is a memory on hard drive used to help you if you doesn't have enough RAM space. But it is slow.

2. To check your swap: $ swapon // I have a swap file 2GB

2.1. To check available use $ sudo free -h

3. To disable swap use $ sudo swapoff -a // Takes a lot of time. Looks like it reload from swap to RAM to re enable $ sudo swapon -a. After reboot it reset.

3.1. But without swap it is impossible to hibernate.

4. Also you could increase swappiness (from 0 to 100). If 10 then linux use swap after RAM is 90% full.

4.1. To chang swappiness redact file /proc/sys/vm/swappiness // $ sudo nano /proc/sys/vm/swappiness

DECREASE MEMORY ALLOCATION

5. After restart my Ubuntu20 takes 1GB of RAM.

6. Change desktop to lxqt. Logout and choose new GUI. But it is not a good idea to install dozens of new packages it could lead to conflicts. It is better to use lubuntu instead of ubuntu.

sudo apt install lubuntu-desktop // Have unmet dependencies.

sudo apt install lxqt sddm
sudo apt-get install lxqt openbox -y
sudo reboot

7. Replace nautilus with PCmabfs $ sudo apt install pcmanfs

8. Clear memory cache:

sudo -i
sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches  // not recommended

9. Clean unused packages $ sudo apt-get autoremove

10. Clear apt cache. Check how much cache you have $ sudo du -sh /var/cache/apt

$ sudo apt-get clean // To clean apt cache

KILL UBUNTU DAEMONS

11. Which services run on ubuntu and what happen if you stop them. If I stop excessive services it saves not only RAM but CPU load and speed.

11.1. Xorg is very important. It is display server responsible for GUI, mouse, keyboard interactions. GNOME based on this service.

11.2. snapd is a service to manage snap-store applications. It restarts after I kill it.

11.3. gnome-terminal-server don't need to explain. Is an application to run commands from GUI.

11.4. snap-confine is used by snapd somehow.

11.5. gnome-clock I can kill with no problem to free 15MB.

11.6. evolution-alarm-notify it is some useless notification. You could delete it from autostart.

11.7. ibus-extension-gtk3 is for keyboard multilingual input. Important.

11.8. tracker-miner-fs for indexing files on background. Could be switched off.

11.9. networkd-dispatcher for network management. Purpose not clear enough.

11.10. unattended-upgrade-shutdown autoinstall security upgrades

11.11. fwupd updates firmware. Possible to turn off.

11.12. gsd-wacom supports wapon interactive pen device. When u turn off it restarts.

11.13. gjs is a GNOME part responsible for javascript

11.14. goa-daemon is responsible for user management

11.15. rsyslogd is for system log

11.16. udisksd for mounting external storage.

11.17. crond is responsible for software updates schedule.

11.18. systemd-resolved is a name resolver kind of DNS

11.19. evolution-calendar-factory is part of evolution email client. Could be switched off.

11.20. systemd is PID1 most important system process.

12. Install synaptic package manager and monitor installed packages and description $ sudo apt install synaptic