Solved Cannot change swap file size in Ubuntu 24.04

Solved issue

lymphor

Member
Joined
Jul 16, 2023
Messages
83
Reaction score
43
Credits
807
Hello, it's me again, with a new Ubuntu 24.04 issue :)

I followed this guide https://ploi.io/documentation/server/change-swap-size-in-ubuntu to increase the size of my swap file. I used the following commands:
Code:
sudo swapoff -a
sudo fallocate -l 10G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Then I opened System Monitor to verify the changes: all good. I thought that's it. But unfortunately when I restart my PC the changes are reset to default. What could I do to change swap file size permanently?

In case you are wondering why I need this: when I render a video in Kdenlive a huge amount of RAM & Swap memory is being used. This didn't happen in Ubuntu 22.04, I don't know what's going on.
 
Last edited:


Crummy instructions.

Follow this instead


Edit to add: how much ram do you have ?
 
Thanks @Condobloke. I only have 8GB RAM, I just added all my specs in the signature. I'm planning to upgrade but right now I'm short on cash. The reason I need more swap space is Kdenlive: I tried to render the last project I completed, a 4 minutes FULL HD video, and the system consumed all my 8GB RAM + 8GB Swap. After which the PC froze and I had to force restart it. I don't understand why it's consuming so much memory, a few months ago I was rendering the same exact project using Ubuntu 22.04 with my old CPU, an AMD Ryzen 5 1500X, and did not have this issue. :rolleyes:
 
Last edited:
Question regarding the guide you kindly provided me: is it my impression or the instructions to disable/delete the current swap file before making a new one are missing?
 
Yes, it is not there. I think their approach is to run :

Code:
sudo swapon --show

.....to show how much you already have....and then ADD to that to make up the amount you wish to have

You could always use the instruction from the first link (the one you provided in post #1) to turn off existing swap, and then follow this with the instructions from my link to finish the whole thing off.

24.04 worries me. I never have the need to 'render' ....so cannot say how linux mint 21.3 handles the same situation.

I run 32GB of ram so I cannot imagine I would have any problem

I know the feeling, being short on cash !!
 
Thanks, I'll do as you suggested.

When I reinstalled my OSs a few weeks ago, following a PC upgrade, I chose Ubuntu because it's the only Linux I used so far (I also tried Ubuntu Studio, Lubuntu and Kubuntu, but just for a very short period of time) and because I thought that being the most popular it would have less problems and support would be easier to find. Didn't imagine 24.04 would actually be so problematic. Now is too late, I already spent too much time installing/configuring it, and don't want to start over with another distro. But if I would have known I would have probably picked another distro.

Regarding the cash, well, I live in Eastern Europe, in one of the countries with the smallest salaries in EU. But the prices of items, like PC components, are like in Western countries. And even if I earn more than the average, it's still not enough. You can easily tell by my PC specs :D
 
OS: Ubuntu 24.04 & Windows 11 Professional
CPU: AMD Ryzen™ 7 5700G
GPU: Radeon™ Graphics (integrated in the CPU)
RAM: ADATA XPG Z1, 8GB, DDR4, 2400MHz
Motherboard: ASUS PRIME B350-PLUS
SSD: Crucial P3, 2TB, PCIe 3.0 x4, M.2
SSD: Western Digital WDS240G1G0A, 240GB, SATA3
HDD: Seagate ST6000DM003, 6TB, 5400RPM, SATA3
HDD: Seagate ST2000DM001, 2TB, 7200RPM, SATA3
Power Supply: Gigabyte P750GM
Monitor: Asus VG289Q, 28", 4K, currently using HDMI cable
K&M: Logitech MK220

So what's sad about these PC specs.
Mine aren't that good.

Code:
# inxi -Fxz
System:    Host: EASYPC9690 Kernel: 6.6.39 x86_64 (64 bit) Desktop: JWM 2.4.2 Distro: EasyOS 6.1.1 scarthgap64
Machine:   Device: desktop System: Hewlett-Packard product: HP Compaq Elite 8300 SFF
           Mobo: Hewlett-Packard model: 3397 UEFI: Hewlett-Packard v: K01 v02.05 date: 05/07/2012
CPU:       Quad core Intel Core i5-3470 (-MCP-) cache: 6144 KB
           flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3) bmips: 25548
           clock speeds: max: 3201 MHz 1: 1596 MHz 2: 1596 MHz 3: 1596 MHz 4: 1596 MHz
