Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
071be11d
Commit
071be11d
authored
Dec 12, 2017
by
Jiangtian Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use GlobalMemoryStatusEx to get total physical memory on Windows node
parent
098cba3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
16 deletions
+34
-16
perfcounter_nodestats.go
pkg/kubelet/winstats/perfcounter_nodestats.go
+34
-16
No files found.
pkg/kubelet/winstats/perfcounter_nodestats.go
View file @
071be11d
...
...
@@ -23,18 +23,32 @@ import (
"os"
"runtime"
"sync"
"syscall"
"time"
"unsafe"
"github.com/golang/glog"
cadvisorapi
"github.com/google/cadvisor/info/v1"
"golang.org/x/sys/windows"
"k8s.io/apimachinery/pkg/util/wait"
)
// MemoryStatusEx is the same as Windows structure MEMORYSTATUSEX
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx
type
MemoryStatusEx
struct
{
Length
uint32
MemoryLoad
uint32
TotalPhys
uint64
AvailPhys
uint64
TotalPageFile
uint64
AvailPageFile
uint64
TotalVirtual
uint64
AvailVirtual
uint64
AvailExtendedVirtual
uint64
}
var
(
modkernel32
=
syscall
.
NewLazy
DLL
(
"kernel32.dll"
)
procG
etPhysicallyInstalledSystemMemory
=
modkernel32
.
NewProc
(
"GetPhysicallyInstalledSystemMemory
"
)
modkernel32
=
windows
.
NewLazySystem
DLL
(
"kernel32.dll"
)
procG
lobalMemoryStatusEx
=
modkernel32
.
NewProc
(
"GlobalMemoryStatusEx
"
)
)
// NewPerfCounterClient creates a client using perf counters
...
...
@@ -163,20 +177,24 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuValue uint64) uint64 {
}
func
getPhysicallyInstalledSystemMemoryBytes
()
(
uint64
,
error
)
{
var
physicalMemoryKiloBytes
uint64
if
ok
:=
getPhysicallyInstalledSystemMemory
(
&
physicalMemoryKiloBytes
);
!
ok
{
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
// on Windows node for the following reasons:
// 1. GetPhysicallyInstalledSystemMemory retrieves the amount of physically
// installed RAM from the computer's SMBIOS firmware tables.
// https://msdn.microsoft.com/en-us/library/windows/desktop/cc300158(v=vs.85).aspx
// On some VM, it is unable to read data from SMBIOS and fails with ERROR_INVALID_DATA.
// 2. On Linux node, total physical memory is read from MemTotal in /proc/meminfo.
// GlobalMemoryStatusEx returns the amount of physical memory that is available
// for the operating system to use. The amount returned by GlobalMemoryStatusEx
// is closer in parity with Linux
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
var
statex
MemoryStatusEx
statex
.
Length
=
uint32
(
unsafe
.
Sizeof
(
statex
))
ret
,
_
,
_
:=
procGlobalMemoryStatusEx
.
Call
(
uintptr
(
unsafe
.
Pointer
(
&
statex
)))
if
ret
==
0
{
return
0
,
errors
.
New
(
"unable to read physical memory"
)
}
return
physicalMemoryKiloBytes
*
1024
,
nil
// convert kilobytes to bytes
}
func
getPhysicallyInstalledSystemMemory
(
totalMemoryInKilobytes
*
uint64
)
bool
{
ret
,
_
,
_
:=
syscall
.
Syscall
(
procGetPhysicallyInstalledSystemMemory
.
Addr
(),
1
,
uintptr
(
unsafe
.
Pointer
(
totalMemoryInKilobytes
)),
0
,
0
)
return
ret
!=
0
return
statex
.
TotalPhys
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment