Swap size is incorrect

Hi,
Recently I upgraded my memory so I would like to also increase the swap size.
My earlier setting is that I have two swap partitions. Both swap partitions are the second of the three partitions on the NVME devices. They were both 10G so the total swap size was 20G at that time.
Now I would like to increase the swap size to a total 72G. Because there was no spared space on the devices, so I deleted the original swap (second) and third partitions on both devices, and then recreate the two swap partitions to 32G on each and the rest of the space to the third partition on both devices (for mirror purpose). However, after mounting those two swap partitions, the reported swap size is still 20G.
Below is the output of lsblk and swapon --show. You can see the size is different.

lsblk                                                                                                                                                                                                                                                                         ✔ 
NAME          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda             8:0    0 465.8G  0 disk  
├─sda1          8:1    0 465.8G  0 part  
└─sda9          8:9    0     8M  0 part  
sdb             8:16   0   1.8T  0 disk  
├─sdb1          8:17   0   1.8T  0 part  
└─sdb9          8:25   0     8M  0 part  
sr0            11:0    1  1024M  0 rom   
nvme1n1       259:0    0 931.5G  0 disk  
├─nvme1n1p1   259:1    0   514M  0 part  
│ └─md127       9:127  0 513.9M  0 raid1 
│   └─md127p1 259:8    0 512.9M  0 part  /boot
├─nvme1n1p2   259:2    0    36G  0 part  [SWAP]
└─nvme1n1p3   259:3    0   895G  0 part  
nvme0n1       259:4    0 931.5G  0 disk  
├─nvme0n1p1   259:5    0   514M  0 part  
│ └─md127       9:127  0 513.9M  0 raid1 
│   └─md127p1 259:8    0 512.9M  0 part  /boot
├─nvme0n1p2   259:6    0    36G  0 part  [SWAP]
└─nvme0n1p3   259:7    0   895G  0 part
swapon --show                                                                                                                                                                                                                                                                 ✔ 
NAME           TYPE      SIZE USED PRIO
/dev/nvme0n1p2 partition  10G   0B   -2
/dev/nvme1n1p2 partition  10G   0B   -3

I used the fstab to mount the swap partitions:

cat /etc/fstab                                                                                                                                                                                                                                                                ✔ 
# Static information about the filesystems.
# See fstab(5) for details.

# <file system>                            <dir> <type> <options> <dump> <pass>
UUID=1A66-24E1                             /boot vfat   defaults  0      0
UUID=5af3f596-1068-457f-9d64-4db5aa649caa  none  swap   defaults  0      0
UUID=388de0df-1d0b-4f78-b6a7-2888859d3fa1  none  swap   defaults  0      0

Please let me know how to solve this issue.
Cheers.

Hi @dobedobedo,

I don’t have much experience, or any really, with SWAP. So I can only point you in this direction:

Edit:

According to this page:

Resizing or moving swap areas: You can’t resize swap areas (as mentioned by Evan Teitelman). And you can’t just swapoff, make a new swap area and then swapon again unless you have enough RAM: swapoff wants to move all the swapped out pages to RAM before letting go of the swap area. So you make a temporary swap area, swapoff the original, wait till all the pages have moved from the old swap area to the temporary one, resize the original swap partition, mkswap it, then swapon the resized one and swapoff the temporary one. The swapped pages are copied from the temporary swap area to the resized one, and you’re done. If you’re moving swap areas, you don’t even need a temporary area. mkswap the new one, swapon it, then swapoff the old one and everything’s moved.

1 Like

How did you create the new swap space?
Did you initialize it (as swap) before trying to use it?
mkswap
is the command to do that

Then you can use it.

btw:
maybe it is a language problem
but swap is not mounted
as there is no filesystem to mount

It looks correct as far as syntax goes, but is this everything there is in your /etc/fstab ?

cat /etc/fstab                                                                                                                                                                                                                                                                ✔ 
# Static information about the filesystems.
# See fstab(5) for details.

# <file system>                            <dir> <type> <options> <dump> <pass>
UUID=1A66-24E1                             /boot vfat   defaults  0      0
UUID=5af3f596-1068-457f-9d64-4db5aa649caa  none  swap   defaults  0      0
UUID=388de0df-1d0b-4f78-b6a7-2888859d3fa1  none  swap   defaults  0      0

as @Mirdarthos or rather his linked source says:
you need to swap off
then you can resize or whatever …
then you initialize it (mkswap)
then you can use it again

or you do it from a usb booted live system …

1 Like

Can you post

  1. fdisk -l
  2. parted -l
    ?
1 Like

For NVME I don’t think it’s a good idea to separate partitions for Swap… so I’d think about doing a backup, get rid of the partitions and then just go with swapfile.

2 Likes

Thanks for everyone’s help. For some reason, the old swap information was kept in my new created partition. After using mkswap on those new swap partitions, it created new UUID on them, and swapon those devices now makes the total swap size 72G. Thanks.
I noticed that swap is not good for nvme, but because my system is on a zfs root, so swapfile or zvol could cause some problems.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.