From: "Darrick J. Wong" <djwong@kernel.org>
To: Xu Yu <xuyu@linux.alibaba.com>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
hch@infradead.org, riteshh@linux.ibm.com, tytso@mit.edu,
gavin.dg@linux.alibaba.com, fstests <fstests@vger.kernel.org>,
linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: [PATCH] generic: add swapfile maxpages regression test
Date: Wed, 18 Aug 2021 18:43:26 -0700 [thread overview]
Message-ID: <20210819014326.GC12597@magnolia> (raw)
In-Reply-To: <db99c25a8e2a662046e498fd13e5f0c35364164a.1629286473.git.xuyu@linux.alibaba.com>
From: Darrick J. Wong <djwong@kernel.org>
Add regression test for "mm/swap: consider max pages in
iomap_swapfile_add_extent".
Cc: Gang Deng <gavin.dg@linux.alibaba.com>
Cc: Xu Yu <xuyu@linux.alibaba.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
tests/generic/727 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/727.out | 2 ++
2 files changed, 64 insertions(+)
create mode 100755 tests/generic/727
create mode 100644 tests/generic/727.out
diff --git a/tests/generic/727 b/tests/generic/727
new file mode 100755
index 00000000..a546ad51
--- /dev/null
+++ b/tests/generic/727
@@ -0,0 +1,62 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Oracle. All Rights Reserved.
+#
+# FS QA Test 727
+#
+# Regression test for "mm/swap: consider max pages in iomap_swapfile_add_extent"
+
+# Xu Yu found that the iomap swapfile activation code failed to constrain
+# itself to activating however many swap pages that the mm asked us for. This
+# is an deviation in behavior from the classic swapfile code. It also leads to
+# kernel memory corruption if the swapfile is cleverly constructed.
+#
+. ./common/preamble
+_begin_fstest auto swap
+
+# Override the default cleanup function.
+_cleanup()
+{
+ cd /
+ rm -f $tmp.*
+ test -n "$swapfile" && swapoff $swapfile &> /dev/null
+}
+
+# real QA test starts here
+_supported_fs generic
+_require_scratch_swapfile
+
+_scratch_mkfs >> $seqres.full
+_scratch_mount >> $seqres.full
+
+# Assuming we're not borrowing a FAT16 partition from Windows 3.1, we need an
+# unlikely enough name that we can grep /proc/swaps for this.
+swapfile=$SCRATCH_MNT/386spart.par
+_format_swapfile $swapfile 1m >> $seqres.full
+
+swapfile_pages() {
+ local swapfile="$1"
+
+ grep "$swapfile" /proc/swaps | awk '{print $3}'
+}
+
+_swapon_file $swapfile
+before_pages=$(swapfile_pages "$swapfile")
+swapoff $swapfile
+
+# Extend the length of the swapfile but do not rewrite the header.
+# The subsequent swapon should set up 1MB worth of pages, not 2MB.
+$XFS_IO_PROG -f -c 'pwrite 1m 1m' $swapfile >> $seqres.full
+
+_swapon_file $swapfile
+after_pages=$(swapfile_pages "$swapfile")
+swapoff $swapfile
+
+# Both swapon attempts should have found the same number of pages.
+test "$before_pages" -eq "$after_pages" || \
+ echo "swapon added $after_pages pages, expected $before_pages"
+
+# success, all done
+echo Silence is golden
+status=0
+exit
diff --git a/tests/generic/727.out b/tests/generic/727.out
new file mode 100644
index 00000000..2de2b4b2
--- /dev/null
+++ b/tests/generic/727.out
@@ -0,0 +1,2 @@
+QA output created by 727
+Silence is golden
next prev parent reply other threads:[~2021-08-19 1:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 11:36 [PATCH] mm/swap: consider max pages in iomap_swapfile_add_extent Xu Yu
2021-08-18 17:01 ` Darrick J. Wong
2021-08-19 0:59 ` Yu Xu
2021-08-19 1:45 ` Darrick J. Wong
2021-08-19 6:31 ` Yu Xu
2021-08-19 1:43 ` Darrick J. Wong [this message]
2021-08-19 5:14 ` [PATCH] generic: add swapfile maxpages regression test Zorro Lang
2021-08-19 8:22 ` Christoph Hellwig
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=20210819014326.GC12597@magnolia \
--to=djwong@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=gavin.dg@linux.alibaba.com \
--cc=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riteshh@linux.ibm.com \
--cc=tytso@mit.edu \
--cc=xuyu@linux.alibaba.com \
/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;
as well as URLs for NNTP newsgroup(s).