11

I often tend to just put my laptop on suspend using xfce4-power-manager, and although usually the battery is sufficiently charged up until the next time (when I plug in the charger), sometimes I forget and after a week or so the battery empties out and the laptop shuts itself down (forcefully).

In these cases, is there any risk of data corruption? I would assume that no, since the hard-drive has already synced and was turned off upon suspend.

Additionally, should one prefer suspend, hibernate or some hybrid variant?

8

Suspending implies that the data you were working with is in the memory. This state will be lost if you run out of power. If you were writing a forum post, for example, it will be lost, but nothing more serious would happen. Think that it's less serious than unplugging and removing the battery, since the computer can sync before and even delay the suspension (when running an update or upgrade).

For obtaining both the benefits of suspend (fast re-start) and hibernate (safely saved to disk, without power consumption) try pm-suspend-hybrid instead. If you run out of power you can re-start from the image saved to disk, if you don't run out of power you can quickly re-start from a suspended to memory state.

  • 1
    "but nothing more serious would happen." Just to be clear, this means that no corruption of hard-drive sectors can occur? In other words, you would lose anything that you didn't already save to disk (as expected), but anything that resides on the disk is safe and sound. Correct? – landroni Feb 16 '14 at 13:44
  • 1
    @landroni: right. – Quora Feans Feb 16 '14 at 17:05
2

There are two things to think about here, as hinted at by other answers.

The first is File System Corruption. This relates to the meta-data structures that makes the file system usable, and is understood and controlled by the Kernel.

The second is the content of the files. When the content of a file is corrupted, the kernel will not know (or care). Complex systems like databases implement their own meta-data facilities to take care of this problem, but for most file types on a typical desktop system there is no such thing.

If you are editing a file, a "change" to the file might consist of writes to several locations. When all of these writes have been completed, the file is in a consistent state, but when only some of these writes are completed the file contents may be corrupted (inconsistent)

The operating system will (should) "group" related writes into a transaction. So, for example when a file grows, the data must be written to the blocks belonging to that file, and the file system structures be updated to allocate those new blocks to the file, and possible changes to the directory entry (eg last modification time) be updated, all as a single group. Once all of this is Sync'ed (flushed) to disk, the file system will be consistent again, but the file contents may not be until all the relevant writes have been submitted by the application and flushed to disk by the operating system.

If the application is in the middle of a complicated change and gets blocked before all the transactions have been issued, for example you press SAVE and immediately close your laptop lid, the entire group of changes may not all make it to the kernel's write queues.

Generally whatever is in the write queues will be flushed to disk. The file systems should, generally, be consistent. Due to File system journals though this might mean that some of those changes are temporarily in a log, albeit safely on disk.

File contents however is another story.

1

Data corruption? Most likely no. Data loss? possibly.

The data that would be at risk when the system loses power during a suspend would be the only things at risk. This data is the "snapshot" of the system's memory that's been temporarily written to disk when you put the system into "suspend" mode. No harm should ever come to your HDD or the data that's present on the HDD.

The data on your system should be safe so long as you've selected that the system "poweroff" if the battery gets into a "critically low" state, as seen in this dialog, under your system's power settings.

    ss #1

versus this:

    ss #2

  • 2
    Hmm, how is this possible? Perhaps you use hibernate? Because when you use suspend, if the laptop runs out of juice, it shuts down and then you basically do a cold boot. (At least here after suspend and a loss of power it never resumes from where it left.) – landroni Feb 16 '14 at 9:53
  • @landroni - see updates. – slm Feb 16 '14 at 13:07
  • @landroni - does this explain it better? – slm Feb 16 '14 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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