Skip to content

Commit 47dc185

Browse files
committed
Add runc_nocriu build tag
This allows to make a 17% smaller runc binary by not compiling in checkpoint/restore support. It turns out that google.golang.org/protobuf package, used by go-criu, is quite big, and go linker can't drop unused stuff if reflection is used anywhere in the code. Currently there's no alternative to using protobuf in go-criu, and since not all users use c/r, let's provide them an option for a smaller binary. For the reference, here's top10 biggest vendored packages, as reported by gsa[1]: $ gsa runc | grep vendor | head │ 8.59% │ google.golang.org/protobuf │ 1.3 MB │ vendor │ │ 5.76% │ github.com/opencontainers/runc │ 865 kB │ vendor │ │ 4.05% │ github.com/cilium/ebpf │ 608 kB │ vendor │ │ 2.86% │ github.com/godbus/dbus/v5 │ 429 kB │ vendor │ │ 1.25% │ github.com/urfave/cli │ 188 kB │ vendor │ │ 0.90% │ github.com/vishvananda/netlink │ 135 kB │ vendor │ │ 0.59% │ github.com/sirupsen/logrus │ 89 kB │ vendor │ │ 0.56% │ github.com/checkpoint-restore/go-criu/v6 │ 84 kB │ vendor │ │ 0.51% │ golang.org/x/sys │ 76 kB │ vendor │ │ 0.47% │ github.com/seccomp/libseccomp-golang │ 71 kB │ vendor │ And here is a total binary size saving when `runc_nocriu` is used. For non-stripped binaries: $ gsa runc-cr runc-nocr | tail -3 │ -17.04% │ runc-cr │ 15 MB │ 12 MB │ -2.6 MB │ │ │ runc-nocr │ │ │ │ └─────────┴──────────────────────────────────────────┴──────────┴──────────┴─────────┘ And for stripped binaries: │ -17.01% │ runc-cr-stripped │ 11 MB │ 8.8 MB │ -1.8 MB │ │ │ runc-nocr-stripped │ │ │ │ └─────────┴──────────────────────────────────────────┴──────────┴──────────┴─────────┘ [1]: https://github.com/Zxilly/go-size-analyzer Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent c487840 commit 47dc185

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

.github/workflows/validate.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ jobs:
7676
uses: actions/setup-go@v5
7777
with:
7878
go-version: "${{ env.GO_VERSION }}"
79+
- name: install deps
80+
run: |
81+
sudo apt update
82+
sudo apt -y install libseccomp-dev
7983
- name: compile with no build tags
8084
run: make BUILDTAGS=""
85+
- name: compile with runc_nocriu build tag
86+
run: make EXTRA_BUILDTAGS="runc_nocriu"
8187

8288
codespell:
8389
runs-on: ubuntu-24.04

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,17 @@ e.g. to disable seccomp:
103103
make BUILDTAGS=""
104104
```
105105

106+
To add some more build tags to the default set, use the `EXTRA_BUILDTAGS`
107+
make variable, e.g. to disable checkpoint/restore:
108+
109+
```bash
110+
make EXTRA_BUILDTAGS="runc_nocriu"
111+
```
112+
106113
| Build Tag | Feature | Enabled by Default | Dependencies |
107114
|---------------|---------------------------------------|--------------------|---------------------|
108115
| `seccomp` | Syscall filtering using `libseccomp`. | yes | `libseccomp` |
116+
| `runc_nocriu` | **Disables** runc checkpoint/restore. | no | `criu` |
109117

110118
The following build tags were used earlier, but are now obsoleted:
111119
- **runc_nodmz** (since runc v1.2.1 runc dmz binary is dropped)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build runc_nocriu
2+
3+
package libcontainer
4+
5+
import "errors"
6+
7+
var ErrNoCR = errors.New("this runc binary has not been compiled with checkpoint/restore support enabled (runc_nocriu)")
8+
9+
func (c *Container) Restore(process *Process, criuOpts *CriuOpts) error {
10+
return ErrNoCR
11+
}
12+
13+
func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
14+
return ErrNoCR
15+
}

libcontainer/criu_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !runc_nocriu
2+
13
package libcontainer
24

35
import (

0 commit comments

Comments
 (0)