1

I want to add swap space on my machine running Fedora. Searching on this raised questions:

  1. I found this 2016 post showing a method to do it, but a comment says changing the swap could result in boot issues. Is it safe to follow that method ?

  2. Fedora's doc says it replaced swap with "an emulated drive that uses RAM for its storage". This got me very confused because I thought the whole point of swap was to use the disk memory when the RAM is full.

Anyway, here is my use case: I have a fairly recent laptop with 24GB RAM, and a 1TB SSD which is 5% full. I want to try running some of the new LLaMA-based LLMs, but they need easily tens of GBs of RAM to load the models. Since I have plenty of free space in my SSD I want to turn ~200GB of it into swap space and be able to load the models.

Here is the result of running lsblk (I removed 30 or so lines of snaps):

loop0    7:0    0   104M  1 loop /var/lib/snapd/snap/authy/18
loop1    7:1    0     4K  1 loop /var/lib/snapd/snap/bare/5
...
loop34   7:34   0 320.4M  1 loop /var/lib/snapd/snap/vlc/3078
zram0  252:0    0     8G  0 disk [SWAP]
nvme0n1
       259:0    0 953.9G  0 disk 
├─nvme0n1p1
│      259:1    0   260M  0 part /boot/efi
├─nvme0n1p2
│      259:2    0    16M  0 part 
├─nvme0n1p3
│      259:3    0 269.1G  0 part 
├─nvme0n1p4
│      259:4    0   959M  0 part 
├─nvme0n1p5
│      259:5    0     1G  0 part /boot
└─nvme0n1p6
       259:6    0 634.8G  0 part /home
                                 /
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
Seldi
  • 31
  • 4

1 Answers1

2

What worked

Following Kamil's comment I followed the instructions here.

First try

I partially solved my problem. The method in (1) didn't work, seemingly because btrfs does not allow swap files. So I followed what I read here, and created a file /etc/systemd/zram-generator.conf with the following content:

[zram0]
zram-size = 100000

After a reboot I now have around 100 G of zram:

$ zramctl
NAME       ALGORITHM DISKSIZE  DATA  COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo-rle      97.7G  3.4G 931.5M  1.2G      12 [SWAP]

However when trying to run the LLMs, the swap memory use reached up to 24GB only and then it plateaued and the program was killed by lack of memory. At this point I'm not sure whether the issues lies with zram itself or the program I try to run...

Seldi
  • 31
  • 4
  • "seemingly because btrfs does not allow swap files" – This [used to be an issue](https://superuser.com/a/1067213/432690). Nowadays you can use a swap file on btrfs but [it requires special setup](https://superuser.com/a/1442752/432690). – Kamil Maciorowski Apr 17 '23 at 10:23