Fedora 19のfeatureリストを見ていたらプロセスのダンプ・リストア機能が入っていたのでちょっと試してみました。
機能としてはカーネルのコンフィグでCONFIG_CHECKPOINT_RESTOREが有効になっていることと、crtoolsパッケージのインストールが必要です。
Fedoraのconfig-3.9.6-301.fc19.x86_64を見たところCONFIG_CHECKPOINT_RESTOREは有効になっているのでcrtoolsパッケージをインストールするだけです。
自分はカーネルは3.10-rc7を使って実験しました。
まずはシングルスレッドのプロセスで実施。1874がpidです。
これは4回目のループを行ったときにcrtoolsコマンドでダンプを取った時のログです。Checkpointはデフォルトではプロセスをkillするようです。
killされたくない場合は-sオプションを使うとSGIKILLの代わりにSIGSTOPが送られるので、Checkpoit処理完了後に再開させることができます。
[masami@saga:~/checkpoint_restore_test]$ ./single_thread 1874:loop 0 1874:loop 1 1874:loop 2 1874:loop 3 zsh: killed ./single_thread
こちらがダンプを実行した側です。-Dオプションでダンプファイルの置き場所を指定してます。
[masami@saga:~/checkpoint_restore_test]$ sudo crtools dump -t 1874 -j -D dump_files
ダンプファイルは以下のように複数できます。
[masami@saga:~/checkpoint_restore_test]$ ls . .. dump_files inventory.img single_thread single_thread.c thread_test.c [masami@saga:~/checkpoint_restore_test]$ ls dump_files . eventfd.img fanotify-mark.img filelocks-1874.img inotify.img mm-1874.img pipes.img rlimit.img tty.img .. eventpoll.img fdinfo-2.img fs-1874.img inotify-wd.img packetsk.img pstree.img sigacts-1874.img tty-info.img core-1874.img eventpoll-tfd.img fifo-data.img ids-1874.img inventory.img pages-1874.img reg-files.img signalfd.img unixsk.img creds-1874.img fanotify.img fifo.img inetsk.img itimers-1874.img pipes-data.img remap-fpath.img sk-queues.img vmas-1874.img
また、シェルのプロセスの場合-jオプションを付けないと以下のように怒られます><
[masami@saga:~/checkpoint_restore_test]$ sudo crtools dump -t 1776 (00.006072) Error (tty.c:1020): tty: Found sid 1680 pgid 1776 (pts) on peer fd 0. Missing option?
ダンプに成功したらリストアを試します。コマンドとしてはdumpがリストアに変わったのと-sオプションが無いくらいです。
[masami@saga:~/checkpoint_restore_test]$ sudo crtools restore -t 1874 -j -D dump_files 1874:loop 4 1874:loop 5 1874:loop 6 1874:loop 7 1874:loop 8 1874:loop 9 ^C% [masami@saga:~/checkpoint_restore_test]$
pidも1874が使われ、ループの開始位置も4からで正常にプロセスがリストアされたのが確認できます。
メインスレッド+サブスレッド2個のプロセスの場合でメインスレッドをダンプ。これも良い感じですね。
ここで出してるtidはgettid()で取得したlwpのpidです。
*ダンプの実行は別のターミナルで、リストアはプロセスを起動したターミナルで実行してます。
[masami@saga:~/checkpoint_restore_test]$ ./threads [-]pid = 10687 : tid = 10687 : thread id = 139687326631744 [-]pid = 10687 : tid = 10688 : thread id = 139687326627584 [-]sleep time is 1 [-]pid = 10687 : tid = 10689 : thread id = 139687318234880 [-]sleep time is 2 [-]tid 139687326627584 : 0 [-]tid 139687318234880 : 0 [-]tid 139687326627584 : 1 [-]tid 139687326627584 : 2 [-]tid 139687318234880 : 1 [-]tid 139687326627584 : 3 zsh: killed ./threads [masami@saga:~/checkpoint_restore_test]$ sudo crtools restore -D ./dump_files -j -t 10687 [-]tid 139687318234880 : 2 [-]tid 139687326627584 : 4 [-]tid 139687326627584 : 5 [-]tid 139687318234880 : 3 [-]tid 139687326627584 : 6 [-]tid 139687326627584 : 7 [-]tid 139687318234880 : 4 [-]tid 139687326627584 : 8
最後にメインスレッドのpidではなく、サブスレッドのpidをダンプ・リストアするとどうなるか。
[masami@saga:~/checkpoint_restore_test]$ ./threads [masami@saga:~/checkpoint_restore_test]$ ./threads [-]pid = 13601 : tid = 13601 : thread id = 140271785342784 [-]pid = 13601 : tid = 13602 : thread id = 140271785338624 [-]sleep time is 1 [-]pid = 13601 : tid = 13603 : thread id = 140271776945920 [-]sleep time is 2 [-]tid 140271785338624 : 0 [-]tid 140271776945920 : 0 [-]tid 140271785338624 : 1 [-]tid 140271785338624 : 2 [-]tid 140271776945920 : 1 [-]tid 140271785338624 : 3 [-]tid 140271785338624 : 4 [-]tid 140271776945920 : 2 [-]tid 140271785338624 : 5 [-]tid 140271785338624 : 6 [-]tid 140271776945920 : 3 [-]tid 140271785338624 : 7 [-]tid 140271785338624 : 8 [-]tid 140271776945920 : 4 [-]tid 140271785338624 : 9 [-]tid 140271785338624 : 10 [-]tid 140271776945920 : 5 [-]tid 140271785338624 : 11 [-]tid 140271785338624 : 12 [-]tid 140271776945920 : 6 [-]tid 140271785338624 : 13 [-]tid 140271785338624 : 14 [-]tid 140271776945920 : 7 [-]tid 140271785338624 : 15 [-]tid 140271785338624 : 16 [-]tid 140271776945920 : 8 [-]tid 140271785338624 : 17 [-]tid 140271785338624 : 18 zsh: killed ./threads [masami@saga:~/checkpoint_restore_test]$ sudo crtools restore -t 13602 -D dump_files (00.001056) 13601: Error (tty.c:178): tty: Found slave peer index 1 without correspond master peer (00.001207) Error (cr-restore.c:902): 13601 exited, status=255 (00.001226) Error (cr-restore.c:1209): Someone can't be restored
ダンプは成功しますが、リストアは失敗しますね。といっても予想通りな動きで問題無いですが。
ということで、Checkpoint/Restore機能の簡単な実験でした(´∀`*)ノシ バイバイ