Skip to content

Commit aa767e4

Browse files
committed
Merge pull request #16619 from ayushr2:private-mf-no-accounting
PiperOrigin-RevId: 1011135243
2 parents 25172e5 + 0af51ca commit aa767e4

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎runsc/boot/vfs.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,9 @@ func createPrivateMemoryFile(file *os.File, resourceID checkpoint.ResourceID, ci
12251225
DiskBackedFile: true,
12261226
// Disk backed files need to be decommited on destroy to release disk space.
12271227
DecommitOnDestroy: true,
1228+
// Pages of a disk backed file are host page cache for that file, which
1229+
// the host may drop at any time, not memory held by the sandbox.
1230+
DisableMemoryAccounting: true,
12281231
// sentry's seccomp filters don't allow the mmap(2) syscalls that
12291232
// hostmm.IMAWorkAroundForMemFile() uses. Users of private memory files
12301233
// are expected to have performed the work around outside the sandbox.

‎runsc/container/container_save_restore_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,49 @@ func TestCheckpointResume(t *testing.T) {
13721372
}
13731373
}
13741374

1375+
// TestUsageDiskBackedOverlay checks that data in a disk backed overlay is not
1376+
// reported as memory usage, before or after a checkpoint and restore.
1377+
func TestUsageDiskBackedOverlay(t *testing.T) {
1378+
if !testutil.IsCheckpointSupported() {
1379+
t.Skip("Checkpoint not supported")
1380+
}
1381+
conf := overlayTestConfig(t)
1382+
1383+
const size = 64 << 20
1384+
file := filepath.Join(testutil.TmpDir(), "usage-overlay")
1385+
done := file + ".done"
1386+
script := fmt.Sprintf("dd if=/dev/urandom of=%q bs=1M count=%d && echo ok > %q; while true; do sleep 1; done", file, size>>20, done)
1387+
spec := testutil.NewSpecWithArgs("bash", "-c", script)
1388+
bundleDir := setupBundle(t, conf, spec)
1389+
cont := startContainer(t, conf, spec, bundleDir, nil)
1390+
waitForGuestFiles(t, conf, cont, done)
1391+
1392+
checkUsage := func(cont *Container, when string) {
1393+
t.Helper()
1394+
m, err := cont.Sandbox.Usage(true /* Full */)
1395+
if err != nil {
1396+
t.Fatalf("error getting usage %s: %v", when, err)
1397+
}
1398+
if m.Tmpfs >= size {
1399+
t.Errorf("overlay data reported as tmpfs memory %s: got Tmpfs = %d, want < %d", when, m.Tmpfs, size)
1400+
}
1401+
}
1402+
checkUsage(cont, "before checkpoint")
1403+
1404+
dir := makeTempDir(t, "checkpoint")
1405+
if err := cont.Checkpoint(conf, dir, sandbox.CheckpointOpts{}); err != nil {
1406+
t.Fatalf("error checkpointing container: %v", err)
1407+
}
1408+
cont2 := newContainer(t, conf, spec, bundleDir, func(args *Args) {
1409+
args.CheckpointDirPath = dir
1410+
})
1411+
if err := cont2.Restore(conf, dir, sandbox.DirectIOOff, false /* background */, nil /* networkArgs */); err != nil {
1412+
t.Fatalf("error restoring container: %v", err)
1413+
}
1414+
waitForGuestFiles(t, conf, cont2, file)
1415+
checkUsage(cont2, "after restore")
1416+
}
1417+
13751418
func TestSplitFSCheckpointRestore(t *testing.T) {
13761419
// We only run this test if checkpoint/restore is supported.
13771420
if !testutil.IsCheckpointSupported() {

0 commit comments

Comments
 (0)