summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/pgalloc/pgalloc.go
diff options
context:
space:
mode:
authorJamie Liu <jamieliu@google.com>2019-05-10 13:36:56 -0700
committerShentubot <shentubot@google.com>2019-05-10 13:37:48 -0700
commit5ee8218483ce172400c21780d5dbc1ec2ba54d63 (patch)
tree94aa884f856324a8b82669358cc4ca9309cc3efa /pkg/sentry/pgalloc/pgalloc.go
parent1bee43be13549b01e18d87df194ac219845de5cf (diff)
Add pgalloc.DelayedEvictionManual.
PiperOrigin-RevId: 247667272 Change-Id: I16b04e11bb93f50b7e05e888992303f730e4a877
Diffstat (limited to 'pkg/sentry/pgalloc/pgalloc.go')
-rw-r--r--pkg/sentry/pgalloc/pgalloc.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/pkg/sentry/pgalloc/pgalloc.go b/pkg/sentry/pgalloc/pgalloc.go
index 9c1313f6f..2b9924ad7 100644
--- a/pkg/sentry/pgalloc/pgalloc.go
+++ b/pkg/sentry/pgalloc/pgalloc.go
@@ -190,6 +190,11 @@ const (
// reclaimer goroutine is out of work (pages to reclaim), then evicts all
// pending evictable allocations immediately.
DelayedEvictionEnabled
+
+ // DelayedEvictionManual requires that evictable allocations are only
+ // evicted when MemoryFile.StartEvictions() is called. This is extremely
+ // dangerous outside of tests.
+ DelayedEvictionManual
)
// usageInfo tracks usage information.
@@ -264,7 +269,7 @@ func NewMemoryFile(file *os.File, opts MemoryFileOpts) (*MemoryFile, error) {
switch opts.DelayedEviction {
case DelayedEvictionDefault:
opts.DelayedEviction = DelayedEvictionEnabled
- case DelayedEvictionDisabled, DelayedEvictionEnabled:
+ case DelayedEvictionDisabled, DelayedEvictionEnabled, DelayedEvictionManual:
default:
return nil, fmt.Errorf("invalid MemoryFileOpts.DelayedEviction: %v", opts.DelayedEviction)
}
@@ -1075,6 +1080,14 @@ func (f *MemoryFile) markReclaimed(fr platform.FileRange) {
}
}
+// StartEvictions requests that f evict all evictable allocations. It does not
+// wait for eviction to complete; for this, see MemoryFile.WaitForEvictions.
+func (f *MemoryFile) StartEvictions() {
+ f.mu.Lock()
+ defer f.mu.Unlock()
+ f.startEvictionsLocked()
+}
+
// Preconditions: f.mu must be locked.
func (f *MemoryFile) startEvictionsLocked() {
for user, info := range f.evictable {
@@ -1122,6 +1135,12 @@ func (f *MemoryFile) startEvictionGoroutineLocked(user EvictableMemoryUser, info
}()
}
+// WaitForEvictions blocks until f is no longer evicting any evictable
+// allocations.
+func (f *MemoryFile) WaitForEvictions() {
+ f.evictionWG.Wait()
+}
+
type usageSetFunctions struct{}
func (usageSetFunctions) MinKey() uint64 {