gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit ab7f518f5732fe5ac71d806858340b0d86ccc004
parent 5904e3b4ee475076908d569afe816fd8a7e9d0d5
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon,  1 May 2023 11:01:36 +0200

[chore]: Bump github.com/KimMachineGun/automemlimit from 0.2.5 to 0.2.6 (#1723)

Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.2.5 to 0.2.6.
- [Release notes](https://github.com/KimMachineGun/automemlimit/releases)
- [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.2.5...v0.2.6)

---
updated-dependencies:
- dependency-name: github.com/KimMachineGun/automemlimit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat:
Mgo.mod | 2+-
Mgo.sum | 4++--
Mvendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go | 42++++++++++++++++++++++++++++++++++--------
Mvendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups_unsupported.go | 4++++
Mvendor/modules.txt | 2+-
5 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/go.mod b/go.mod @@ -15,7 +15,7 @@ require ( codeberg.org/gruf/go-runners v1.6.1 codeberg.org/gruf/go-sched v1.2.3 codeberg.org/gruf/go-store/v2 v2.2.2 - github.com/KimMachineGun/automemlimit v0.2.5 + github.com/KimMachineGun/automemlimit v0.2.6 github.com/abema/go-mp4 v0.10.1 github.com/buckket/go-blurhash v1.1.0 github.com/coreos/go-oidc/v3 v3.5.0 diff --git a/go.sum b/go.sum @@ -88,8 +88,8 @@ codeberg.org/gruf/go-store/v2 v2.2.2/go.mod h1:QRM3LUAfYyoGMWLTqA1WzohxQgYqPFiVv dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/KimMachineGun/automemlimit v0.2.5 h1:+wWu5hu/dVqWWauY2rZmlGN+z7SnP02gMVQpcP7xvrk= -github.com/KimMachineGun/automemlimit v0.2.5/go.mod h1:pJhTW/nWJMj6SnWSU2TEKSlCaM+1N5Mej+IfS/5/Ol0= +github.com/KimMachineGun/automemlimit v0.2.6 h1:tQFriVTcIteUkV5EgU9iz03eDY36T8JU5RAjP2r6Kt0= +github.com/KimMachineGun/automemlimit v0.2.6/go.mod h1:pJhTW/nWJMj6SnWSU2TEKSlCaM+1N5Mej+IfS/5/Ol0= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/abema/go-mp4 v0.10.1 h1:wOhZgNxjduc8r4FJdwPa5x/gdBSSX+8MTnfNj/xkJaE= diff --git a/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go b/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups.go @@ -4,6 +4,8 @@ package memlimit import ( + "path/filepath" + "github.com/containerd/cgroups/v3" "github.com/containerd/cgroups/v3/cgroup1" "github.com/containerd/cgroups/v3/cgroup2" @@ -18,7 +20,9 @@ func FromCgroup() (uint64, error) { switch cgroups.Mode() { case cgroups.Legacy: return FromCgroupV1() - case cgroups.Hybrid, cgroups.Unified: + case cgroups.Hybrid: + return fromCgroupHybrid() + case cgroups.Unified: return FromCgroupV2() } return 0, ErrNoCgroup @@ -36,21 +40,41 @@ func FromCgroupV1() (uint64, error) { metrics, err := cg.Stat(cgroup1.IgnoreNotExist) if err != nil { return 0, err - } else if metrics.Memory == nil { - return 0, ErrNoLimit } - return metrics.Memory.HierarchicalMemoryLimit, nil + if limit := metrics.GetMemory().GetHierarchicalMemoryLimit(); limit != 0 { + return limit, nil + } + + return 0, ErrNoLimit +} + +// fromCgroupHybrid returns the memory limit from the cgroup v1 or v2. +// It checks the cgroup v2 first, and if it fails, it falls back to cgroup v1. +// TODO: make this function public in the next minor version. +func fromCgroupHybrid() (uint64, error) { + limit, err := fromCgroupV2(filepath.Join(cgroupMountPoint, "unified")) + if err == nil { + return limit, nil + } else if err != ErrNoLimit { + return 0, err + } + + return FromCgroupV1() } // FromCgroupV2 returns the memory limit from the cgroup v2. func FromCgroupV2() (uint64, error) { + return fromCgroupV2(cgroupMountPoint) +} + +func fromCgroupV2(mountPoint string) (uint64, error) { path, err := cgroup2.NestedGroupPath("") if err != nil { return 0, err } - m, err := cgroup2.Load(path, cgroup2.WithMountpoint(cgroupMountPoint)) + m, err := cgroup2.Load(path, cgroup2.WithMountpoint(mountPoint)) if err != nil { return 0, err } @@ -58,9 +82,11 @@ func FromCgroupV2() (uint64, error) { stats, err := m.Stat() if err != nil { return 0, err - } else if stats.Memory == nil { - return 0, ErrNoLimit } - return stats.Memory.UsageLimit, nil + if limit := stats.GetMemory().GetUsageLimit(); limit != 0 { + return limit, nil + } + + return 0, ErrNoLimit } diff --git a/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups_unsupported.go b/vendor/github.com/KimMachineGun/automemlimit/memlimit/cgroups_unsupported.go @@ -11,6 +11,10 @@ func FromCgroupV1() (uint64, error) { return 0, ErrCgroupsNotSupported } +func fromCgroupHybrid() (uint64, error) { + return 0, ErrCgroupsNotSupported +} + func FromCgroupV2() (uint64, error) { return 0, ErrCgroupsNotSupported } diff --git a/vendor/modules.txt b/vendor/modules.txt @@ -69,7 +69,7 @@ codeberg.org/gruf/go-sched codeberg.org/gruf/go-store/v2/kv codeberg.org/gruf/go-store/v2/storage codeberg.org/gruf/go-store/v2/util -# github.com/KimMachineGun/automemlimit v0.2.5 +# github.com/KimMachineGun/automemlimit v0.2.6 ## explicit; go 1.19 github.com/KimMachineGun/automemlimit github.com/KimMachineGun/automemlimit/memlimit