-
Notifications
You must be signed in to change notification settings - Fork 2
/
memory_ext
executable file
·269 lines (254 loc) · 7.22 KB
/
memory_ext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/perl -w
#
# Plugin to monitor extended memory usage.
#
# Origional Author: Jimmy Olsen, Mike Fedyk
# Author: KOSAKI Motohiro
#
# ChangeLog
# v1
# - Convert app to anon
# - Convert slab_cache to slab(unreclaim) and slab(reclaimable)
# - Convert cache to cache and shmem
# - Remove active and inactive
# - Remove committed
# - Convert swap represented as line
# - Introduce mlocked
# - Introduce dirty
# - Introduce writeback
# - Change display order
# v2
# - Remove Mlocked
# - Instead, Introduce Unevictable
# - Rename swap to swap_used
# - Anon use Active(anon) + Inactive(anon) instead AnonPages
# - Remove Buffers
# - Remove Dirty field
# - Instead, Introduce file_cache(clean) and file_cache(dirty)
# - Cleanups
#
# Parameters:
#
# config (required)
# autoconf (optional - only used by munin-config)
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#%# family=auto
#%# capabilities=autoconf
if ($ARGV[0] and $ARGV[0] eq "autoconf")
{
if (-r "/proc/meminfo")
{
print "yes\n";
exit 0;
}
else
{
print "/proc/meminfo not found\n";
exit 1;
}
}
my %mems;
&fetch_meminfo;
if ($ARGV[0] and $ARGV[0] eq "config")
{
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit ", $mems{'MemTotal'}, "\n";
print "graph_title Extended memory usage\n";
print "graph_category system\n";
print "graph_info This graph shows what the machine uses its memory for.\n";
print "graph_order ",
"anon ";
if (exists $mems{'PageTables'})
{
print "page_tables ";
}
if (exists $mems{'KernelStack'})
{
print "kernel_stack ";
}
if (exists $mems{'SwapCached'})
{
print "swap_cache ";
}
if (exists $mems{'Shmem'})
{
print "shmem ";
}
if (exists $mems{'VmallocUsed'})
{
print "vmalloc_used ";
}
if (exists $mems{'Unevictable'})
{
print "unevictable "
}
if (exists $mems{'SReclaimable'})
{
print "slab_unreclaim ";
print "slab_reclaimable ";
}
elsif (exists $mems{'Slab'})
{
print "slab ";
}
print "file_cache_dirty ",
"file_cache_clean ",
"free ",
"swap_used ";
if (exists $mems{'Mapped'})
{
print "mapped ";
}
if (exists $mems{'Writeback'})
{
print "writeback "
}
print "\n";
print "anon.label anon\n";
print "anon.draw AREA\n";
print "anon.info Memory used by user-space applications.\n";
if (exists $mems{'PageTables'})
{
print "page_tables.label page_tables\n";
print "page_tables.draw STACK\n";
print "page_tables.info Memory used to map between virtual and physical memory addresses.\n"
}
if (exists $mems{'KernelStack'})
{
print "kernel_stack.label in-kernel stacks\n";
print "kernel_stack.draw STACK\n";
print "kernel_stack.info Memory used by process stack in kernel.\n"
}
if (exists $mems{'SwapCached'})
{
print "swap_cache.label swap_cache\n";
print "swap_cache.draw STACK\n";
print "swap_cache.info A piece of memory that keeps track of pages that have been fetched from swap but not yet been modified.\n";
}
if (exists $mems{'Shmem'})
{
print "shmem.label shmem\n";
print "shmem.draw STACK\n";
print "shmem.info tmpfs, shmfs, SYSV-shmem.\n";
}
if (exists $mems{'VmallocUsed'})
{
print "vmalloc_used.label vmalloc_used\n";
print "vmalloc_used.draw STACK\n";
print "vmalloc_used.info Virtual memory used by the kernel (used when the memory does not have to be physically contiguous).\n";
}
if (exists $mems{'Unevictable'})
{
print "unevictable.label unevictable\n";
print "unevictable.draw STACK\n";
print "unevictable.info Unevictable pages (e.g. mlock()ed).\n";
}
if (exists $mems{'SReclaimable'})
{
print "slab_reclaimable.label slab(reclamable)\n";
print "slab_reclaimable.draw STACK\n";
print "slab_reclaimable.info Memory used by the inode and/or dentry cache.\n";
print "slab_unreclaim.label slab(unreclaim)\n";
print "slab_unreclaim.draw STACK\n";
print "slab_unreclaim.info Memory used by the kernel.\n";
}
elsif (exists $mems{'Slab'})
{
print "slab.label slab_cache\n";
print "slab.draw STACK\n";
print "slab.info Memory used by the kernel (major users are caches like inode, dentry, etc).\n";
}
print "file_cache_dirty.label file_cache(dirty)\n";
print "file_cache_dirty.draw STACK\n";
print "file_cache_dirty.info Parked dirtied file data (file content) cache.\n";
print "file_cache_clean.label file_cache(clean)\n";
print "file_cache_clean.draw STACK\n";
print "file_cache_clean.info Parked non-dirtied file data (file content) cache.\n";
print "free.label unused\n";
print "free.draw STACK\n";
print "free.info Wasted memory. Memory that is not used for anything at all.\n";
print "swap_used.label swap_used\n";
print "swap_used.draw LINE2\n";
print "swap_used.info Swap space used.\n";
if (exists $mems{'Mapped'})
{
print "mapped.label mapped\n";
print "mapped.draw LINE2\n";
print "mapped.info All mmap()ed pages.\n";
}
if (exists $mems{'Writeback'})
{
print "writeback.label writeback\n";
print "writeback.draw LINE2\n";
print "writeback.info All writeback pages.\n";
}
exit 0;
}
# Any optional value needs to be initialized to zero if it's used in a calculation below
# and is has not been set by &fetch_meminfo
$anon = $mems{'Active(anon)'} + $mems{'Inactive(anon)'};
$file = $mems{'Active(file)'} + $mems{'Inactive(file)'};
print "anon.value ", $anon - $mems{'SwapCached'} - $mems{'Shmem'}, "\n";
print "page_tables.value ", $mems{'PageTables'}, "\n";
print "kernel_stack.value ", $mems{'KernelStack'}, "\n";
print "swap_cache.value ", $mems{'SwapCached'}, "\n";
print "shmem.value ", $mems{'Shmem'}, "\n";
print "vmalloc_used.value ", $mems{'VmallocUsed'}, "\n";
print "unevictable.value ", $mems{'Unevictable'}, "\n";
print "slab_unreclaim.value ", $mems{'SUnreclaim'}, "\n";
print "slab_reclaimable.value ", $mems{'SReclaimable'}, "\n";
print "file_cache_dirty.value ", $mems{'Dirty'}, "\n";
print "file_cache_clean.value ", $file - $mems{'Dirty'}, "\n";
print "free.value ", $mems{'MemFree'}, "\n";
print "swap_used.value ", $mems{'SwapTotal'} - $mems{'SwapFree'}, "\n";
print "mapped.value ", $mems{'Mapped'}, "\n";
print "dirty.value ", $mems{'Dirty'}, "\n";
print "writeback.value ", $mems{'Writeback'}, "\n";
sub fetch_meminfo
{
open (IN, "/proc/meminfo") || die "Could not open /proc/meminfo for reading: $!";
while (<IN>)
{
if (/^([\w\(\)]+):\s*(\d+)\s+kb/i)
{
$mems{"$1"} = $2 * 1024;
}
}
close (IN);
# Only 2.6 and above has slab reported in meminfo, so read slabinfo if it isn't in meminfo
if (!$mems{Slab})
{
&fetch_slabinfo;
}
# Support 2.4 Rmap VM based kernels
if (!$mems{'Inactive'} && $mems{'Inact_dirty'} && $mems{'Inact_laundry'} && $mems{'Inact_clean'})
{
$mems{'Inactive'} = $mems{'Inact_dirty'} + $mems{'Inact_laundry'} + $mems{'Inact_clean'}
}
}
sub fetch_slabinfo
{
# In 2.0 there is no slabinfo file, so return if the file doesn't open
open (IN, "/proc/slabinfo") || return;
my @slabinfo;
my $tot_slab_pages = 0;
my $slab_version = <IN>;
if ($slab_version =~ /^slabinfo - version: 1.1/)
{
while (<IN>)
{
if (!/^slabinfo/)
{
@slabinfo = split;
$tot_slab_pages += $slabinfo[5];
}
}
}
close (IN);
if ($tot_slab_pages gt 0)
{
$mems{'Slab'} = $tot_slab_pages * 4096;
}
}
# vim:syntax=perl:ts=8