Skip to content

Commit 498d70b

Browse files
committed
Add lazy-pages and status-fd options
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 <[email protected]>
1 parent 0d18714 commit 498d70b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

runc.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ type CheckpointOpts struct {
452452
// EmptyNamespaces creates a namespace for the container but does not save its properties
453453
// Provide the namespaces you wish to be checkpointed without their settings on restore
454454
EmptyNamespaces []string
455+
// LazyPages uses userfaultfd to lazily restore memory pages
456+
LazyPages bool
457+
// StatusFile is the file criu writes \0 to once lazy-pages is ready
458+
StatusFile *os.File
455459
}
456460

457461
type CgroupMode string
@@ -493,6 +497,9 @@ func (o *CheckpointOpts) args() (out []string) {
493497
for _, ns := range o.EmptyNamespaces {
494498
out = append(out, "--empty-ns", ns)
495499
}
500+
if o.LazyPages {
501+
out = append(out, "--lazy-pages")
502+
}
496503
return out
497504
}
498505

@@ -511,13 +518,23 @@ func PreDump(args []string) []string {
511518
// Checkpoint allows you to checkpoint a container using criu
512519
func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOpts, actions ...CheckpointAction) error {
513520
args := []string{"checkpoint"}
521+
extraFiles := []*os.File{}
514522
if opts != nil {
515523
args = append(args, opts.args()...)
524+
if opts.StatusFile != nil {
525+
// pass the status file to the child process
526+
extraFiles = []*os.File{opts.StatusFile}
527+
// set status-fd to 3 as this will be the file descriptor
528+
// of the first file passed with cmd.ExtraFiles
529+
args = append(args, "--status-fd", "3")
530+
}
516531
}
517532
for _, a := range actions {
518533
args = a(args)
519534
}
520-
return r.runOrError(r.command(context, append(args, id)...))
535+
cmd := r.command(context, append(args, id)...)
536+
cmd.ExtraFiles = extraFiles
537+
return r.runOrError(cmd)
521538
}
522539

523540
type RestoreOpts struct {

0 commit comments

Comments
 (0)