How to enlarge swap space on a linux VPS in order to compile an R package?

1

1

Matt Lacey explained how to compile dplyr on low memory VPS. He managed to install dplyr by adding a larger swap space. Unfortunately this operation is not permitted on my VPS (Virtual Private Server): "swapon failed: Operation not permitted". Here is the output:

$ sudo fallocate -l 1G /swapfile    
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3bfbcf12-6b81-46b4-96b0-7de37fa1640b
$  sudo swapon /swapfile
swapon: /swapfile: swapon failed: Operation not permitted
$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/null                               partition       131072  3060    -1

EDIT I used other instructions from digitalocean to create a swap file. But they failed too:

sudo swapon /var/swap.img 
swapon: /var/swap.img: swapon failed: Operation not permitted

There is a related issue in the dplyr package's repository.

Are there other, recommended ways to enlarge the swap space?

Paul Rougieux

Posted 2015-12-18T09:35:25.547

Reputation: 167

Are you on an OpenVZ machine? If so, then you may take a look at this purported trick, http://www.serveridol.com/2014/08/03/how-do-i-create-swap-partition-in-linux-mkswap-operation-not-permitted/, which is widely discussed on the Net. I never tried it myself, so I will not try to sell it as the solution, but given the dire straits you seem to find yourself in, it might be worth a try.

– MariusMatutiae – 2015-12-18T09:49:22.087

Look interesting. Might get you in trouble if you abuse it, but this might be an option if you needed it just once and right now. (As opposed to waiting to the VPS provider). @Paul4forest. If this works then please leave some feedback. – Hennes – 2015-12-18T10:13:58.047

Yes, pls, leave a feedback if this works. But then, on a different note: do you really want to run the R statistics package on such a small server??? It will easily hog out all of your resources. – MariusMatutiae – 2015-12-18T12:11:04.413

@MariusMatutiae the link you posted proposes 2 solutions: (1) create a swap file or (2)create a swap partition. I used instruction from digitalocean to create a swap file. But this is not permitted swapon: /var/swap.img: swapon failed: Operation not permitted. I didn't figure out how to do option (2), since ls /dev doesn't show me any sda.

– Paul Rougieux – 2015-12-18T12:38:59.087

This small server is good enough to process a gigabyte of data and share the result in the form of static files. – Paul Rougieux – 2015-12-18T12:39:19.223

1The link I posted has a solution starting with Create a script file named “create_swap.sh”. That's what you should try to do. It is quite different from what you have tried so far. – MariusMatutiae – 2015-12-18T13:09:45.503

Executing the script file fails with the message: #sh create_swap.sh create_swap.sh: 2: create_swap.sh: Bad substitution. – Paul Rougieux – 2015-12-18T13:35:16.493

Running the script with bash instead of sh doesn't return an error. sudo bash create_swap.sh 4096. But it doesn't add any swap space. I still have mem total 1024 and swap total 128. @MariusMatutiae To answer your first question I am on openVZ. – Paul Rougieux – 2015-12-22T07:40:40.123

Answers

1

No, you can either:

  • Add a parttion to page to,
  • or add a file (as you tried) to page to,
  • or add more physical memory,
  • or ask the VPS provider to allocate more resources.

Alternatively, you could compile it on a different host and upload it to the VPS. (e.g. compile, create .rpm or whatever package manager you use on the VPS, upload that rpm).

Hennes

Posted 2015-12-18T09:35:25.547

Reputation: 60 739

1

Purchasing more physical memory is not an option for this small project. I am using a little test server for 2 € per month. I use it mostly for long running processes and do not want to upgrade. I will try to add a swap partition based on instructions from the VPS provider. *** Thank for suggesting an alternative to compile on a different host. I am using a Debian host and these Debian packaging instructions for R software might help.

– Paul Rougieux – 2015-12-18T10:49:53.183

An alternative as mentioned here, would be to compile the package on my local machine by using the distributed compiler distcc.

– Paul Rougieux – 2015-12-18T12:57:48.353