34 Commits
Author SHA1 Message Date
Jamie LiuandgVisor bot e23347e5b5 Move //pkg/sentry/kernel/time to //pkg/sentry/ktime.
This avoids needing to rename it everywhere it's imported.

PiperOrigin-RevId: 693930089
2024-11-06 18:13:51 -08:00
Jamie LiuandgVisor bot e882488ed7 pgalloc: add SaveOpts.ExcludeCommittedZeroPages
This option, enabled via `runsc checkpoint --exclude-committed-zero-pages`,
instructs `pgalloc.MemoryFile.SaveTo()` to also exclude definitely-committed
zero pages from checkpointing (in addition to possibly-committed zero pages,
which are always scanned for and excluded). This is useful when the application
being checkpointed is known to have a large number of committed zero pages:
pages that (1) have been touched by application memory accesses, a syscall such
as read(), or page pinning by e.g. a driver, and (2) have not been subsequently
released by the application to the operating system by e.g. munmap() or
madvise(MADV_DONTNEED) (+ page unpinning if necessary), and (3) are filled with
zero bytes.

Minor changes:

- In `MemoryFile.updateUsageLocked()`, pass file offset to `checkCommitted` so
  that `MemoryFile.SaveTo()`'s `checkCommitted` can use `FALLOC_FL_PUNCH_HOLE`
  to decommit pages rather than `MADV_REMOVE` (which translates addresses to
  file offsets and then invokes `FALLOC_FL_PUNCH_HOLE`).

- In `MemoryFile.SaveTo()`, buffer up to a hugepage worth of pages to decommit
  rather than decommitting one page per syscall.

- Increment `MemoryFile.usageExpected` in `MemoryFile.LoadFrom()`, such that
  the first following call to `MemoryFile.UpdateUsage()` might skip the call
  to `MemoryFile.updateUsageLocked()` (if memory usage hasn't changed since
  loading).

PiperOrigin-RevId: 632370455
2024-05-09 21:50:58 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Etienne PerotandgVisor bot ab1e49567e gVisor: Add control command to get metric registration information.
This metric registration information contains the metadata of all the metrics
that the Sentry is expected to produce during its lifetime, including all
possible field combinations, the types, distribution bucket boundaries, etc.

This will be called during sandbox startup, before starting any container, in
order to save this information in the metrics server so that it can verify the
validity of instrumentation data from the Sentry once the container is
started.

This change has no tests, but coverage is provided in a later change that
provides an end-to-end container tests that the metric server works and
exports data faithfully.

This change is part of a series of changes to support Prometheus-style metrics
in `runsc`. Doing so requires making several seemingly-odd design decisions,
due to the following architectural constraints:

- Prometheus requires an HTTP server serving the `/metrics` endpoint.
- For performance reasons, the `runsc boot` process cannot run the `netpoller`
  goroutine.
  - Since we don't want to write our own HTTP server implementation, this
    means the HTTP endpoint has to be served by a separate process that
    remains running during the lifetime of the container.
- The `runsc boot` process is untrusted.
  - This means we cannot trust metrics data that comes out of the Sentry.
    Therefore, there needs to be an elaborate dance where we pre-register
    metric metadata before starting any untrusted workload. Then, the server
    relaying the metric data must verify the validity of metric values against
    this metric metadata. This avoids leaking metrics, cardinality blow-ups,
    and other such DoS vectors.
- This feature needs to be easy-to-use in a typical Docker setting.
  - This means having the ability to just say
    `--metrics-server=localhost:1337` in the `runsc` runtime entry in
    `/etc/docker/daemon.json` and have that Just Work(TM), even when multiple
    containers are running.
  - Since only one process may listen on a port at a given time, this means
    the metric server needs to be able to multiplex requests out to multiple
    running sandboxes, and remain alive for the entire duration of either of
    these sandboxes. However, it should also die when there are no sandboxes,
    so that we don't end up with leftover metric servers lying around.
  - For this reason, the metrics server runs *outside* of the usual
    per-container cgroups.
  - This also saves system resources by not running one server per sandbox.
- The metrics server must be exposed to the outside world, and cannot assume
  that its clients are trustworthy.
  - For this reason, a metrics server is bound to a runtime root directory,
    and double-checks all that the sandboxes it is asked to follow actually
    exist in this root directory.

PiperOrigin-RevId: 498076197
2022-12-27 19:04:58 -08:00
Etienne PerotandgVisor bot 01061a8f20 gVisor: Add runsc metrics-export subcommand.
This subcommand prints a sandbox's instrumentation data in Prometheus format
to stdout.

This change is part of a series of changes to support Prometheus-style metrics
in `runsc`. Doing so requires making several seemingly-odd design decisions,
due to the following architectural constraints:

- Prometheus requires an HTTP server serving the `/metrics` endpoint.
- For performance reasons, the `runsc boot` process cannot run the `netpoller`
  goroutine.
  - Since we don't want to write our own HTTP server implementation, this
    means the HTTP endpoint has to be served by a separate process that
    remains running during the lifetime of the container.
- The `runsc boot` process is untrusted.
  - This means we cannot trust metrics data that comes out of the Sentry.
    Therefore, there needs to be an elaborate dance where we pre-register
    metric metadata before starting any untrusted workload. Then, the server
    relaying the metric data must verify the validity of metric values against
    this metric metadata. This avoids leaking metrics, cardinality blow-ups,
    and other such DoS vectors.
