Harald Hoyer 308914
From 7dd8a2f4d351ce8975c0af122732a2a12697c8cc Mon Sep 17 00:00:00 2001
Harald Hoyer 308914
From: Kairui Song <kasong@redhat.com>
Harald Hoyer 308914
Date: Wed, 8 Apr 2020 20:09:38 +0800
Harald Hoyer 308914
Subject: [PATCH] Add 99memstrack module
Harald Hoyer 308914
Harald Hoyer 308914
memstrack is a new tool to track the overall memory usage and
Harald Hoyer 308914
allocation, which can help off load the improve the builtin module
Harald Hoyer 308914
memory tracing function in dracut.
Harald Hoyer 308914
Harald Hoyer 308914
With this change, the rd.memdebug=4 behavior is similiar with before,
Harald Hoyer 308914
but the report is defered to pre-pivot, so the memory usage info
Harald Hoyer 308914
during the whole initramfs run is traced. And the ourput format is
Harald Hoyer 308914
changed a bit:
Harald Hoyer 308914
Harald Hoyer 308914
  dracut-pre-pivot[519]: ======== Report format module_summary: ========
Harald Hoyer 308914
  dracut-pre-pivot[519]: Module squashfs using 10.4MB (2658 pages), peak allocation 10.4MB (2671 pages)
Harald Hoyer 308914
  dracut-pre-pivot[519]: Module qxl using 3.4MB (865 pages), peak allocation 3.4MB (880 pages)
Harald Hoyer 308914
  dracut-pre-pivot[519]: Module crc32c_intel using 2.0MB (519 pages), peak allocation 3.0MB (769 pages)
Harald Hoyer 308914
  dracut-pre-pivot[519]: Module serio_raw using 2.0MB (505 pages), peak allocation 3.6MB (918 pages)
Harald Hoyer 308914
  dracut-pre-pivot[519]: Module virtio_console using 1.6MB (416 pages), peak allocation 1.6MB (419 pages)
Harald Hoyer 308914
  ... snip ...
Harald Hoyer 308914
  dracut-pre-pivot[519]: ======== Report format module_summary END ========
Harald Hoyer 308914
Harald Hoyer 308914
It now contains more detail and also includes the peak usage which could
Harald Hoyer 308914
be more helpful.
Harald Hoyer 308914
Harald Hoyer 308914
And now it have a rd.memdebug=5, which will print more detail about
Harald Hoyer 308914
the stack trace of the top memory user, also printed on pri-pivot:
Harald Hoyer 308914
Harald Hoyer 308914
  dracut-pre-pivot[519]: ======== Report format module_top: ========
Harald Hoyer 308914
  dracut-pre-pivot[519]: Top stack usage of module squashfs:
Harald Hoyer 308914
  dracut-pre-pivot[519]:   (null) Pages: 2658 (peak: 2671)
Harald Hoyer 308914
  dracut-pre-pivot[519]:     (null) Pages: 2658 (peak: 2671)
Harald Hoyer 308914
  dracut-pre-pivot[519]:       async_page_fault (0xffffffff81a01149) Pages: 1448 (peak: 1461)
Harald Hoyer 308914
  dracut-pre-pivot[519]:         do_async_page_fault (0xffffffff8105c509) Pages: 1448 (peak: 1461)
Harald Hoyer 308914
  dracut-pre-pivot[519]:           do_page_fault (0xffffffff8106296a) Pages: 1448 (peak: 1461)
Harald Hoyer 308914
  dracut-pre-pivot[519]:             do_user_addr_fault (0xffffffff810626bd) Pages: 1448 (peak: 1461)