Graphics:  Card: Intel Xeon E3-1200 v2/3rd Gen Core processor Graphics Controller bus-ID: 00:02.0
           Display Server: X.org 1.21.1.11 drivers: modesetting (unloaded: fbdev,vesa)
           tty size: 124x35 Advanced Data: N/A for root
Audio:     Card Intel 7 Series/C216 Family High Definition Audio Controller
           driver: snd_hda_intel bus-ID: 00:1b.0
           Sound: Advanced Linux Sound Architecture v: k6.6.39
Network:   Card: Intel 82579LM Gigabit Network Connection (Lewisville) driver: e1000e port: f080 bus-ID: 00:19.0
           IF: eth0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Drives:    HDD Total Size: NA (-)
           ID-1: /dev/sda model: SAMSUNG_SP2504C size: 250.1GB
RAID:      No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors:   None detected - is lm-sensors installed and configured?
Info:      Processes: 169 Uptime: 14:11 Memory: 4014.4/7842.1MB Init: SysVinit runlevel: 5 Gcc sys: N/A
           Client: Shell (bash 5.2.211) inxi: 2.3.8
#
 
Ok, thank you all, I finally managed to permanently increase the size of my swap file. The problem is I wrote a value of 10GB but I got a swap file of 25GB :p It seems that the system made a sum from the previous default size (around 4GB) and my last attempt to change it (20GB). I suppose that's why I got this output when I ran sudo mkswap /swapfile:
mkswap: /swapfile: warning: wiping old swap signature.
Setting up swapspace version 1, size = 20 GiB (21474832384 bytes)
no label, UUID=eb45aad4-dc13-4d25-9ead-62a13a14380b
Any ideas how to fix this?

@The Duck : alright, you beat me :D But I use my PC to make video editing, and I would like to switch to 4k resolution, that's why I said my specs are not so impressive.
 
@The Duck : alright, you beat me :D But I use my PC to make video editing, and I would like to switch to 4k resolution, that's why I said my specs are not so impressive.
I would think you could get a Kick A$$ graphics card and get your 4K you are wanting.
 