- This feature needs to be easy-to-use in a typical Docker setting.
  - This means having the ability to just say
    `--metrics-server=localhost:1337` in the `runsc` runtime entry in
    `/etc/docker/daemon.json` and have that Just Work(TM), even when multiple
    containers are running.
  - Since only one process may listen on a port at a given time, this means
    the metric server needs to be able to multiplex requests out to multiple
    running sandboxes, and remain alive for the entire duration of either of
    these sandboxes. However, it should also die when there are no sandboxes,
    so that we don't end up with leftover metric servers lying around.
  - For this reason, the metrics server runs *outside* of the usual
    per-container cgroups.
  - This also saves system resources by not running one server per sandbox.
- The metrics server must be exposed to the outside world, and cannot assume
  that its clients are trustworthy.
  - For this reason, a metrics server is bound to a runtime root directory,
    and double-checks all that the sandboxes it is asked to follow actually
    exist in this root directory.

PiperOrigin-RevId: 498067941
2022-12-27 18:11:57 -08:00
Shambhavi SrivastavaandgVisor bot 1f8c4cb6ba Adding container_start_duration metric for container multi-container mode.
Including the time when a container start request is
received and the time it is completed in the
ContainerStartedEvent proto message.

PiperOrigin-RevId: 495390114
2022-12-14 12:46:49 -08:00
Ayush RanjanandgVisor bot 7eeeb796f8 Delete VFS1 filesystem implementations.
Updates #1624

PiperOrigin-RevId: 488986080
2022-11-16 11:05:10 -08:00
Ayush RanjanandgVisor bot 020df37be7 Start cleaning up VFS1.
PiperOrigin-RevId: 486586072
2022-11-07 00:39:54 -08:00
Rahat MahmoodandgVisor bot 10a1cadd73 Add container exit event.
PiperOrigin-RevId: 479651998
2022-10-07 13:11:13 -07:00
Rahat MahmoodandgVisor bot fc0e4d0a03 Implement sentry control commands for cgroupfs.
Add sentry control commands to read and write cgroup control
values.

PiperOrigin-RevId: 474663678
2022-09-15 14:55:45 -07:00
Nicolas LacasseandgVisor bot 295fd0a977 Port sentry control Cat method to VFS2.
And re-enable the cat container_test.

Updates #6742

PiperOrigin-RevId: 449578758
2022-05-18 14:34:18 -07:00
gVisor bot 68bb74d77a Create a usage command that outputs the read wait times from the sentry.
PiperOrigin-RevId: 413167721
2021-11-30 09:20:41 -08:00
Chong CaiandgVisor bot 75b5a4f455 Add control configs
Also plumber the controls through runsc

PiperOrigin-RevId: 391594318
2021-08-18 13:13:49 -07:00
Chong CaiandgVisor bot 6eb8596f72 Add Event controls
Add Event controls and implement "stream" commands.

PiperOrigin-RevId: 390691702
2021-08-13 14:20:12 -07:00
Chong CaiandgVisor bot ddcf884e9d Add Usage controls
Add Usage controls and implement "usage/usagefd" commands.

PiperOrigin-RevId: 390507423
2021-08-12 18:32:01 -07:00
Chong CaiandgVisor bot cbb99336ce Add Fs controls
Add Fs controls and implement "cat" command.

PiperOrigin-RevId: 388812540
2021-08-04 16:44:11 -07:00
Chong CaiandgVisor bot 8caf231cb1 Add Lifecycle controls
Also change runsc pause/resume cmd to access Lifecycle instead of
containerManager.

PiperOrigin-RevId: 388534928
2021-08-03 13:49:26 -07:00
Fabricio VoznikaandgVisor bot 2202812e07 Simplify FD handling for container start/exec
VFS1 and VFS2 host FDs have different dupping behavior,
making error prone to code for both. Change the contract
so that FDs are released as they are used, so the caller
can simple defer a block that closes all remaining files.
This also addresses handling of partial failures.

With this fix, more VFS2 tests can be enabled.

Updates #1487

PiperOrigin-RevId: 330112266
2020-09-04 11:42:02 -07:00
Fabricio VoznikaandgVisor bot 4e96b94915 Combine executable lookup code
Run vs. exec, VFS1 vs. VFS2 were executable lookup were
slightly different from each other. Combine them all
into the same logic.

PiperOrigin-RevId: 315426443
2020-06-08 23:08:23 -07:00
Nicolas LacasseandgVisor bot 93edb36cbb Refactor the ResolveExecutablePath logic.
PiperOrigin-RevId: 313871804
2020-05-29 16:35:21 -07:00
Fabricio VoznikaandgVisor bot cbc5bef2a6 Add TTY support on VFS2 to runsc
Updates #1623, #1487

PiperOrigin-RevId: 309777922
2020-05-04 10:59:20 -07:00
gVisor bot 4075de11be Plumb VFS2 inside the Sentry
- Added fsbridge package with interface that can be used to open
  and read from VFS1 and VFS2 files.
- Converted ELF loader to use fsbridge
- Added VFS2 types to FSContext
- Added vfs.MountNamespace to ThreadGroup

Updates #1623

PiperOrigin-RevId: 295183950
2020-02-14 11:12:47 -08:00
Adin ScannellandgVisor bot d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Ian GudgerandgVisor bot 27500d529f New sync package.
* Rename syncutil to sync.
* Add aliases to sync types.
* Replace existing usage of standard library sync package.

This will make it easier to swap out synchronization primitives. For example,
this will allow us to use primitives from github.com/sasha-s/go-deadlock to
check for lock ordering violations.

Updates #1472

PiperOrigin-RevId: 289033387
2020-01-09 22:02:24 -08:00
Michael PrattandgVisor bot df5d377521 Remove go_test from go_stateify and go_marshal
They are no-ops, so the standard rule works fine.

PiperOrigin-RevId: 268776264
2019-09-12 15:10:17 -07:00