Skip to content

Commit

Permalink
merge branch 'pr-2791'
Browse files Browse the repository at this point in the history
Kir Kolyshkin (1):
  cgroupv1 freezer: thaw to increase freeze chances

LGTMs: @cyphar @dqminh
Closes #2791
  • Loading branch information
cyphar committed Feb 7, 2021
2 parents b4cb54c + d1007b0 commit 94ae7af
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions libcontainer/cgroups/fs/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

Expand All @@ -38,13 +39,19 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
// (either via fork/clone or by writing new PIDs to
// cgroup.procs).
//
// The number of retries below is chosen to have a decent
// chance to succeed even in the worst case scenario (runc
// pause/unpause with parallel runc exec).
// The numbers below are chosen to have a decent chance to
// succeed even in the worst case scenario (runc pause/unpause
// with parallel runc exec).
//
// Adding any amount of sleep in between retries did not
// increase the chances of successful freeze.
for i := 0; i < 1000; i++ {
if i%50 == 49 {
// Briefly thawing the cgroup also helps.
_ = fscommon.WriteFile(path, "freezer.state", string(configs.Thawed))
time.Sleep(10 * time.Millisecond)
}

if err := fscommon.WriteFile(path, "freezer.state", string(configs.Frozen)); err != nil {
return err
}
Expand All @@ -58,6 +65,9 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
case "FREEZING":
continue
case string(configs.Frozen):
if i > 1 {
logrus.Debugf("frozen after %d retries", i)
}
return nil
default:
// should never happen
Expand Down

0 comments on commit 94ae7af

Please sign in to comment.