I am running a python code on jupyter lab which deals with a large list of dataframes and I need to concatenate, compute averages, etc. It is memory consuming, and I take advantage of swapfiles, as memory size is not sufficient.
The problem I am observing is it crashes when memory usage reaches the end of the first swap file.
It appears I am missing something here... I found references, using two swapfiles are possible here, here and here. And this one even says amounts high as 29 swap files are possible!
- my first swapfile is at the root (
/swapfile
).
- The second swapfile I tried was at home (
~/swapfile2
). The 'home' is at a secondary device (SSD) mounted as /home
.
- my primary device (
/
) is a NVMe device (M.2 SSD)
- if I deactivate/remove the
~/swapfile2
, it works fine (if I do not reach the maximum memory+swapfile)
- In both situations, I see, at system monitor, the equivalent of the first swapfile being used with no problem.
- I see no error message, it just crashes, and jupyter lab/chrome closes.
- My system is Ubuntu 22.04.2 LTS
- I checked, and the priority was for the first swapfile (at M.2), which why I am certain to say the crash happens when the first swapfile is fully used...
I am aware of the differences in the speed, and, though I have more space at SSD, I would prefer having the NVMe device being used, at least until reaching its limits. And, unfortunately, I have no more space available at M.2 to increase that first swapfile.
Are there any requirement of such swapfiles being at similar devices (similar speeds, etc.)?
What is the correct way to use two swapfiles?
Thank you in advance,
Update:
Regarding how the swapfiles were set:
sudo fallocate -l 50g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
The same for ~/swapfile2
sudo fallocate -l 50g ~/swapfile2
sudo chmod 600 ~/swapfile2
sudo mkswap ~/swapfile2
sudo swapon ~/swapfile2
echo '~/swapfile2 none swap sw 0 0' | sudo tee -a /etc/fstab
I have tried initially without restarting. After restaring, I saw the 2nd swapfile was deactivated, so I edited the /etc/fstab
(sudo nano /etc/fstab
), as described here. The problem remains even after restarting again after the edited etc/fstab...
Update 2:
I have now managed to release some space on a secondary partition of the same NVMe (same device comprising a partition with the system root '/'). And added a swapfile located there to make a test.
sudo fallocate -l 50g /Data/swapfile2
sudo chmod 600 /Data/swapfile2
sudo mkswap /Data/swapfile2
sudo swapon /Data/swapfile2
echo '/Data/swapfile2 none swap sw 0 0' | sudo tee -a /etc/fstab
With two swapfiles located in different partitions of the same NVMe device, it works fine. I am experiencing the trouble, just when the second swapfile is in the SSD SATA. So I am having more arguments to think it has something with the differences in speed...
All partitions and disks are formated as ext4.
Is there any way to make it work with one (or two) swapfiles at NVMe device and another at SSD SATA?