2

I need to run some application to convert large files (7GB). The converter application isn't nicely written. So it doesn't stream the coverted data. Therefore, it requires high amount of memory. I have 8GB memory and 8GB swap space. But the application reports a memory usage of around 9GB and stops at 60% of conversion. I assume with some more memory, I can finish the task. As this needs to be done once only, I can maybe allocate some space from my SSD to extend memory temporarily. Only for this operation. Is there any way to do that without messing with partitions?

Thanks!

  • What do you mean by "messing with partitions"? If you want to enlarge your swap partition, for sure you will have to do something with them... Or you might want to create a swapfile, where things get swapped in, but it does not touch partitions. – dadexix86 Apr 09 '16 at 13:07
  • I did not want to change swap partition, that is what I meant. I wasn't aware of the swapfile, I am looking into that right now. Thanks. – Saren Tasciyan Apr 09 '16 at 13:48
  • I never used it myself, so I do not feel confident on giving you more suggestions on that, but please let me know if it does what you want :) – dadexix86 Apr 09 '16 at 13:48

1 Answers1

2

You can indeed use swapfile as temporary addition to your system memory. Personally, I have an SSD and use 1 GB swap file for protection instead of having a partition , since it's a compromise between using the limited disk space, but having extra memory if I ever run out of RAM

First create the file itself

sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

The command will create a file named swapfile inside your root folder, its content being all zeroes and size of 1024 megabytes (1 GB). To make it 2 GB , change count value to 2048

Next, make it read-writable by root only

sudo chmod 600 /swapfile

And format it to swap

sudo mkswap /swapfile

Finally, enable the file

sudo swapon /swapfile

You can disable it at any point using sudo swapoff /swapfile command and remove at will; in addition, since here we don't add it to the /etc/fstab file, it won't be added at next boot, so on the next boot you can remove it

FYI, all this I've turned into a script so that there's an actual single command you can execute to add swap. See How can i increase size of swap file?

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497