summaryrefslogtreecommitdiffhomepage
path: root/util/sysresources
diff options
context:
space:
mode:
authorNick Khyl <nickk@tailscale.com>2024-12-05 13:16:48 -0600
committerNick Khyl <nickk@tailscale.com>2024-12-05 13:16:48 -0600
commit0267fe83b200f1702a2fa0a395442c02a053fadb (patch)
tree63654c55225eeb834de59a5a0bc8d19033c6145b /util/sysresources
parent87546a5edf6b6503a87eeb2d666baba57398a066 (diff)
downloadtailscale-1.78.0.tar.xz
tailscale-1.78.0.zip
VERSION.txt: this is v1.78.0v1.78.0
Signed-off-by: Nick Khyl <nickk@tailscale.com>
Diffstat (limited to 'util/sysresources')
-rw-r--r--util/sysresources/memory.go20
-rw-r--r--util/sysresources/memory_bsd.go32
-rw-r--r--util/sysresources/memory_darwin.go32
-rw-r--r--util/sysresources/memory_linux.go38
-rw-r--r--util/sysresources/memory_unsupported.go16
-rw-r--r--util/sysresources/sysresources.go12
-rw-r--r--util/sysresources/sysresources_test.go50
7 files changed, 100 insertions, 100 deletions
diff --git a/util/sysresources/memory.go b/util/sysresources/memory.go
index 7363155cd..8bf784e13 100644
--- a/util/sysresources/memory.go
+++ b/util/sysresources/memory.go
@@ -1,10 +1,10 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-package sysresources
-
-// TotalMemory returns the total accessible system memory, in bytes. If the
-// value cannot be determined, then 0 will be returned.
-func TotalMemory() uint64 {
- return totalMemoryImpl()
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package sysresources
+
+// TotalMemory returns the total accessible system memory, in bytes. If the
+// value cannot be determined, then 0 will be returned.
+func TotalMemory() uint64 {
+ return totalMemoryImpl()
+}
diff --git a/util/sysresources/memory_bsd.go b/util/sysresources/memory_bsd.go
index 26850dce6..39d3a18a9 100644
--- a/util/sysresources/memory_bsd.go
+++ b/util/sysresources/memory_bsd.go
@@ -1,16 +1,16 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-//go:build freebsd || openbsd || dragonfly || netbsd
-
-package sysresources
-
-import "golang.org/x/sys/unix"
-
-func totalMemoryImpl() uint64 {
- val, err := unix.SysctlUint64("hw.physmem")
- if err != nil {
- return 0
- }
- return val
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build freebsd || openbsd || dragonfly || netbsd
+
+package sysresources
+
+import "golang.org/x/sys/unix"
+
+func totalMemoryImpl() uint64 {
+ val, err := unix.SysctlUint64("hw.physmem")
+ if err != nil {
+ return 0
+ }
+ return val
+}
diff --git a/util/sysresources/memory_darwin.go b/util/sysresources/memory_darwin.go
index e07bac0cd..2f74b6cec 100644
--- a/util/sysresources/memory_darwin.go
+++ b/util/sysresources/memory_darwin.go
@@ -1,16 +1,16 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-//go:build darwin
-
-package sysresources
-
-import "golang.org/x/sys/unix"
-
-func totalMemoryImpl() uint64 {
- val, err := unix.SysctlUint64("hw.memsize")
- if err != nil {
- return 0
- }
- return val
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build darwin
+
+package sysresources
+
+import "golang.org/x/sys/unix"
+
+func totalMemoryImpl() uint64 {
+ val, err := unix.SysctlUint64("hw.memsize")
+ if err != nil {
+ return 0
+ }
+ return val
+}
diff --git a/util/sysresources/memory_linux.go b/util/sysresources/memory_linux.go
index 0239b0e80..f3c51469f 100644
--- a/util/sysresources/memory_linux.go
+++ b/util/sysresources/memory_linux.go
@@ -1,19 +1,19 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-//go:build linux
-
-package sysresources
-
-import "golang.org/x/sys/unix"
-
-func totalMemoryImpl() uint64 {
- var info unix.Sysinfo_t
-
- if err := unix.Sysinfo(&info); err != nil {
- return 0
- }
-
- // uint64 casts are required since these might be uint32s
- return uint64(info.Totalram) * uint64(info.Unit)
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build linux
+
+package sysresources
+
+import "golang.org/x/sys/unix"
+
+func totalMemoryImpl() uint64 {
+ var info unix.Sysinfo_t
+
+ if err := unix.Sysinfo(&info); err != nil {
+ return 0
+ }
+
+ // uint64 casts are required since these might be uint32s
+ return uint64(info.Totalram) * uint64(info.Unit)
+}
diff --git a/util/sysresources/memory_unsupported.go b/util/sysresources/memory_unsupported.go
index 0fde256e0..f80ef4e6e 100644
--- a/util/sysresources/memory_unsupported.go
+++ b/util/sysresources/memory_unsupported.go
@@ -1,8 +1,8 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-//go:build !(linux || darwin || freebsd || openbsd || dragonfly || netbsd)
-
-package sysresources
-
-func totalMemoryImpl() uint64 { return 0 }
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+//go:build !(linux || darwin || freebsd || openbsd || dragonfly || netbsd)
+
+package sysresources
+
+func totalMemoryImpl() uint64 { return 0 }
diff --git a/util/sysresources/sysresources.go b/util/sysresources/sysresources.go
index 32d972ab1..1cce164a7 100644
--- a/util/sysresources/sysresources.go
+++ b/util/sysresources/sysresources.go
@@ -1,6 +1,6 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-// Package sysresources provides OS-independent methods of determining the
-// resources available to the current system.
-package sysresources
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+// Package sysresources provides OS-independent methods of determining the
+// resources available to the current system.
+package sysresources
diff --git a/util/sysresources/sysresources_test.go b/util/sysresources/sysresources_test.go
index 331ad913b..af9662042 100644
--- a/util/sysresources/sysresources_test.go
+++ b/util/sysresources/sysresources_test.go
@@ -1,25 +1,25 @@
-// Copyright (c) Tailscale Inc & AUTHORS
-// SPDX-License-Identifier: BSD-3-Clause
-
-package sysresources
-
-import (
- "runtime"
- "testing"
-)
-
-func TestTotalMemory(t *testing.T) {
- switch runtime.GOOS {
- case "linux":
- case "freebsd", "openbsd", "dragonfly", "netbsd":
- case "darwin":
- default:
- t.Skipf("not supported on runtime.GOOS=%q yet", runtime.GOOS)
- }
-
- mem := TotalMemory()
- if mem == 0 {
- t.Fatal("wanted TotalMemory > 0")
- }
- t.Logf("total memory: %v bytes", mem)
-}
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package sysresources
+
+import (
+ "runtime"
+ "testing"
+)
+
+func TestTotalMemory(t *testing.T) {
+ switch runtime.GOOS {
+ case "linux":
+ case "freebsd", "openbsd", "dragonfly", "netbsd":
+ case "darwin":
+ default:
+ t.Skipf("not supported on runtime.GOOS=%q yet", runtime.GOOS)
+ }
+
+ mem := TotalMemory()
+ if mem == 0 {
+ t.Fatal("wanted TotalMemory > 0")
+ }
+ t.Logf("total memory: %v bytes", mem)
+}