Shutdown takes 10 minutes when swap is enabled


Answer: 1

34 hours ago

For over a year now, I have a problem with shutdown. Here are the conditions that need to be met:

  • Swap is enabled
  • Swap is used: I have 8GB and when I start using above 4~5GB, I start seeing stuff in swap. Usually happens when I run virtual machines or big games.

In these cases, when I shutdown the PC, I see the following:

  • Most of the shutdown takes place
  • Do nothing for minutes, even 10 minutes or more
  • Finally shutdown

Of course, at this point I use Alt+SysRq to sync, mount read only and force shutdown.

With swap disabled, I don't have this problem, but I can run out of memory (which hangs Linux for a minute before OOM makes up its mind to kill someone, which is another problem).

Does anyone know what the problem could be? Or how I can debug it?

I tried taking the stack trace with Alt+SysRq, but during shutdown the resolution is low and with four cores, most of the trace is outside the screen, so I can't seem to figure out where it is stalling either.

P.S. I am not sure if I was affected by this in 14.04, but I'm fairly certain it happened before systemd as well as after it.


Silly me, I can scroll back and see the shutdown logs. If I print a stack trace when shutdown gets stuck, three cores are in cupidle_enter_state() or something like that, and the thread printing the stack trace has this trace:

Part 2

Part 1


I thought about doing a swapoff before shutdown, so that perhaps the problem goes away. This showed that the swap is turned off at a super-slow rate of 8MB/s. This may be why the shutdown was so slow in the first place, perhaps it was doing a swapoff. swapoff being slow seems to affect many people. I'll investigate more and write an answer if I can manage to get something conclusive.

Added by: Kaylah Murphy

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9