Skip to content

Commit 2d49080

Browse files
committed
pkg/sysinfo: move MemInfo and ReadMemInfo to a separate package
Commit 6a516ac moved the MemInfo type and ReadMemInfo() function into the pkg/sysinfo package. In an attempt to assist consumers of these to migrate to the new location, an alias was added. Unfortunately, the side effect of this alias is that pkg/system now depends on pkg/sysinfo, which means that consumers of this (such as docker/cli) now get all (indirect) dependencies of that package as dependency, which includes many dependencies that should only be needed for the daemon / runtime; - github.com/cilium/ebpf - github.com/containerd/cgroups - github.com/coreos/go-systemd/v22 - github.com/godbus/dbus/v5 - github.com/moby/sys/mountinfo - github.com/opencontainers/runtime-spec This patch moves the MemInfo related code to its own package. As the previous move was not yet part of a release, we're not adding new aliases in pkg/sysinfo. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6a8964b commit 2d49080

8 files changed

Lines changed: 22 additions & 19 deletions

File tree

daemon/info.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/docker/docker/daemon/logger"
1515
"github.com/docker/docker/dockerversion"
1616
"github.com/docker/docker/pkg/fileutils"
17+
"github.com/docker/docker/pkg/meminfo"
1718
"github.com/docker/docker/pkg/parsers/kernel"
1819
"github.com/docker/docker/pkg/parsers/operatingsystem"
1920
"github.com/docker/docker/pkg/platform"
@@ -249,11 +250,11 @@ func kernelVersion() string {
249250
return kernelVersion
250251
}
251252

252-
func memInfo() *sysinfo.Memory {
253-
memInfo, err := sysinfo.ReadMemInfo()
253+
func memInfo() *meminfo.Memory {
254+
memInfo, err := meminfo.Read()
254255
if err != nil {
255256
logrus.Errorf("Could not read system memory info: %v", err)
256-
memInfo = &sysinfo.Memory{}
257+
memInfo = &meminfo.Memory{}
257258
}
258259
return memInfo
259260
}

daemon/stats_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/docker/docker/daemon/stats"
8-
"github.com/docker/docker/pkg/sysinfo"
8+
"github.com/docker/docker/pkg/meminfo"
99
)
1010

1111
// newStatsCollector returns a new statsCollector that collections
@@ -15,7 +15,7 @@ import (
1515
func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
1616
// FIXME(vdemeester) move this elsewhere
1717
if runtime.GOOS == "linux" {
18-
meminfo, err := sysinfo.ReadMemInfo()
18+
meminfo, err := meminfo.Read()
1919
if err == nil && meminfo.MemTotal > 0 {
2020
daemon.machineMemory = uint64(meminfo.MemTotal)
2121
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package sysinfo
1+
// Package meminfo provides utilites to retrieve memory statistics of
2+
// the host system.
3+
package meminfo
24

3-
// ReadMemInfo retrieves memory statistics of the host system and returns a
5+
// Read retrieves memory statistics of the host system and returns a
46
// Memory type. It is only supported on Linux and Windows, and returns an
57
// error on other platforms.
6-
func ReadMemInfo() (*Memory, error) {
8+
func Read() (*Memory, error) {
79
return readMemInfo()
810
}
911

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package sysinfo
1+
package meminfo
22

33
import (
44
"bufio"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build linux || freebsd
22
// +build linux freebsd
33

4-
package sysinfo
4+
package meminfo
55

66
import (
77
"strings"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build !linux && !windows
22
// +build !linux,!windows
33

4-
package sysinfo
4+
package meminfo
55

66
import "errors"
77

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package sysinfo
1+
package meminfo
22

33
import (
44
"unsafe"
@@ -26,7 +26,7 @@ type memorystatusex struct {
2626
ullAvailExtendedVirtual uint64
2727
}
2828

29-
// ReadMemInfo retrieves memory statistics of the host system and returns a
29+
// readMemInfo retrieves memory statistics of the host system and returns a
3030
// Memory type.
3131
func readMemInfo() (*Memory, error) {
3232
msi := &memorystatusex{

pkg/system/meminfo_deprecated.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package system
22

3-
import "github.com/docker/docker/pkg/sysinfo"
3+
import "github.com/docker/docker/pkg/meminfo"
44

55
// MemInfo contains memory statistics of the host system.
66
//
7-
// Deprecated: use [sysinfo.Memory].
8-
type MemInfo = sysinfo.Memory
7+
// Deprecated: use [meminfo.Memory].
8+
type MemInfo = meminfo.Memory
99

1010
// ReadMemInfo retrieves memory statistics of the host system and returns a
1111
// MemInfo type.
1212
//
13-
// Deprecated: use [sysinfo.ReadMemInfo].
14-
func ReadMemInfo() (*sysinfo.Memory, error) {
15-
return sysinfo.ReadMemInfo()
13+
// Deprecated: use [meminfo.Read].
14+
func ReadMemInfo() (*meminfo.Memory, error) {
15+
return meminfo.Read()
1616
}

0 commit comments

Comments
 (0)