I would think you could get a Kick A$$ graphics card and get your 4K you are wanting.
Short answer: no.
Long answer (sorry but there's no medium lenght answer :p) : first of all, I'm not sure I need a dedicated GPU. As far as I know, in my case, the CPU is much more important, because it takes care of the rendering (that is the process of making a new video file from the original footage). If I'm correctly informed, for video editing the GPU must only be capable of outputting a 4k resolution video image.
I'm sure my PC can currently render a 4k video and output it, but I don't know if it can handle a smooth video editing process (that is modifying and previewing videos and audios in the timeline). I still have to try, I didn't have the time because I'm occupied with all sorts of problems Ubuntu 24.04 is giving me (I don't know if you noticed, but I am literally spamming this Forum).

Money wise, my priorities in term of PC upgrades are the following:
  • An external SSD drive to backup important data.
  • 64GB RAM, also necessary for a smooth video editing process.
  • Internal SSD drives to replace HDDs. SSDs are obviously faster in handling video files, but also much more reliable for storing data.
Only afterwards I would consider buying a dedicated GPU.

I don't know how much time it will take me. I was planning to have the RAM issue fixed by October/November. But I'm receiving disturbing news from my workplace. In the country I live in they plan to increase the taxes on salaries. These taxes are usually supported by the employer. But the company I work for wants the employees to support them, and it also wants to prohibit working for the competition, regardless of the role/field. So in their opinion I should earn less and be prohibited to compensate this loss by working extra for another company. For me the damage is even bigger, because I'm working in the Quality Control field but I studied Cinematography. My possibilities of professionally growing in this direction would be seriously affected.

The end (yes, I'm being abrupt, but I'm pretty sure you're already bored by now :D)
 
@lymphor
You're alright not boring me just more than I ever do.

I just surf the web and stream videos and my old thrift store and garage sale desktops are more than what I need.

You'll get it together however and whenever you can and everything works out in your favor.

Good Luck to ya for better days ahead.
 
Ok, thank you all, I finally managed to permanently increase the size of my swap file. The problem is I wrote a value of 10GB but I got a swap file of 25GB :p It seems that the system made a sum from the previous default size (around 4GB) and my last attempt to change it (20GB). I suppose that's why I got this output when I ran sudo mkswap /swapfile:

Any ideas how to fix this?

@The Duck : alright, you beat me :D But I use my PC to make video editing, and I would like to switch to 4k resolution, that's why I said my specs are not so impressive.
I don't know what you are talking about or how did that happen, but you can just delete the swap and make a new one.
 
I don't know how much time it will take me. I was planning to have the RAM issue fixed by October/November. But I'm receiving disturbing news from my workplace. In the country I live in they plan to increase the taxes on salaries. These taxes are usually supported by the employer. But the company I work for wants the employees to support them, and it also wants to prohibit working for the competition, regardless of the role/field. So in their opinion I should earn less and be prohibited to compensate this loss by working extra for another company. For me the damage is even bigger, because I'm working in the Quality Control field but I studied Cinematography. My possibilities of professionally growing in this direction would be seriously affected.

The end (yes, I'm being abrupt, but I'm pretty sure you're already bored by now :D)
I found all of that a good read....definitely not boring. Far from it !

There is a place for member Introductions....you might like to visit there and tell us more of the @lymphor story

 
Ever wondered why modern Linux Distros now come with a 2GB Swap File. ?
1722046361542.gif
 
I don't know what you are talking about or how did that happen, but you can just delete the swap and make a new one.
I did, but whatever size I input for the new swap file the result is always 5GB more. I want 10GB, but I get 15GB.
I suspect I somehow have 2 swap files, because when I run sudo swapoff -v /swapfile my system has 4.3GB of swap memory. And if I run sudo swapon /swapfile the size increases to 15GB.
This is the content of my fstab file, maybe someone has some time to look into it and tell me what is wrong:
Code:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p5 during curtin installation
/dev/disk/by-uuid/10ee13a5-bc35-42e8-88e2-a8e0c412c538 / ext4 defaults 0 1
# /boot/efi was on /dev/nvme0n1p1 during curtin installation
/dev/disk/by-uuid/FA4D-FBB0 /boot/efi vfat defaults 0 1
/swap.img       none    swap    sw      0       0
/dev/disk/by-uuid/01DADA7CB9415F40 /media/lafenice/SSD2 auto nosuid,nodev,nofai>
/dev/disk/by-uuid/01DADA60D581CC60 /media/lafenice/MUSICA\040&\040VIDEO auto no>
/dev/disk/by-uuid/01DAD9DA51E5BF00 /media/lafenice/DATA auto nosuid,nodev,nofai>
/dev/disk/by-uuid/54BC56CBBC56A6F0 /media/lafenice/WINDOWS\04011 auto nosuid,no>
/dev/disk/by-uuid/01D29F1808F76C30 /media/lafenice/FENICE auto nosuid,nodev,nof>
/swapfile none swap sw 0 0
 
From my limited understanding, there is no swap there,,,,but I could be wrong !
/swap.img none swap sw 0 0
/swapfile none swap sw 0 0

Since upgrading to 32gb ram I have not bothered with swap....it is unnecessary with that much ram

SO, reboot your pc and run ;
Code:
sudo swapon --show

Mine shows...
brian@brian-desktop:~$ sudo swapon --show
brian@brian-desktop:~$

....in other words a blank result..therefore no swap

I will mention a couple of members names here who will have a better idea then me. No need for you to do anything....they will come to the topic if they are online etc ect

@wizardfromoz

@osprey

@GatorsFan
 
It would be good to get an output from

Code:
cat /etc/fstab

Wiz
 
@lymphor

First of all, delete the older swap.img from your fstab if it doesn't exist. Second, either there are 2 swap files, or you might be using something like Zram or other memory compression thing which might be acting like a swap (idk if it works like that). Run the "sudo swapon --show" command as @Condobloke said.
 

Members online


Latest posts

Top