From: Jason Miu <jasonmiu@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Shuah Khan <shuah@kernel.org>,
David Rientjes <rientjes@google.com>,
Shakeel Butt <shakeel.butt@linux.dev>
Cc: Lorenzo Stoakes <ljs@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Greg Thelen <gthelen@google.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, Jason Miu <jasonmiu@google.com>
Subject: [PATCH 3/3] selftests: mm: add script for memory allocation stall test
Date: Wed, 19 Aug 2026 00:05:38 -0700 [thread overview]
Message-ID: <20260819070538.2404983-4-jasonmiu@google.com> (raw)
In-Reply-To: <20260819070538.2404983-1-jasonmiu@google.com>
Integrate page_alloc_stall.sh, a script to synchronize userspace and
kernelspace workloads to reproduce page allocation stalls.
Provision a synthetic loopback zswap block device, inject the
test_mempress_timer.ko module to generate atomic page allocations
inside kernel timers, and execute the page_alloc_stall_pressure.py
payload to induce system-wide swap activity.
Signed-off-by: Jason Miu <jasonmiu@google.com>
---
.../testing/selftests/mm/page_alloc_stall.sh | 80 +++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100644 tools/testing/selftests/mm/page_alloc_stall.sh
diff --git a/tools/testing/selftests/mm/page_alloc_stall.sh b/tools/testing/selftests/mm/page_alloc_stall.sh
new file mode 100644
index 000000000000..3ece026fd680
--- /dev/null
+++ b/tools/testing/selftests/mm/page_alloc_stall.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# page_alloc_stall.sh
+#
+# Orchestrator script to generate concurrent userspace and kernelspace
+# memory allocation pressure over a synthetic zswap backing block device
+# to artificially induce systemic memory contention.
+#
+# Dependencies:
+# - External memtoy binary (Source: https://github.com/kosaki/memtoy)
+#
+# Usage:
+# ./page_alloc_stall.sh [hog_percent=80] [workers=64] [overcommit=2.5] \
+# [swap_gb=10%_RAM] [memtoy_path="memtoy/memtoy"]
+
+set -e
+
+SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
+PYTHON_CMD=${PYTHON_CMD:-python3}
+
+HOG_PERCENT=${1:-80}
+NUM_WORKERS=${2:-64}
+OVERCOMMIT=${3:-2.5}
+TARGET_SWAP_GB=$4
+MEMTOY_PATH=${5:-"memtoy/memtoy"}
+
+function total_mem_gb()
+{
+ awk '/MemTotal/ {print int($2 / 1024 / 1024)}' /proc/meminfo
+}
+
+function enable_zswap_file()
+{
+ local swap_size_gb=$1
+
+ fallocate -l ${swap_size_gb}G "$SCRIPT_DIR/swap.img"
+
+ LOOP_DEV=$(losetup -f --show "$SCRIPT_DIR/swap.img")
+ mkswap $LOOP_DEV
+ swapon $LOOP_DEV
+
+ echo 1 > /sys/module/zswap/parameters/enabled
+}
+
+function cleanup()
+{
+ echo "Tearing down the test..."
+ if lsmod | grep -q test_mempress_timer; then
+ rmmod test_mempress_timer || echo "Failed to rmmod mempress_timer"
+ fi
+
+ # Check if loop dev was actually created before trying to destroy it
+ if [ -n "$LOOP_DEV" ]; then
+ swapoff $LOOP_DEV 2>/dev/null || true
+ losetup -d $LOOP_DEV 2>/dev/null || true
+ fi
+ rm -f "$SCRIPT_DIR/swap.img"
+}
+
+trap cleanup EXIT
+
+if [ -z "$TARGET_SWAP_GB" ]; then
+ # use 10% of the total mem for zswap file by default.
+ TARGET_SWAP_GB=$(($(total_mem_gb) / 10))
+fi
+
+enable_zswap_file $TARGET_SWAP_GB
+
+KROOT=$(cd "$SCRIPT_DIR/../../../.." && pwd)
+KO_PATH="$KROOT/lib/test_mempress_timer.ko"
+
+if [ "$KO_PATH" ]; then
+ insmod "$KO_PATH"
+else
+ echo "WARNING: $KO_PATH not found! Aborting the test."
+ exit 1
+fi
+
+"$PYTHON_CMD" "$SCRIPT_DIR/page_alloc_stall_pressure.py" $HOG_PERCENT $NUM_WORKERS $OVERCOMMIT $MEMTOY_PATH
--
2.55.0.691.gc56d675ccc-goog
next prev parent reply other threads:[~2026-08-19 7:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 7:05 [RFC PATCH 0/3] selftests: mm: introduce page allocation stall reproducer Jason Miu
2026-08-19 7:05 ` [PATCH 1/3] lib/test_mempress_timer: add module to generate kernel allocation pressure Jason Miu
2026-08-19 7:05 ` [PATCH 2/3] selftests: mm: add script to induce userspace memory contention Jason Miu
2026-08-19 7:05 ` Jason Miu [this message]
2026-08-21 0:03 ` [RFC PATCH 0/3] selftests: mm: introduce page allocation stall reproducer Andrew Morton
2026-08-21 9:53 ` David Hildenbrand (Arm)
2026-08-21 10:44 ` Lorenzo Stoakes (ARM)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260819070538.2404983-4-jasonmiu@google.com \
--to=jasonmiu@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=gthelen@google.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox