summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/share/initramfs-tools/scripts/init-premount/memory_wipe
blob: a291ff70831f79b5e5ba34bf1a4a59f4904258dc (plain)
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
#!/bin/sh

PREREQ=""

prereqs() {
   echo "${PREREQ}"
}

tweak_sysctl() {
   echo 3   > /proc/sys/kernel/printk

   echo 3   > /proc/sys/vm/drop_caches
   echo 256 > /proc/sys/vm/min_free_kbytes

   echo 1   > /proc/sys/vm/overcommit_memory
   echo 1   > /proc/sys/vm/oom_kill_allocating_task
   echo 0   > /proc/sys/vm/oom_dump_tasks
}

case ${1} in
   prereqs)
      prereqs
      exit 0
      ;;
esac

if [ -n "${sdmem}" ] ; then
   tweak_sysctl
   if [ -z "${sdmemopts}" ] ; then
      sdmemopts="v"
   fi
   # We run one instance of sdmem per 2 GiB of RAM to deal with the
   # x86 per-process memory limitation.
   mem=$(free | awk '/Mem:/ { print $2 }')
   instances=$((${mem}/(2*1024*1024)+1))
   for i in $(seq 1 "${instances}") ; do
      ( /usr/bin/sdmem "-${sdmemopts}" ; killall sdmem >/dev/null 2>&1 ) &
   done
   # Wait for sdmem jobs to finish.
   wait
fi

if [ "${sdmemdebug}" = 1 ] ; then
   echo "Going to sleep 10 minutes. Happy dumping!"
   sleep 600
fi

case "${sdmem}" in
   halt)
      /sbin/halt -fndp
      ;;
   reboot)
      /sbin/reboot -fnd
      ;;
   *)
      ;;
esac