Harald Hoyer 308914
  dracut-pre-pivot[519]:               handle_mm_fault (0xffffffff812940c4) Pages: 1448 (peak: 1461)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                 __handle_mm_fault (0xffffffff81293627) Pages: 1195 (peak: 1208)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                   __do_fault (0xffffffff8128b07e) Pages: 1195 (peak: 1208)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                     filemap_fault (0xffffffff8124c0b9) Pages: 1195 (peak: 1208)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                       __do_page_cache_readahead (0xffffffff812585da) Pages: 1063 (peak: 1076)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                         read_pages (0xffffffff812583c2) Pages: 1063 (peak: 1076)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                           squashfs_readpage squashfs (0xffffffffc0022073) Pages: 1039 (peak: 1052)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                             squashfs_readpage_block squashfs (0xffffffffc0024334) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                               squashfs_copy_cache squashfs (0xffffffffc0021a3f) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                 pagecache_get_page (0xffffffff8124abf7) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                   __page_cache_alloc (0xffffffff81247df6) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                     alloc_pages_current (0xffffffff812cdca7) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                       __alloc_pages_nodemask (0xffffffff812b3107) Pages: 744 (peak: 744)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                         __alloc_pages_nodemask (0xffffffff812b3107) Pages: 1488 (peak: 1488)
Harald Hoyer 308914
  dracut-pre-pivot[519]: Top stack usage of module qxl:
Harald Hoyer 308914
  dracut-pre-pivot[519]:   (null) Pages: 865 (peak: 880)
Harald Hoyer 308914
  dracut-pre-pivot[519]:     entry_SYSCALL_64_after_hwframe (0xffffffff81a0008c) Pages: 855 (peak: 858)
Harald Hoyer 308914
  dracut-pre-pivot[519]:       do_syscall_64 (0xffffffff81002a5a) Pages: 855 (peak: 858)
Harald Hoyer 308914
  dracut-pre-pivot[519]:         __x64_sys_finit_module (0xffffffff8117ccea) Pages: 811 (peak: 811)
Harald Hoyer 308914
  dracut-pre-pivot[519]:           __do_sys_finit_module (0xffffffff8117cc6e) Pages: 811 (peak: 811)
Harald Hoyer 308914
  dracut-pre-pivot[519]:             load_module (0xffffffff8117c6be) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:               do_init_module (0xffffffff81179e72) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                 do_one_initcall (0xffffffff81000d5a) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                   serio_raw_poll serio_raw (0xffffffffc0200054) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                     __pci_register_driver (0xffffffff81557804) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                       driver_register (0xffffffff8167ed24) Pages: 802 (peak: 802)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                         bus_add_driver (0xffffffff8167cbb2) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                           driver_attach (0xffffffff8167d28e) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                             bus_for_each_dev (0xffffffff8167b62c) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                               __driver_attach (0xffffffff8167e18f) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                 device_driver_attach (0xffffffff8167e0ed) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                   driver_probe_device (0xffffffff8167de6c) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                     really_probe (0xffffffff8167d9c9) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                       pci_device_probe (0xffffffff81559627) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                         local_pci_probe (0xffffffff81557f98) Pages: 801 (peak: 801)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                           qxl_pci_probe qxl (0xffffffffc01f0387) Pages: 773 (peak: 773)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                             drm_fbdev_generic_setup drm_kms_helper (0xffffffffc01b30c5) Pages: 773 (peak: 773)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                               drm_fbdev_client_hotplug drm_kms_helper (0xffffffffc01b2656) Pages: 773 (peak: 773)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                                 __drm_fb_helper_initial_config_and_unlock drm_kms_helper (0xffffffffc01b1a28) Pages: 770 (peak: 770)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                                   drm_fb_helper_generic_probe drm_kms_helper (0xffffffffc01b2fa5) Pages: 770 (peak: 770)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                                     vzalloc (0xffffffff812aa39c) Pages: 770 (peak: 770)
Harald Hoyer 308914
  dracut-pre-pivot[519]:                                                       __vmalloc_node_range (0xffffffff812aa200) Pages: 768 (peak: 768)
Harald Hoyer 308914
  ... snip ...
Harald Hoyer 308914
  ======== Report format module_top END ========
