Slashdot Mirror


UNIX Process Cryogenics?

shawarma asks: "Due to a recent power outage, I've had to shut down a server running a process that had been running for ages calculating something. The job it was doing would have been done in a few days, I think, but I had to shut it down before the UPS ran out of juice. This got me thinking: Why can't I freeze down the process and thaw it back up at a later time? It ought to be possible to take all the connected memory pages and save them in some way, preserve file handles and pointers, and everything. Maybe net-connections would die, but that's understandable. Has any work been done in this field? If not, shouldn't there be? I'd like to contribute in some way, but I think it's a bit over my head.." Laptops have been doing this in some form for years: most laptops, when they run out of power, or when told by the user will go into "suspend" mode which is similar to what the poster is describing, however outside of laptops, I haven't seen this done. Sleeping processes also do something similar, sending their memory pages into swap so other running processes can use the memory. What, if anything, is preventing someone from taking this a step further?

28 of 555 comments (clear)

  1. the mode you are speaking of by Stone+Rhino · · Score: 2, Informative

    is not suspend, it is hibernate. Suspend will power down the computer except for the energy needed to keep the ram alive. hibernate will save all data to from memory to disk. I, personally, use neither on my laptop.

    --


    Remember, there were no nuclear weapons before women were allowed to vote.
    1. Re:the mode you are speaking of by Timbo · · Score: 2, Informative

      What you refer to as suspend is what most people (and APM) call standby. What you call hibernate is what APM refers to as suspend. I believe Windows uses the term hibernate to refer to a software suspend function.

    2. Re:the mode you are speaking of by SilentChris · · Score: 2, Informative

      *Sigh*. More people with very little experience with laptops. Read the mini-faq, people.

  2. We do it in Condor by epaulson · · Score: 5, Informative

    http://www.cs.wisc.edu/condor/

    Free-as-in-beer, on most major UNIX platforms. Check out our publications, we have several that give all the details you'd need to write it yourself.

    Plenty of others, too - libckpt, there was a "Checkpointing Threaded Programs" paper at USENIX this past summer... there are some kernel patches that can do, most of them under the GPL.

    1. Re:We do it in Condor by dsouth · · Score: 5, Informative

      As the poster said, there are plenty of others:

      • SGI IRIX and Cray UNICOS provide kernel-level checkpoint-restart.
      • Condor provides user-level checkpoint restart and process migration by manipulating libraries at runtime.
      • esky provides user-level checkpoint restart under Solaris and Linux via runtime library manipulation.
      • crak provides kernel-level checkpoint restart for linux.
      • cocheck provides user-level checkpoint-restart.
      • libckpt provides user-level checkpoint-restart.


      I'm sure I left serveral out. Checkpoint-restart has been part of the high-performance computing scene for years. Having been a systdmin on large, high-performance, computing platforms for the last few years of my professional life, my experiences with checkpoint-restart have been a mixed bag. All of the existing systems have limitations. Depending on the application, those limitations can be no problem, or they can be deal-breakers.
  3. you can by Lumpy · · Score: 5, Informative

    It's called software suspend for linux. look for it on freshmeat.net

    --
    Do not look at laser with remaining good eye.
    1. Re:you can by Lumpy · · Score: 5, Informative

      AHA! I knew I still had it
      http://falcon.sch.bme.hu/~seasons/linux/swsusp.htm l

      this is what you need.

      --
      Do not look at laser with remaining good eye.
    2. Re:you can by i_am_nitrogen · · Score: 3, Informative

      There's just one tiny little problem with that. It only supports ext2. Try it with a journalling filesystem, and ... bye bye Linux partition!
      At least, last time I checked that's how it was. There may have been improvements made. It would require somewhat major changes to the VM and each filesystem in the current Linux implementation to get it working with journalled systems, or if Linux finally gets a journal-capable VM (similar to IRIX's, perhaps), it would just require some VM changes if it's done right.

      (Begin semi-OT stuff)
      Oh, and please, please everyone ask Linus not to rip out memory zones just because it's a BSD-like idea.

      Kernel 2.6 will probably be able to support hibernation without funkiness in the filesystems themselves, just a good VM setup. The new framebuffer system (Ruby) will rock, too (think 'echo "640x480-16@60" > /dev/gfx/fb/0/mode'), especially because DRI is going to be separated from X so console applications can take advantage of OpenGL as well.

  4. Suspend by selectspec · · Score: 4, Informative

    You can't just serialize and page out one process. Under every process are a slew of kernel objects and kernel crud including the virtual to physical mappings of your address space. It would be quite a challenge to isolate all of this and somehow persist it.

    To make suspend work, you'd have to dump your entire memory image to disk. Then you swap in the entire image, kernel and user pages alike.

    --

    Someone you trust is one of us.

  5. Solaris Suspend & Resume by morcheeba · · Score: 3, Informative

    I've used the Suspend/Resume feature on a sun box. IIRC, it mostly worked, but with a minor hitch that made me worry enough to never do it again. This suspend/resume is just like the laptop version -- save a copy of all memory to disk -- not the cryogenic per-process version you're talking about.

    The per-process sounds neat, but usable only if you've got a simple critical task you're running. For a more complicated application, multiple processes may be working together, and you'd have to suspend all of them at the same time.
    One big question I would have would be file handles... if you restore a process that thinks it owns file handle #5 and some other process is already using it, it would be awkward to get either process to use a different handle.

  6. VMWare by Creedo · · Score: 2, Informative

    Vmware does this for the VM's it hosts. Works great.

    Creed

    --
    All that is necessary for the triumph of good is that evil men do nothing.
  7. Been there, done that by jstott · · Score: 2, Informative
    Look at the makefile for emacs--the emacs executable is essentially a memory dump of a partially initialized emacs process. Perl's dump and undump work the same way.

    For long-running processes, rather than shut down the process when the UPS kicks in, I've always found it easier to have the program snapshot its data tables periodically (say every half-hour) and build a "resume from disk" feature into the program. This lets you restart the program from its last check-point even in the event of uncontrolled program termination (e.g. kill -9 and the like).

    -JS

    --
    Vanity of vanities, all is vanity...
  8. EPCKPT by cmason · · Score: 5, Informative
    EPCKPT is a checkpoint/restart utility built into the Linux kernel. Checkpointing is the ability to save an image of the state of a process (or group of processes) at a certain point during its lifetime.

    --

    --
    "If you are an idealist it doesn't matter what you do or what goes on around you, because it isn't real anyway."-R.P.W.
  9. Re:Really worth the effort? by kdawg6000 · · Score: 3, Informative

    If you are a grad student who has been waiting for a month for a job to finish...this could be very important. I was in an engineering department where jobs that ran for weeks were not uncommon (fortunately most of mine only took a day or two). A shutdown of a critical machine could set someone back months.

  10. Software suspend by Timbo · · Score: 2, Informative

    Linux software suspend may be of interest.

  11. Windows 2000 and Hibernation by doorbot.com · · Score: 5, Informative
    If you have a Windows 2000 or XP machine you can enable hibernation. However, this is not a "power management" feature... it has been separated from ACPI and/or proprietary disk partitions and will work on all computers, even servers, whether they have ACPI/APM/nothing for power management.

    Once you've enabled it, you create a hibernation file on the C: drive. Hibernation should only take place when there is minimal disk activity (eg, don't hibernate while trying to save your Word document). The system saves the contents on RAM to the hard drive, and then shuts down. When the machine boots, a flag was set (I assume) indicating the system should resume from hibernation... so the hibernation file is read from disk and written to RAM and you're back up and running, in less time than it takes to boot. Plus it keeps your uptime from resetting back to zero.

    Some things to note:

    You will need WHQL certified drivers, or at least properly-written drivers. I have a SB Audigy and the first drivers I used (the ones on the included CD) caused a blue screen on resume from hibernation. When a updated driver was released, it fixed this issue.

    Applications need to be properly-written as well, as there is some sort of Win32 suspend signal that is sent to apps just before the system hibernates, so the app must support this and the resume command when the system is restored.

    Hibernation works great on my laptop and on my workstation, and I especially like the fact that I don't need to create a separate partition or install special drivers to make it work (you can even use it on an NTFS formatted drive).

  12. Process-saving is known, but not what you want by Seth+Finkelstein · · Score: 4, Informative
    The idea of saving the state of a process is very well-known. Take a look at anything from emacs dumping to the gcore(1) program. It's been used in everything from saved games of Rogue to saved states of PERL.

    But isn't it overkill for a data-crunching operation? As many other people have noted, it would seem you're much better off checkpointing your data to disk, rather than relying on low-level OS process wizardry.

    Sig: What Happened To The Censorware Project (censorware.org)

  13. Re:This CAN be trivially done on any un*x i know.. by xyzzy · · Score: 3, Informative

    You can't. The previous poster was making it sound too easy. Real checkpointing needs to save Kernel state as well -- file handles, device driver state, you name it. It isn't as simple as saving the in-memory image of the process.

  14. doesnt SETI@home do this, sorta? by Pharmboy · · Score: 3, Informative
    seti@home kinda does it.

    the seti@home client uses its *.sah files to save the state of a calculation. of course, this is program dependent, not OS dependent. I guess if you have the source files for the program doing the counting.....

    --
    Tequila: It's not just for breakfast anymore!
  15. STANDALONE CONDOR CHECKPOINTING by Anonymous Coward · · Score: 5, Informative

    STANDALONE CONDOR CHECKPOINTING:

    Using the Condor checkpoint library without the remote system call functionality and outside of the Condor system is known as
    "standalone" mode checkpointing.

    To link in standalone mode, follow the instructions for linking Condor executables, but replace condor_syscall_lib.a with libckpt.a. If you
    have installed Condor version 5.62 or above, you can easily link your program for standalone checkpointing using the condor_compile
    utility with the little-known "-condor_standalone" option. For example:

    condor_compile -condor_standalone [options/files....]

    where is any of cc, f77, gcc, g++, ld, etc. Just enter "condor_compile" by itself to see a usage summary, and/or refer to
    the condor_compile man page for additional information.

    Once your program is relinked with the Condor standalone-checkpointing library (libckpt.a), your program will sport two new command
    line arguments: "_condor_ckpt " and "_condor_restart ".

    If the command line looks like:

    exec_name -_condor_ckpt ..

    then we set up to checkpoint to the given file name.

    If the command line looks like:

    exec_name -_condor_restart ...

    then we effect a restart from the given file name.

    Any Condor command line options are removed from the head of the command line before main() is called. If we aren't given
    instructions on the command line, by default we assume we are an original invocation, and that we should write any checkpoints to the
    name by which we were invoked with a "ckpt" extension.

    To cause a program to checkpoint and exit, send it a SIGTSTP signal. For example, in C you would add the following line to your code:

    kill( getpid(), SIGTSTP );

    Note that most Unix shells are configured to send a TSTP signal to the foreground process when the user enters a Ctrl-Z. To cause a
    program to write a periodic checkpoint (i.e., checkpoint and continue running), sent it a SIGUSR2:

    kill( getpid(), SIGUSR2 );

    In addition to the command-line parameters interface described above, a C interface is also provided for restarting a program from a
    checkpoint file. The prototypes are:

    void init_image_with_file_name( char *ckpt_name );

    void init_image_with_file_descriptor( int fd );

    void restart( );

    The init_image_with_file_name() and init_image_with_file_descriptor() functions are used to specify the location of the checkpoint file.
    Only one of the two must be used. The restart() function causes the process image from the specified file to be read and restored.

  16. Search in the slashdot archives for kernel patches by Alan · · Score: 5, Informative

    I think it was somewhere in the list of patches from the -mjc tree (see here) that there was a patch for the entire kernel for linux. Basically it let the system save it's state, and then restore it if it detects that it was shut down at that point. I'm not sure if this is what you want (and I couldn't get it working), but it's certainly a step in the right direction to what you're looking for.

    Just found it here, it's the 'swsusp' patch.

  17. Darwin/MacOS X by Duck_Taffy · · Score: 4, Informative

    Here's a mutation of FreeBSD that can do exactly that. I've put my laptop to sleep in the middle of installing software while running MacOS X and brought it back up several hours later to resume installation with no problems. The same function works on my G4 tower. Yes, it does drop network connections. However, it does use a trickle charge to power the LED's and presumably to keep the processor alive, and possibly some memory. Paging several hundred megabytes in a couple of seconds would be quite the task! One item of note is that all Apple machines have a special piece of hardware known as the PMU (Power Management Unit). In the desktops, it's parted out onto the mother board and into the power supply, but in the laptops it's a seperate card which controls both sleep and the charging of the battery. Perhaps other UNIX machines would need a similar device for this function to work properly.

    --
    Karma: Ran over your dogma.
  18. File Descriptors are per-process by parc · · Score: 3, Informative

    A file descriptor is a per-process entity. Yes, there's a big table of file descriptors that exists for the entire sstem, but file descriptor 5 for process a is not file descriptor 5 for process b. Not even if they point to the same file/pipe. A case in point is FD 0, aka stdin. Every process starts out with a stdin on FD 0.

    More important is how do you tell the kernel what file descriptor 5 pointed to? What if the file/pipe doesn't exist any more?

  19. Re:Search on "Checkpointing" by duplicate-nickname · · Score: 2, Informative

    The condor project is still alive and well: http://www.cs.wisc.edu/condor/ and should do what this guy wants to accomplish (but not what he's asking).

    --

    ÕÕ

  20. Re:Hibernation comments are missing the point by The+Smith · · Score: 2, Informative
    You mean like: run for four hours, force a core dump by pressing Ctrl-\, and then re-run the last five minutes as many times as you want?

    You don't need hibernation for that.

  21. Re:Use Windows XP - OT by ADRA · · Score: 2, Informative

    Yeah, not really relevent to the main topic, but any modern PC's do have suspend support built into them, so the no-additional software thing is a pretty moot point.

    Hibernation IS a software thing, and it just means that when the OS receives or generates a shudown-hibernate event, that the OS writes all available memory and state to disk and shutdown, setting a flag that the OS can know that it was hibernated to begin with.

    --
    Bye!
  22. A case for Python by defile · · Score: 3, Informative

    Python supports a concept that it calls 'pickling' (which is also known as Object Serialization).

    It's extremely easy to save the state of any object along with the objects it references to disk with literally a couple of lines of code (like, 3). You cannot pickle whole processes, but it's effortless to write some skeleton code to resume the process from its last pickle. You can also define specific methods in each object that are called on pickle/unpickle for special cases (restoring network connections, for example).

    The fact that it's an interpreted language shouldn't deter you. Python integrates easily with modules compiled from C, allowing you to accelerate time critical aspects of your code while rapidly developing the not so critical aspects.** Python was designed to solve the problems you're working on.

    Oh, and if you're short on time, don't worry; Python is extremely easy to learn.

    ** As most programmers have found, about 90% of their program's execution is spent in 5% of their code.

  23. EROS is an entire operating system based on it by jeske · · Score: 2, Informative
    EROS is a research operating system built around the idea of making all processes persistant at all times.

    EROS' predecessor, KeyKOS, made waves at USENIX when they did a demo of a UNIX system + Xwindows which would instantly restore the running state of all software when rebooted. It was basically a UNIX port to KeyKOS, and since everything in KeyKOS was persistant, so was everything in the UNIX.

    One interesting caviat with this type of OS is that you really need to use ECC memory, because bit errors can get saved to disk and propagated forever!