diff options
author | Jamie Liu <jamieliu@google.com> | 2019-03-14 08:11:36 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-03-14 08:12:48 -0700 |
commit | 8f4634997bd97810a85a70b71f000378d9db2e55 (patch) | |
tree | 903096f91ee8f201fa622296e0f04cf7c7cd9013 /runsc/boot | |
parent | fb9919881c7dc98eaf97cad2a70d187bd78f1566 (diff) |
Decouple filemem from platform and move it to pgalloc.MemoryFile.
This is in preparation for improved page cache reclaim, which requires
greater integration between the page cache and page allocator.
PiperOrigin-RevId: 238444706
Change-Id: Id24141b3678d96c7d7dc24baddd9be555bffafe4
Diffstat (limited to 'runsc/boot')
-rw-r--r-- | runsc/boot/BUILD | 2 | ||||
-rw-r--r-- | runsc/boot/controller.go | 9 | ||||
-rw-r--r-- | runsc/boot/events.go | 2 | ||||
-rw-r--r-- | runsc/boot/loader.go | 26 |
4 files changed, 35 insertions, 4 deletions
diff --git a/runsc/boot/BUILD b/runsc/boot/BUILD index daa197437..df9907e52 100644 --- a/runsc/boot/BUILD +++ b/runsc/boot/BUILD @@ -51,6 +51,8 @@ go_library( "//pkg/sentry/kernel/kdefs", "//pkg/sentry/limits", "//pkg/sentry/loader", + "//pkg/sentry/memutil", + "//pkg/sentry/pgalloc", "//pkg/sentry/platform", "//pkg/sentry/platform/kvm", "//pkg/sentry/platform/ptrace", diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go index a864be720..14e1eba5b 100644 --- a/runsc/boot/controller.go +++ b/runsc/boot/controller.go @@ -332,6 +332,11 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { k := &kernel.Kernel{ Platform: p, } + mf, err := createMemoryFile() + if err != nil { + return fmt.Errorf("creating memory file: %v", err) + } + k.SetMemoryFile(mf) cm.l.k = k // Set up the restore environment. @@ -362,7 +367,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { loadOpts := state.LoadOpts{ Source: o.FilePayload.Files[0], } - if err := loadOpts.Load(k, p, networkStack); err != nil { + if err := loadOpts.Load(k, networkStack); err != nil { return err } @@ -384,7 +389,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { cm.l.mu.Lock() eid := execID{cid: o.SandboxID} cm.l.processes = map[execID]*execProcess{ - eid: &execProcess{ + eid: { tg: cm.l.k.GlobalInit(), }, } diff --git a/runsc/boot/events.go b/runsc/boot/events.go index f954b8c0b..717adfedd 100644 --- a/runsc/boot/events.go +++ b/runsc/boot/events.go @@ -68,7 +68,7 @@ func (cm *containerManager) Event(_ *struct{}, out *Event) error { } func (s *Stats) populateMemory(k *kernel.Kernel) { - mem := k.Platform.Memory() + mem := k.MemoryFile() mem.UpdateUsage() _, totalUsage := usage.MemoryAccounting.Copy() s.Memory.Usage = MemoryEntry{ diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index 9ebe64dce..56cb137f0 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -37,6 +37,8 @@ import ( "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel/auth" "gvisor.googlesource.com/gvisor/pkg/sentry/loader" + "gvisor.googlesource.com/gvisor/pkg/sentry/memutil" + "gvisor.googlesource.com/gvisor/pkg/sentry/pgalloc" "gvisor.googlesource.com/gvisor/pkg/sentry/platform" "gvisor.googlesource.com/gvisor/pkg/sentry/platform/kvm" "gvisor.googlesource.com/gvisor/pkg/sentry/platform/ptrace" @@ -189,6 +191,13 @@ func New(args Args) (*Loader, error) { Platform: p, } + // Create memory file. + mf, err := createMemoryFile() + if err != nil { + return nil, fmt.Errorf("creating memory file: %v", err) + } + k.SetMemoryFile(mf) + // Create VDSO. // // Pass k as the platform since it is savable, unlike the actual platform. @@ -297,7 +306,7 @@ func New(args Args) (*Loader, error) { stdioFDs: args.StdioFDs, rootProcArgs: procArgs, sandboxID: args.ID, - processes: map[execID]*execProcess{eid: &execProcess{}}, + processes: map[execID]*execProcess{eid: {}}, } // We don't care about child signals; some platforms can generate a @@ -404,6 +413,21 @@ func createPlatform(conf *Config, deviceFD int) (platform.Platform, error) { } } +func createMemoryFile() (*pgalloc.MemoryFile, error) { + const memfileName = "runsc-memory" + memfd, err := memutil.CreateMemFD(memfileName, 0) + if err != nil { + return nil, fmt.Errorf("error creating memfd: %v", err) + } + memfile := os.NewFile(uintptr(memfd), memfileName) + mf, err := pgalloc.NewMemoryFile(memfile) + if err != nil { + memfile.Close() + return nil, fmt.Errorf("error creating pgalloc.MemoryFile: %v", err) + } + return mf, nil +} + // Run runs the root container.. func (l *Loader) Run() error { err := l.run() |