Skip to content

Commit fd99ee4

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

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

runc.go

+6-1
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

+36-1
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,23 @@ 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+
317334
func TestCreateArgs(t *testing.T) {
318335
o := &CreateOpts{}
319336
args, err := o.args()
@@ -336,6 +353,24 @@ func TestCreateArgs(t *testing.T) {
336353
}
337354
}
338355

356+
func TestCheckpointArgs(t *testing.T) {
357+
o := &CheckpointOpts{}
358+
args := o.args()
359+
if len(args) != 0 {
360+
t.Fatal("args should be empty")
361+
}
362+
o = &CheckpointOpts{
363+
AutoDedup: true,
364+
}
365+
args = o.args()
366+
if len(args) != 1 {
367+
t.Fatal("args should have 1 arg")
368+
}
369+
if actual := args[0]; actual != "--auto-dedup" {
370+
t.Fatalf("arg should be --auto-dedup but got %s", actual)
371+
}
372+
}
373+
339374
func TestRuncFeatures(t *testing.T) {
340375
ctx := context.Background()
341376
if _, err := exec.LookPath(DefaultCommand); err != nil {

0 commit comments

Comments
 (0)