0

I am using Kubuntu which is Ubuntu with KDE. My swap partition is too small causing me some lag. I have 16GB Ram but it is set to 1.9GB. Attached is screen shots of my current partition. vgkubuntu is the Volume Group. I was thinking to just create a swapfile instead of a partition. Can I just create the swapfile inside the ext4 filesystem without having to adjust partitions?

My plan is to boot live and use kparted. I believe it's doable from that tool.

enter image description here

enter image description here

Adding: free -m and before closing Chrome, after Chrome and closing Godot IDE. Notice swap never changes.

~$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15673       12407        1430        2401        4571        3266
Swap:           1955        1955           0

~$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15673       10299        3554        2123        4305        5373
Swap:           1955        1955           0
~$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15673        8100        5727        1302        3510        7573
Swap:           1955        1955           0

Edit: I finally took the easy way out. I created a 16G swap file and disabled the swap partition. I don't have to mess around with LVM stuff.

4
  • 1
    Too small swap will not normally be an issue, espeically with 16GB RAM and Kubuntu which is more lightweight. What does free -m show when slow? Note that Linux caches apps into RAM so if RAM full it releases unused apps before using swap, You can easily expand swap in LVM if you have space in the volume. discourse.ubuntu.com/t/how-to-expand-disk-space/68505/4 & unix.stackexchange.com/questions/733982/… Commented 2 days ago
  • 2
    "My swap partition is too small causing me some lag." um, without very specific problems that doesn't seem to make any sense. What problem are you really solving here? Commented 2 days ago
  • @Kusalananda see free -m in Edit above Commented yesterday
  • Edit your question to add the output of cat /proc/pressure/memory around a lag issue. Pressure stall information is a "better load average" that will show if there are actual delays waiting on memory. Commented 13 hours ago

1 Answer 1

-3

Swap aka paging space is on slower storage, but still can be helpful in some memory workloads. Whether it will feel faster is not obvious. You have the disk space for a generous 100% of RAM or more, so might as well try it.

Either swap on a file or swap on that logical volume are options. Both can make use of the existing encryption. Neither require changing partitions.

As always before storage changes, do a restore test. Get the most important file or two from backups. Open that file up, prove it is good.

File

A swap file can be created online and does not require booting live. Although swap file could be accidentally removed by a human if mistaken for a less important large file.

One time setup might look like:

mkdir /var/swap/
# file swap on ext4 works with non-sparse file, use mkswap to ensure this
# "2" to distinguish from the existing "swap 1"
mkswap --uid random --label swap2 --size 16G --file /var/swap/swap2

Append to /etc/fstab

/var/swap/swap2 none swap defaults 0 0

Logical Volume

LVM is capable of online operation, and ext4 file systems can be reduced. However reduce requires unmounting, and as its all in / that means booting live media or some other system to work on this disk.

KDE Partition Manager should be capable of these steps, although its also not difficult on the command line.

Open the encrypted LVM PV, which if it has not already been detected could be a cryptsetup-open command followed by vgchange --activate

Reduce the ext4 file system and the LV containing it. LVM can do this for you, easier to do correctly then remembering unmount, fsck, resize2fs. Minus sign indicates a negative relative size. Followed by adding that space to the existing swap LV.

lvresize --size -16g --resizefs  vgkubuntu/root
lvresize --size +16g vgkubuntu/swap_1

That is it for swap LV size. If you wanted to try more LVM LVs including snapshots, consider reducing vgkubuntu/root quite a bit more. You can add it back later, extend does not even require unmount.

2
  • Hi, why was this downvoted this much? Commented yesterday
  • This explains the purpose of swap and how the swap size can be managed. It does not address the underlying problem of performance issues due to swap. Commented 14 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.