Harald Hoyer 308914
Harald Hoyer 308914
This could be very helpful for debuging memory usage issues.
Harald Hoyer 308914
---
Harald Hoyer 308914
 dracut.cmdline.7.asc                      | 16 ++++++++++------
Harald Hoyer 308914
 dracut.spec                               |  2 ++
Harald Hoyer 308914
 modules.d/99base/dracut-lib.sh            |  2 +-
Harald Hoyer 308914
 modules.d/99memstrack/memstrack-report.sh | 23 +++++++++++++++++++++++
Harald Hoyer 308914
 modules.d/99memstrack/memstrack-start.sh  | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Harald Hoyer 308914
 modules.d/99memstrack/memstrack.service   | 13 +++++++++++++
Harald Hoyer 308914
 modules.d/99memstrack/module-setup.sh     | 27 +++++++++++++++++++++++++++
Harald Hoyer 308914
 7 files changed, 144 insertions(+), 7 deletions(-)
Harald Hoyer 308914
Harald Hoyer 308914
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer 308914
index c53601ea..4d4970c8 100644
Harald Hoyer 308914
--- a/dracut.cmdline.7.asc
Harald Hoyer 308914
+++ b/dracut.cmdline.7.asc
Harald Hoyer 308914
@@ -188,8 +188,8 @@ It should be attached to any report about dracut problems.
Harald Hoyer 308914
     _/run/initramfs/init.log_.
Harald Hoyer 308914
     If "quiet" is set, it also logs to the console.
Harald Hoyer 308914
 
Harald Hoyer 308914
-**rd.memdebug=[0-3]**::
Harald Hoyer 308914
-    Print memory usage info at various points, set the verbose level from 0 to 4.
Harald Hoyer 308914
+**rd.memdebug=[0-5]**::
Harald Hoyer 308914
+    Print memory usage info at various points, set the verbose level from 0 to 5.
Harald Hoyer 308914
 +
Harald Hoyer 308914
     Higher level means more debugging output:
Harald Hoyer 308914
 +
Harald Hoyer 308914
@@ -198,10 +198,14 @@ It should be attached to any report about dracut problems.
Harald Hoyer 308914
     1 - partial /proc/meminfo
Harald Hoyer 308914
     2 - /proc/meminfo
Harald Hoyer 308914
     3 - /proc/meminfo + /proc/slabinfo
Harald Hoyer 308914
-    4 - /proc/meminfo + /proc/slabinfo + tracekomem
Harald Hoyer 308914
-        NOTE: tracekomem is a shell script utilizing kernel trace to track
Harald Hoyer 308914
-              the rough total memory consumption of kernel modules during
Harald Hoyer 308914
-              loading. It may override other trace configurations.
Harald Hoyer 308914
+    4 - /proc/meminfo + /proc/slabinfo + memstrack summary
Harald Hoyer 308914
+        NOTE: memstrack is a memory tracing tool that tracks the total memory
Harald Hoyer 308914
+              consumption, and peak memory consumption of each kernel modules
Harald Hoyer 308914
+              and userspace progress during the whole initramfs runtime, report
Harald Hoyer 308914
+              is genereted and the end of initramsfs run.
Harald Hoyer 308914
+    5 - /proc/meminfo + /proc/slabinfo + memstrack (with top memory stacktrace)
Harald Hoyer 308914
+        NOTE: memstrack (with top memory stacktrace) will print top memory
Harald Hoyer 308914
+              allocation stack traces during the whole initramfs runtime.
Harald Hoyer 308914
 ----
Harald Hoyer 308914
 
Harald Hoyer 308914
 **rd.break**::
Harald Hoyer 308914
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer 308914
index 0369dde6..1eb47402 100644
Harald Hoyer 308914
--- a/dracut.spec
Harald Hoyer 308914
+++ b/dracut.spec
Harald Hoyer 308914
@@ -77,6 +77,7 @@ Requires: xz
Harald Hoyer 308914
 Requires: gzip
