Skip to content

Commit

Permalink
Add lazy-pages and status-fd options
Browse files Browse the repository at this point in the history
This makes it possible to checkpoint using
[lazy-pages](https://criu.org/Lazy_migration). This also adds the option
to use a `StatusFile` to get notified as soon as the lazy-pages server
is ready.

Signed-off-by: Cyrill Troxler <cyrilltroxler@gmail.com>
  • Loading branch information
ctrox committed Jul 6, 2020
1 parent 0d18714 commit 498d70b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ type CheckpointOpts struct {
// EmptyNamespaces creates a namespace for the container but does not save its properties
// Provide the namespaces you wish to be checkpointed without their settings on restore
EmptyNamespaces []string
// LazyPages uses userfaultfd to lazily restore memory pages
LazyPages bool
// StatusFile is the file criu writes \0 to once lazy-pages is ready
StatusFile *os.File
}

type CgroupMode string
Expand Down Expand Up @@ -493,6 +497,9 @@ func (o *CheckpointOpts) args() (out []string) {
for _, ns := range o.EmptyNamespaces {
out = append(out, "--empty-ns", ns)
}
if o.LazyPages {
out = append(out, "--lazy-pages")
}
return out
}

Expand All @@ -511,13 +518,23 @@ func PreDump(args []string) []string {
// Checkpoint allows you to checkpoint a container using criu
func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOpts, actions ...CheckpointAction) error {
args := []string{"checkpoint"}
extraFiles := []*os.File{}
if opts != nil {
args = append(args, opts.args()...)
if opts.StatusFile != nil {
// pass the status file to the child process
extraFiles = []*os.File{opts.StatusFile}
// set status-fd to 3 as this will be the file descriptor
// of the first file passed with cmd.ExtraFiles
args = append(args, "--status-fd", "3")
}
}
for _, a := range actions {
args = a(args)
}
return r.runOrError(r.command(context, append(args, id)...))
cmd := r.command(context, append(args, id)...)
cmd.ExtraFiles = extraFiles
return r.runOrError(cmd)
}

type RestoreOpts struct {
Expand Down

0 comments on commit 498d70b

Please sign in to comment.