Skip to content

Commit 6a516ac

Browse files
committed
pkg/system: move memory-info types to pkg/systeminfo
These types and functions are more closely related to the functionality provided by pkg/systeminfo, and used in conjunction with the other functions in that package, so moving them there. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6919b98 commit 6a516ac

9 files changed

Lines changed: 47 additions & 30 deletions

daemon/info.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/docker/docker/pkg/parsers/operatingsystem"
1919
"github.com/docker/docker/pkg/platform"
2020
"github.com/docker/docker/pkg/sysinfo"
21-
"github.com/docker/docker/pkg/system"
2221
"github.com/docker/docker/registry"
2322
metrics "github.com/docker/go-metrics"
2423
"github.com/opencontainers/selinux/go-selinux"
@@ -252,11 +251,11 @@ func kernelVersion() string {
252251
return kernelVersion
253252
}
254253

255-
func memInfo() *system.MemInfo {
256-
memInfo, err := system.ReadMemInfo()
254+
func memInfo() *sysinfo.Memory {
255+
memInfo, err := sysinfo.ReadMemInfo()
257256
if err != nil {
258257
logrus.Errorf("Could not read system memory info: %v", err)
259-
memInfo = &system.MemInfo{}
258+
memInfo = &sysinfo.Memory{}
260259
}
261260
return memInfo
262261
}

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/system"
8+
"github.com/docker/docker/pkg/sysinfo"
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 := system.ReadMemInfo()
18+
meminfo, err := sysinfo.ReadMemInfo()
1919
if err == nil && meminfo.MemTotal > 0 {
2020
daemon.machineMemory = uint64(meminfo.MemTotal)
2121
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package system // import "github.com/docker/docker/pkg/system"
1+
package sysinfo
22

3-
// MemInfo contains memory statistics of the host system.
4-
type MemInfo struct {
3+
// Memory contains memory statistics of the host system.
4+
type Memory struct {
55
// Total usable RAM (i.e. physical RAM minus a few reserved bits and the
66
// kernel binary code).
77
MemTotal int64
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package system // import "github.com/docker/docker/pkg/system"
1+
package sysinfo
22

33
import (
44
"bufio"
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
// ReadMemInfo retrieves memory statistics of the host system and returns a
12-
// MemInfo type.
13-
func ReadMemInfo() (*MemInfo, error) {
12+
// Memory type.
13+
func ReadMemInfo() (*Memory, error) {
1414
file, err := os.Open("/proc/meminfo")
1515
if err != nil {
1616
return nil, err
@@ -20,10 +20,10 @@ func ReadMemInfo() (*MemInfo, error) {
2020
}
2121

2222
// parseMemInfo parses the /proc/meminfo file into
23-
// a MemInfo object given an io.Reader to the file.
23+
// a Memory object given an io.Reader to the file.
2424
// Throws error if there are problems reading from the file
25-
func parseMemInfo(reader io.Reader) (*MemInfo, error) {
26-
meminfo := &MemInfo{}
25+
func parseMemInfo(reader io.Reader) (*Memory, error) {
26+
meminfo := &Memory{}
2727
scanner := bufio.NewScanner(reader)
2828
memAvailable := int64(-1)
2929
for scanner.Scan() {
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 system // import "github.com/docker/docker/pkg/system"
4+
package sysinfo
55

66
import (
77
"strings"

pkg/sysinfo/meminfo_unsupported.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !linux && !windows
2+
// +build !linux,!windows
3+
4+
package sysinfo
5+
6+
import "errors"
7+
8+
// ReadMemInfo is not supported on platforms other than linux and windows.
9+
func ReadMemInfo() (*Memory, error) {
10+
return nil, errors.New("platform and architecture is not supported")
11+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package system // import "github.com/docker/docker/pkg/system"
1+
package sysinfo
22

33
import (
44
"unsafe"
@@ -27,16 +27,16 @@ type memorystatusex struct {
2727
}
2828

2929
// ReadMemInfo retrieves memory statistics of the host system and returns a
30-
// MemInfo type.
31-
func ReadMemInfo() (*MemInfo, error) {
30+
// Memory type.
31+
func ReadMemInfo() (*Memory, error) {
3232
msi := &memorystatusex{
3333
dwLength: 64,
3434
}
3535
r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msi)))
3636
if r1 == 0 {
37-
return &MemInfo{}, nil
37+
return &Memory{}, nil
3838
}
39-
return &MemInfo{
39+
return &Memory{
4040
MemTotal: int64(msi.ullTotalPhys),
4141
MemFree: int64(msi.ullAvailPhys),
4242
SwapTotal: int64(msi.ullTotalPageFile),

pkg/system/meminfo_deprecated.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package system
2+
3+
import "github.com/docker/docker/pkg/sysinfo"
4+
5+
// MemInfo contains memory statistics of the host system.
6+
//
7+
// Deprecated: use [sysinfo.Memory].
8+
type MemInfo = sysinfo.Memory
9+
10+
// ReadMemInfo retrieves memory statistics of the host system and returns a
11+
// MemInfo type.
12+
//
13+
// Deprecated: use [sysinfo.ReadMemInfo].
14+
func ReadMemInfo() (*sysinfo.Memory, error) {
15+
return sysinfo.ReadMemInfo()
16+
}

pkg/system/meminfo_unsupported.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)