Harald Hoyer 308914
 
Harald Hoyer 308914
 %if 0%{?fedora} || 0%{?rhel}
Harald Hoyer 308914
+Recommends: memstrack
Harald Hoyer 308914
 Recommends: hardlink
Harald Hoyer 308914
 Recommends: pigz
Harald Hoyer 308914
 Recommends: kpartx
Harald Hoyer 308914
@@ -403,6 +404,7 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne
Harald Hoyer 308914
 %{dracutlibdir}/modules.d/98syslog
Harald Hoyer 308914
 %{dracutlibdir}/modules.d/98usrmount
Harald Hoyer 308914
 %{dracutlibdir}/modules.d/99base
Harald Hoyer 308914
+%{dracutlibdir}/modules.d/99memstrack
Harald Hoyer 308914
 %{dracutlibdir}/modules.d/99fs-lib
Harald Hoyer 308914
 %{dracutlibdir}/modules.d/99shutdown
Harald Hoyer 308914
 %attr(0644,root,root) %ghost %config(missingok,noreplace) %{_localstatedir}/log/dracut.log
Harald Hoyer 308914
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 308914
index b7020892..e602bacb 100755
Harald Hoyer 308914
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 308914
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 308914
@@ -1187,7 +1187,7 @@ are_lists_eq() {
Harald Hoyer 308914
 
Harald Hoyer 308914
 setmemdebug() {
Harald Hoyer 308914
     if [ -z "$DEBUG_MEM_LEVEL" ]; then
Harald Hoyer 308914
-        export DEBUG_MEM_LEVEL=$(getargnum 0 0 3 rd.memdebug)
Harald Hoyer 308914
+        export DEBUG_MEM_LEVEL=$(getargnum 0 0 5 rd.memdebug)
Harald Hoyer 308914
     fi
Harald Hoyer 308914
 }
Harald Hoyer 308914
 
Harald Hoyer 308914
diff --git a/modules.d/99memstrack/memstrack-report.sh b/modules.d/99memstrack/memstrack-report.sh
Harald Hoyer 308914
new file mode 100755
Harald Hoyer 308914
index 00000000..241e8621
Harald Hoyer 308914
--- /dev/null
Harald Hoyer 308914
+++ b/modules.d/99memstrack/memstrack-report.sh
Harald Hoyer 308914
@@ -0,0 +1,23 @@
Harald Hoyer 308914
+#!/usr/bin/env bash
Harald Hoyer 308914
+. /lib/dracut-lib.sh
Harald Hoyer 308914
+
Harald Hoyer 308914
+if ! [ "$DEBUG_MEM_LEVEL" -ge 4 ]; then
Harald Hoyer 308914
+    exit 0
Harald Hoyer 308914
+fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+if type -P systemctl >/dev/null; then
Harald Hoyer 308914
+    systemctl stop memstrack.service
Harald Hoyer 308914
+else
Harald Hoyer 308914
+    get_pid_of_tracer () {
Harald Hoyer 308914
+        local _user _pid _rest
Harald Hoyer 308914
+        read _user _pid _rest <<< $(ps aux | grep [m]emstrack | head -1)
Harald Hoyer 308914
+        echo $_pid
Harald Hoyer 308914
+    }
Harald Hoyer 308914
+
Harald Hoyer 308914
+    kill -s INT $(get_pid_of_tracer)
Harald Hoyer 308914
+    while [[ -n $(get_pid_of_tracer) ]]; do
Harald Hoyer 308914
+        sleep 1
Harald Hoyer 308914
+    done
Harald Hoyer 308914
+fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+cat /.memstrack
Harald Hoyer 308914
diff --git a/modules.d/99memstrack/memstrack-start.sh b/modules.d/99memstrack/memstrack-start.sh
Harald Hoyer 308914
new file mode 100755
Harald Hoyer 308914
index 00000000..5aa73efe
Harald Hoyer 308914
--- /dev/null
Harald Hoyer 308914
+++ b/modules.d/99memstrack/memstrack-start.sh
Harald Hoyer 308914
@@ -0,0 +1,68 @@
Harald Hoyer 308914
+#!/bin/sh
Harald Hoyer 308914
+# Mount kernel debug fs so debug tools can work.
Harald Hoyer 308914
+# memdebug=4 and memdebug=5 requires debug fs to be mounted.
Harald Hoyer 308914
+# And there is no need to umount it.
Harald Hoyer 308914
+
Harald Hoyer 308914
+type getargnum >/dev/null 2>&1 || . /lib/dracut-lib.sh
Harald Hoyer 308914
+
Harald Hoyer 308914
+# "sys/kernel/tracing" has the priority if exists.
Harald Hoyer 308914
+get_trace_base() {
Harald Hoyer 308914
+    # trace access through debugfs would be obsolete if "/sys/kernel/tracing" is available.
Harald Hoyer 308914
+    if [ -d "/sys/kernel/tracing" ]; then
Harald Hoyer 308914
+        echo "/sys/kernel"
Harald Hoyer 308914
+    else
Harald Hoyer 308914
+        echo "/sys/kernel/debug"
Harald Hoyer 308914
+    fi
Harald Hoyer 308914
+}
Harald Hoyer 308914
+
Harald Hoyer 308914
+is_debugfs_ready() {
Harald Hoyer 308914
+    [ -f "$(get_trace_base)/tracing/trace" ]
Harald Hoyer 308914
+}
Harald Hoyer 308914
+
Harald Hoyer 308914
+prepare_debugfs() {
Harald Hoyer 308914
+    local trace_base
Harald Hoyer 308914
+
Harald Hoyer 308914
+    trace_base=$(get_trace_base)
Harald Hoyer 308914
+    # old debugfs interface case.
Harald Hoyer 308914
+    if ! [ -d "$trace_base/tracing" ]; then
Harald Hoyer 308914
+        mount none -t debugfs $trace_base
Harald Hoyer 308914
+    # new tracefs interface case.
Harald Hoyer 308914
+    elif ! [ -f "$trace_base/tracing/trace" ]; then
Harald Hoyer 308914
+        mount none -t tracefs "$trace_base/tracing"
Harald Hoyer 308914
+    fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+    if ! [ -f "$trace_base/tracing/trace" ]; then
Harald Hoyer 308914
+        echo "WARN: failed to mount debugfs"
Harald Hoyer 308914
+        return 1
Harald Hoyer 308914
+    fi
Harald Hoyer 308914
+}
Harald Hoyer 308914
+
Harald Hoyer 308914
+if ! is_debugfs_ready ; then
Harald Hoyer 308914
+    prepare_debugfs
Harald Hoyer 308914
+fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+if [ -n "$DEBUG_MEM_LEVEL" ]; then
Harald Hoyer 308914
+    if [ "$DEBUG_MEM_LEVEL" -ge 5 ]; then
Harald Hoyer 308914
+        echo "memstrack - will report kernel module memory usage summary and top allocation stack"
Harald Hoyer 308914
+        memstrack --report module_summary,module_top --notui --throttle 80 -o /.memstrack &
Harald Hoyer 308914
+    elif [ "$DEBUG_MEM_LEVEL" -ge 4 ]; then
Harald Hoyer 308914
+        echo "memstrack - will report memory usage summary"
Harald Hoyer 308914
+        memstrack --report module_summary --notui --throttle 80 -o /.memstrack &
Harald Hoyer 308914
+    else
Harald Hoyer 308914
+        exit 0;
Harald Hoyer 308914
+    fi
Harald Hoyer 308914
+fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+PID=$!
Harald Hoyer 308914
+RET=$?
Harald Hoyer 308914
+
Harald Hoyer 308914
+if [ $RET -ne 0 ]; then
Harald Hoyer 308914
+    echo "Failed to start memstrack, exit status: $RET"
Harald Hoyer 308914
+    exit $RET
Harald Hoyer 308914
+fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+# Wait a second for memstrack to setup everything, avoid missing any event
Harald Hoyer 308914
+sleep 1
Harald Hoyer 308914
+
Harald Hoyer 308914
+echo $PID > /run/memstrack.pid
Harald Hoyer 308914
+disown
Harald Hoyer 308914
diff --git a/modules.d/99memstrack/memstrack.service b/modules.d/99memstrack/memstrack.service
Harald Hoyer 308914
new file mode 100644
Harald Hoyer 308914
index 00000000..6b47adef
Harald Hoyer 308914
--- /dev/null
Harald Hoyer 308914
+++ b/modules.d/99memstrack/memstrack.service
Harald Hoyer 308914
@@ -0,0 +1,13 @@
Harald Hoyer 308914
+[Unit]
Harald Hoyer 308914
+Description=Memstrack Anylazing Service
Harald Hoyer 308914
+DefaultDependencies=no
Harald Hoyer 308914
+Before=dracut-cmdline.service systemd-udevd.service local-fs-pre.target
Harald Hoyer 308914
+IgnoreOnIsolate=true
Harald Hoyer 308914
+
Harald Hoyer 308914
+[Service]
Harald Hoyer 308914
+Type=simple
Harald Hoyer 308914
+ExecStart=/bin/memstrack-start
Harald Hoyer 308914
+PIDFile=/run/memstrack.pid
Harald Hoyer 308914
+StandardInput=null
Harald Hoyer 308914
+StandardOutput=syslog+console
Harald Hoyer 308914
+StandardError=syslog+console
Harald Hoyer 308914
diff --git a/modules.d/99memstrack/module-setup.sh b/modules.d/99memstrack/module-setup.sh
Harald Hoyer 308914
new file mode 100755
Harald Hoyer 308914
index 00000000..d5bacb4d
Harald Hoyer 308914
--- /dev/null
Harald Hoyer 308914
+++ b/modules.d/99memstrack/module-setup.sh
Harald Hoyer 308914
@@ -0,0 +1,27 @@
Harald Hoyer 308914
+#!/usr/bin/bash
Harald Hoyer 308914
+
Harald Hoyer 308914
+check() {
Harald Hoyer 308914
+    if type -P memstrack >/dev/null; then
Harald Hoyer 308914
+        dinfo "memstrack is available"
Harald Hoyer 308914
+        return 0
Harald Hoyer 308914
+    fi
Harald Hoyer 308914
+
Harald Hoyer 308914
+    dinfo "memstrack is not available"
Harald Hoyer 308914
+    dinfo "If you need to use rd.memdebug>=4, please install memstrack"
Harald Hoyer 308914
+
Harald Hoyer 308914
+    return 1
Harald Hoyer 308914
+}
Harald Hoyer 308914
+
Harald Hoyer 308914
+depends() {
Harald Hoyer 308914
+    return 0
Harald Hoyer 308914
+}
Harald Hoyer 308914
+
Harald Hoyer 308914
+install() {
Harald Hoyer 308914
+    inst "/bin/memstrack" "/bin/memstrack"
Harald Hoyer 308914
+
Harald Hoyer 308914
+    inst "$moddir/memstrack-start.sh" "/bin/memstrack-start"
Harald Hoyer 308914
+    inst_hook cleanup 99 "$moddir/memstrack-report.sh"
Harald Hoyer 308914
+
Harald Hoyer 308914
+    inst "$moddir/memstrack.service" "$systemdsystemunitdir/memstrack.service"
Harald Hoyer 308914
+    systemctl -q --root "$initdir" add-wants initrd.target memstrack.service
Harald Hoyer 308914
+}
Harald Hoyer 308914