Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimize memory usage of tcell library on init #7579

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ WORKDIR /src/internal/app/machined
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
ARG GOAMD64
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=amd64 GOAMD64=${GOAMD64} go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /machined
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=amd64 GOAMD64=${GOAMD64} go build ${GO_BUILDFLAGS} -tags tcell_minimal -ldflags "${GO_LDFLAGS}" -o /machined
RUN chmod +x /machined

FROM base AS machined-build-arm64
WORKDIR /src/internal/app/machined
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=arm64 go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /machined
RUN --mount=type=cache,target=/.cache GOOS=linux GOARCH=arm64 go build ${GO_BUILDFLAGS} -tags tcell_minimal -ldflags "${GO_LDFLAGS}" -o /machined
RUN chmod +x /machined

FROM machined-build-${TARGETARCH} AS machined-build
Expand Down
4 changes: 3 additions & 1 deletion internal/app/machined/pkg/system/services/apid.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ func (o *APID) Runner(r runtime.Runtime) (runner.Runner, error) {
{Type: "bind", Destination: filepath.Dir(constants.APISocketPath), Source: filepath.Dir(constants.APISocketPath), Options: []string{"rbind", "rw"}},
}

env := []string{}
env := []string{
constants.TcellMinimizeEnvironment,
}

for _, value := range environment.Get(r.Config()) {
key, _, _ := strings.Cut(value, "=")
Expand Down
5 changes: 4 additions & 1 deletion internal/app/machined/pkg/system/services/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func (d *Dashboard) Runner(r runtime.Runtime) (runner.Runner, error) {
ProcessArgs: []string{"/sbin/dashboard"},
},
runner.WithLoggingManager(r.Logging()),
runner.WithEnv([]string{"TERM=linux"}),
runner.WithEnv([]string{
"TERM=linux",
constants.TcellMinimizeEnvironment,
}),
runner.WithStdinFile(tty),
runner.WithStdoutFile(tty),
runner.WithCtty(1),
Expand Down
1 change: 1 addition & 0 deletions internal/app/machined/pkg/system/services/trustd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (t *Trustd) Runner(r runtime.Runtime) (runner.Runner, error) {
}

env := environment.Get(r.Config())
env = append(env, constants.TcellMinimizeEnvironment)

if debug.RaceEnabled {
env = append(env, "GORACE=halt_on_error=1")
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/gdamore/tcell/v2"
_ "github.com/gdamore/tcell/v2/terminfo/l/linux" // linux terminal is used when running on the machine, but not included with tcell_minimal
"github.com/gizak/termui/v3"
"github.com/rivo/tview"
"github.com/siderolabs/gen/maps"
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/mount/switchroot/switchroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func Switch(prefix string, mountpoints *mount.Points) (err error) {
// convention.
log.Println("executing /sbin/init")

envv := []string{}
envv := []string{
constants.TcellMinimizeEnvironment,
}

if debug.RaceEnabled {
envv = append(envv, "GORACE=halt_on_error=1")
Expand Down
3 changes: 3 additions & 0 deletions pkg/machinery/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ const (

// GRPCMaxMessageSize is the maximum message size for Talos API.
GRPCMaxMessageSize = 32 * 1024 * 1024

// TcellMinimizeEnvironment is the environment variable to minimize tcell library memory usage (skips rune width calculation).
TcellMinimizeEnvironment = "TCELL_MINIMIZE=1"
)

// See https://linux.die.net/man/3/klogctl
Expand Down