1

What happens if I execute the command

sudo swapoff -a && swapon -a

having RAM full 25GB/32GB and swap full 20GB/32GB? 25+20 = 45 > 32 so there's no way RAM can fit all operating data. On the other hand, it's only for a few seconds before swap is turned on again.

The goal of it is that the performance of my laptop is better when I restart swap from time to time and I want to use crontab to do it once a day. I don't want to worry what happens if there's not enough memory. I don't care if a swap file is created temporarily to contain the content of the swap partition. I don't want the kernel to kill any processes. Can I somehow instruct kernel that if the RAM capacity is insufficient, it should create a swap file temporarily for swapoff + swapon?

2
  • not sure about linux specifically, but in AIX Unix, swapoff will fail with an error (return code 2, 3, or 4) if there are not sufficient free pages in RAM for the contents of the swap file. ibm.com/docs/es/aix/7.1?topic=s-swapoff-command Commented Jan 11 at 21:18
  • @FrankThomas oh I wouldn't expect that Linux can stop me from being stupid, but you seem to be right as I just checked man, thx let's make it an answer
    – banan3'14
    Commented Jan 11 at 22:26

1 Answer 1

0

swapoff will fail with an error if there are not sufficient free pages in RAM for the contents of the swap file

From man

EXIT STATUS
   swapoff has the following exit status values since v2.36:

   0
       success

   2
       system has insufficient memory to stop swapping (OOM)

   4
       swapoff syscall failed for another reason

   8
       non-swapoff syscall system error (out of memory, ...)

   16
       usage or syntax error

   32
       all swapoff failed on --all

   64
       some swapoff succeeded on --all

   The command swapoff --all returns 0 (all succeeded), 32 (all failed), or 64 (some failed, some succeeded).

   + The old versions before v2.36 has no documented exit status, 0 means success in all versions.
1
  • if someone smarter than me knows better please post your answer, I'm answering based on the @FrankThomas's comment, and I will try it out
    – banan3'14
    Commented Jan 11 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .