How to enlarge swap size

hi all .

i don't know which file is concerned about swap .

any way
the next script can change swap size up temporally , namely when reboot , swap size is return to the small original size .

the following script i saw at some URL , but forgot the UTL .

 #!/bin/bash
truncate -s 0 /mnt/swapfile
chattr +C /mnt/swapfile
btrfs property set /mnt/swapfile compression none
fallocate -l 2000M /mnt/swapfile
chmod 600 /mnt/swapfile
lsattr /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile

my crontab is

# crontab -l
@reboot shutdown -h +180 ;  /home/garu/swapON.bat 

and cat swapON.bat

swapon /mnt/swapfile

regards

You gotta change systemd-swap parameters to have swap automatically generated as you want it to.

sudo micro /etc/systemd/swap.conf

i think you do have to move the configuration to /etc/systemd/swap.conf.d/swap.conf, this is the first config file to get applied of those two. @librewish correct me if wrong

Here you can say how much swap is allocated to which conditions with the swapfc parameters.
Imo thats superior to allocating a static swapfile. :slight_smile:

2 Likes

The swapfile in our installs is located at
/var/cache/swapfile

So try to increase it

1 Like

thanks .

my /etc/systemd/swap.conf.d/swap.conf is

zram_enabled=1
zswap_enabled=0
swapfc_enabled=0

and

cat /proc/swaps is

Filename				Type		Size		Used	Priority
/mnt/swapfile                           file		2047996		0	-2
/dev/zram0                              partition	489792		256	32767
/dev/zram1                              partition	489792		256	32767

please show me ordinal /etc/systemd/swap.conf.d/swap.conf

regards

Just for info
What is the size of ram ?

Do you use ssd?

1 Like

thanks
i use 2.5 inch mechanical hard disk only .

So i think you dont need a swapfile
It would be better to just use a swap partition
Equal to or greater than ram size

3 Likes

Just thought Iā€™d mention that I believe the use of fallocate has been depracated.

Btw, b9458851ae2391bbf80cb104d33f55c7f868ea12

when i reinstall garuda ( xfce4) , i know the swap setting .

now my swap is device swap ( /dev/sda2)

cat /proc/swaps 
Filename                Type        Size        Used    Priority
/dev/sda2                               partition   8620368     0   -2
/dev/zram0                              partition   489792      0   32767
/dev/zram1                              partition   489792      0   32767
free
              total        used        free      shared  buff/cache   available
Mem:        3918340     1038452     1501940      116128     1377948     2327080
Swap:       9599952           0     9599952
/etc/fstab 
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 1
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /root          btrfs   subvol=@root,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /srv           btrfs   subvol=@srv,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /var/cache     btrfs   subvol=@cache,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /var/log       btrfs   subvol=@log,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=1b9ae1cd-98f7-4453-b130-a70fcad0fc06 /var/tmp       btrfs   subvol=@tmp,defaults,noatime,space_cache,autodefrag,compress=zstd,ssd,commit=120 0 2
UUID=04e87cca-c611-4aad-ace0-512ba9734fbe swap           swap    defaults,noatime 0 0 
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0

fdisk -l 
Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 232827039 232824992  111G 83 Linux
/dev/sda2       232827040 250067789  17240750  8.2G 82 Linux swap / Solaris
Disk /dev/zram0: 478.32 MiB, 501551104 bytes, 122449 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/zram1: 478.32 MiB, 501551104 bytes, 122449 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

swap size is over 9GB .


thanks for good advices .

Put terminal output in three ~ at first and last line. You can edit your post.
Now I show you how it work.

Summary

2 Likes

2 posts were merged into an existing topic: Nohang low memory