summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/kernel/memevent
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/kernel/memevent')
-rw-r--r--pkg/sentry/kernel/memevent/BUILD32
-rw-r--r--pkg/sentry/kernel/memevent/memory_events.go111
-rw-r--r--pkg/sentry/kernel/memevent/memory_events.proto29
3 files changed, 0 insertions, 172 deletions
diff --git a/pkg/sentry/kernel/memevent/BUILD b/pkg/sentry/kernel/memevent/BUILD
deleted file mode 100644
index ebcfaa619..000000000
--- a/pkg/sentry/kernel/memevent/BUILD
+++ /dev/null
@@ -1,32 +0,0 @@
-load("//tools/go_stateify:defs.bzl", "go_library")
-load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
-
-package(licenses = ["notice"])
-
-go_library(
- name = "memevent",
- srcs = ["memory_events.go"],
- importpath = "gvisor.dev/gvisor/pkg/sentry/kernel/memevent",
- visibility = ["//:sandbox"],
- deps = [
- ":memory_events_go_proto",
- "//pkg/eventchannel",
- "//pkg/log",
- "//pkg/metric",
- "//pkg/sentry/kernel",
- "//pkg/sentry/usage",
- ],
-)
-
-proto_library(
- name = "memory_events_proto",
- srcs = ["memory_events.proto"],
- visibility = ["//visibility:public"],
-)
-
-go_proto_library(
- name = "memory_events_go_proto",
- importpath = "gvisor.dev/gvisor/pkg/sentry/kernel/memevent/memory_events_go_proto",
- proto = ":memory_events_proto",
- visibility = ["//visibility:public"],
-)
diff --git a/pkg/sentry/kernel/memevent/memory_events.go b/pkg/sentry/kernel/memevent/memory_events.go
deleted file mode 100644
index b0d98e7f0..000000000
--- a/pkg/sentry/kernel/memevent/memory_events.go
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2018 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Package memevent implements the memory usage events controller, which
-// periodically emits events via the eventchannel.
-package memevent
-
-import (
- "sync"
- "time"
-
- "gvisor.dev/gvisor/pkg/eventchannel"
- "gvisor.dev/gvisor/pkg/log"
- "gvisor.dev/gvisor/pkg/metric"
- "gvisor.dev/gvisor/pkg/sentry/kernel"
- pb "gvisor.dev/gvisor/pkg/sentry/kernel/memevent/memory_events_go_proto"
- "gvisor.dev/gvisor/pkg/sentry/usage"
-)
-
-var totalTicks = metric.MustCreateNewUint64Metric("/memory_events/ticks", false /*sync*/, "Total number of memory event periods that have elapsed since startup.")
-var totalEvents = metric.MustCreateNewUint64Metric("/memory_events/events", false /*sync*/, "Total number of memory events emitted.")
-
-// MemoryEvents describes the configuration for the global memory event emitter.
-type MemoryEvents struct {
- k *kernel.Kernel
-
- // The period is how often to emit an event. The memory events goroutine
- // will ensure a minimum of one event is emitted per this period, regardless
- // how of much memory usage has changed.
- period time.Duration
-
- // Writing to this channel indicates the memory goroutine should stop.
- stop chan struct{}
-
- // done is used to signal when the memory event goroutine has exited.
- done sync.WaitGroup
-}
-
-// New creates a new MemoryEvents.
-func New(k *kernel.Kernel, period time.Duration) *MemoryEvents {
- return &MemoryEvents{
- k: k,
- period: period,
- stop: make(chan struct{}),
- }
-}
-
-// Stop stops the memory usage events emitter goroutine. Stop must not be called
-// concurrently with Start and may only be called once.
-func (m *MemoryEvents) Stop() {
- close(m.stop)
- m.done.Wait()
-}
-
-// Start starts the memory usage events emitter goroutine. Start must not be
-// called concurrently with Stop and may only be called once.
-func (m *MemoryEvents) Start() {
- if m.period == 0 {
- return
- }
- m.done.Add(1)
- go m.run() // S/R-SAFE: doesn't interact with saved state.
-}
-
-func (m *MemoryEvents) run() {
- defer m.done.Done()
-
- // Emit the first event immediately on startup.
- totalTicks.Increment()
- m.emit()
-
- ticker := time.NewTicker(m.period)
- defer ticker.Stop()
-
- for {
- select {
- case <-m.stop:
- return
- case <-ticker.C:
- totalTicks.Increment()
- m.emit()
- }
- }
-}
-
-func (m *MemoryEvents) emit() {
- totalPlatform, err := m.k.MemoryFile().TotalUsage()
- if err != nil {
- log.Warningf("Failed to fetch memory usage for memory events: %v", err)
- return
- }
- snapshot, _ := usage.MemoryAccounting.Copy()
- total := totalPlatform + snapshot.Mapped
-
- totalEvents.Increment()
- eventchannel.Emit(&pb.MemoryUsageEvent{
- Mapped: snapshot.Mapped,
- Total: total,
- })
-}
diff --git a/pkg/sentry/kernel/memevent/memory_events.proto b/pkg/sentry/kernel/memevent/memory_events.proto
deleted file mode 100644
index bf8029ff5..000000000
--- a/pkg/sentry/kernel/memevent/memory_events.proto
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-syntax = "proto3";
-
-package gvisor;
-
-// MemoryUsageEvent describes the memory usage of the sandbox at a single
-// instant in time. These messages are emitted periodically on the eventchannel.
-message MemoryUsageEvent {
- // The total memory usage of the sandboxed application in bytes, calculated
- // using the 'fast' method.
- uint64 total = 1;
-
- // Memory used to back memory-mapped regions for files in the application, in
- // bytes. This corresponds to the usage.MemoryKind.Mapped memory type.
- uint64 mapped = 2;
-}