File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
docs/concepts/scheduling-eviction Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,8 @@ like `free -m`. This is important because `free -m` does not work in a
86
86
container, and if users use the [ node allocatable] ( /docs/tasks/administer-cluster/reserve-compute-resources/#node-allocatable )
87
87
feature, out of resource decisions
88
88
are made local to the end user Pod part of the cgroup hierarchy as well as the
89
- root node. This [ script] ( /examples/admin/resource/memory-available.sh )
89
+ root node. This [ script] ( /examples/admin/resource/memory-available.sh ) or
90
+ [ cgroupv2 script] ( /examples/admin/resource/memory-available-cgroupv2.sh )
90
91
reproduces the same set of steps that the kubelet performs to calculate
91
92
` memory.available ` . The kubelet excludes inactive_file (the number of bytes of
92
93
file-backed memory on the inactive LRU list) from its calculation, as it assumes that
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # This script reproduces what the kubelet does
4
+ # to calculate memory.available relative to kubepods cgroup.
5
+
6
+ # current memory usage
7
+ memory_capacity_in_kb=$( cat /proc/meminfo | grep MemTotal | awk ' {print $2}' )
8
+ memory_capacity_in_bytes=$(( memory_capacity_in_kb * 1024 ))
9
+ memory_usage_in_bytes=$( cat /sys/fs/cgroup/kubepods.slice/memory.current)
10
+ memory_total_inactive_file=$( cat /sys/fs/cgroup/kubepods.slice/memory.stat | grep inactive_file | awk ' {print $2}' )
11
+
12
+ memory_working_set=${memory_usage_in_bytes}
13
+ if [ " $memory_working_set " -lt " $memory_total_inactive_file " ];
14
+ then
15
+ memory_working_set=0
16
+ else
17
+ memory_working_set=$(( memory_usage_in_bytes - memory_total_inactive_file))
18
+ fi
19
+
20
+ memory_available_in_bytes=$(( memory_capacity_in_bytes - memory_working_set))
21
+ memory_available_in_kb=$(( memory_available_in_bytes / 1024 ))
22
+ memory_available_in_mb=$(( memory_available_in_kb / 1024 ))
23
+
24
+ echo " memory.capacity_in_bytes $memory_capacity_in_bytes "
25
+ echo " memory.usage_in_bytes $memory_usage_in_bytes "
26
+ echo " memory.total_inactive_file $memory_total_inactive_file "
27
+ echo " memory.working_set $memory_working_set "
28
+ echo " memory.available_in_bytes $memory_available_in_bytes "
29
+ echo " memory.available_in_kb $memory_available_in_kb "
30
+ echo " memory.available_in_mb $memory_available_in_mb "
You can’t perform that action at this time.
0 commit comments