-
Notifications
You must be signed in to change notification settings - Fork 128
/
memory_usage.sh
55 lines (46 loc) · 938 Bytes
/
memory_usage.sh
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
#!/bin/bash
FILE_NAME=`basename $0`
memsize=$2
function usage()
{
echo "Usage:$FILE_NAME consume memory_size|release -----the value of memory_size like 100M 2G and etc"
echo "Example: $FILE_NAME consume 1G"
echo " $FILE_NAME release"
}
function consume()
{
if [ -d /tmp/memory ];then
echo "/tmp/memory already exists"
else
mkdir /tmp/memory
fi
mount -t tmpfs -o size=$1 tmpfs /tmp/memory
dd if=/dev/zero of=/tmp/memory/block
}
function release()
{
rm /tmp/memory/block;ret=$?
if [ $ret != 0 ]; then
echo "remove memory data failed"
return $ret
fi
umount /tmp/memory;ret=$?
if [ $ret != 0 ]; then
echo "umount memory filedir failed"
return $ret
fi
rmdir /tmp/memory;ret=$?
if [ $ret != 0 ]; then
echo "remove memory filedir failed"
return $ret
fi
}
function main()
{
case "$1" in
consume) consume $memsize;;
release) release;;
*) usage;exit 1;;
esac
}
main $*