Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I saw a lot of recommendations claiming that for hibernation the swap partition/file must be at least as large as the main memory. This makes no sense to me. Lets assume I have 8 GB of main memory and 8 GB swap area and want to hibernate:

  • case 1: I'm using 4 GB of virtual memory -> 8 GB of swap is unnecessarily large.
  • case 2: I'm using 8 GB of virtual memory -> 8 GB of swap is just right.
  • case 3: I'm using 12 GB of virtual memory -> 8 GB of swap is too small.

The outcome is: A swap area of size equal to the memory size is sufficient for hibernate IFF it doesn't get used for swapping at all. So what is the reason behind the claim that you need at least as much swap area as main memory for hibernate to work?

I know that virtual memory gets used for caching too, and that the cache may be simply discarded, but what happens to hibernation if a program allocates 12 GB of virtual memory (given the above memory and swap sizes)?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It's quite simple really,

When hibernating the system saves whatever is in RAM to the disk, and if there is not enough room in swap, the system will complain and not allow you to hibernate. To avoid this happening, it is best to have at least the same amount of swap space as your RAM. In most cases, you don't need any more than this, as the majority of applications almost never use enough RAM for swap to be under heavy usage.

However, if you have a small amount of RAM, or if you use a rather heavy application, you will probably want to double the size of your swap to accommodate the memory that needs to be written for hibernation.

share|improve this answer
    
That's OK, but with no amount of swap there's a guarantee that hibernate will succeed (it can be all taken as virtual memory), right? –  maaartinus Mar 13 '11 at 12:07
    
@maaartinus I'm not sure I understand what you're asking me in this comment? You should be able to hibernate if you follow the recommended setup, because applications won't be allowed to go over a certain level of memory (for stability reasons). –  RolandiXor Mar 13 '11 at 13:20
    
OK, I'll try it out. –  maaartinus Mar 13 '11 at 13:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.