Skip to content

Commit aa7c06c

Browse files
committed
Enable checkpoint/restore auto deduplication of memory images
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
1 parent 4a6db15 commit aa7c06c

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

runc.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ type CheckpointOpts struct {
526526
LazyPages bool
527527
// StatusFile is the file criu writes \0 to once lazy-pages is ready
528528
StatusFile *os.File
529-
ExtraArgs []string
529+
// AutoDedup enables auto deduplication of memory images
530+
AutoDedup bool
531+
ExtraArgs []string
530532
}
531533

532534
// CgroupMode defines the cgroup mode used for checkpointing
@@ -575,6 +577,9 @@ func (o *CheckpointOpts) args() (out []string) {
575577
if o.LazyPages {
576578
out = append(out, "--lazy-pages")
577579
}
580+
if o.AutoDedup {
581+
out = append(out, "--auto-dedup")
582+
}
578583
if len(o.ExtraArgs) > 0 {
579584
out = append(out, o.ExtraArgs...)
580585
}

runc_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func interrupt(ctx context.Context, t *testing.T, started <-chan int) {
287287
}
288288
}
289289

290-
// dummySleepRunc creates s simple script that just runs `sleep 10` to replace
290+
// dummySleepRunc creates a simple script that just runs `sleep 10` to replace
291291
// runc for testing process that are longer running.
292292
func dummySleepRunc() (_ string, err error) {
293293
fh, err := os.CreateTemp("", "*.sh")
@@ -314,6 +314,42 @@ func dummySleepRunc() (_ string, err error) {
314314
return fh.Name(), nil
315315
}
316316

317+
func TestRuncCheckpoint(t *testing.T) {
318+
ctx, cancel := context.WithCancel(context.Background())
319+
defer cancel()
320+
321+
okRunc := &Runc{
322+
Command: "/bin/true",
323+
}
324+
325+
opts := &CheckpointOpts{
326+
AutoDedup: true,
327+
}
328+
err := okRunc.Checkpoint(ctx, "fake-id", opts)
329+
if err != nil {
330+
t.Fatalf("unexpected error from Checkpoint: %v", err)
331+
}
332+
}
333+
334+
func TestRuncRestore(t *testing.T) {
335+
ctx, cancel := context.WithCancel(context.Background())
336+
defer cancel()
337+
338+
okRunc := &Runc{
339+
Command: "/bin/true",
340+
}
341+
342+
opts := &RestoreOpts{
343+
CheckpointOpts: CheckpointOpts{
344+
AutoDedup: true,
345+
},
346+
}
347+
_, err := okRunc.Restore(ctx, "fake-id", "fake-bundle", opts)
348+
if err != nil {
349+
t.Fatalf("unexpected error from Checkpoint: %v", err)
350+
}
351+
}
352+
317353
func TestCreateArgs(t *testing.T) {
318354
o := &CreateOpts{}
319355
args, err := o.args()
@@ -336,6 +372,24 @@ func TestCreateArgs(t *testing.T) {
336372
}
337373
}
338374

375+
func TestCheckpointArgs(t *testing.T) {
376+
o := &CheckpointOpts{}
377+
args := o.args()
378+
if len(args) != 0 {
379+
t.Fatal("args should be empty")
380+
}
381+
o = &CheckpointOpts{
382+
AutoDedup: true,
383+
}
384+
args = o.args()
385+
if len(args) != 1 {
386+
t.Fatal("args should have 1 arg")
387+
}
388+
if actual := args[0]; actual != "--auto-dedup" {
389+
t.Fatalf("arg should be --auto-dedup but got %s", actual)
390+
}
391+
}
392+
339393
func TestRuncFeatures(t *testing.T) {
340394
ctx := context.Background()
341395
if _, err := exec.LookPath(DefaultCommand); err != nil {

0 commit comments

Comments
 (0)