From: Matthew Wilcox <willy@infradead.org>
To: fstests@vger.kernel.org
Cc: sfrench@samba.org, linux-fsdevel@vger.kernel.org
Subject: Testing swap
Date: Thu, 12 Aug 2021 14:20:13 +0100 [thread overview]
Message-ID: <YRUgDfwHNrcL47xu@casper.infradead.org> (raw)
All the current xfstests for swap only test setting up a swap partition,
not actually doing swap to it. That's why this bug went unnoticed for
two years and why Steve French is still under the impression that
swap-over-CIFS works (it doesn't). Could somebody adapt Dave's test
into the xfstests framework?
----- Forwarded message from David Howells <dhowells@redhat.com> -----
Date: Thu, 12 Aug 2021 12:57:50 +0100
From: David Howells <dhowells@redhat.com>
To: willy@infradead.org
Cc: dhowells@redhat.com, trond.myklebust@primarydata.com,
darrick.wong@oracle.com, hch@lst.de, jlayton@kernel.org,
sfrench@samba.org, torvalds@linux-foundation.org,
linux-nfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] nfs: Fix write to swapfile failure due to
generic_write_checks()
User-Agent: StGit/0.23
Trying to use a swapfile on NFS results in every DIO write failing with
ETXTBSY because generic_write_checks(), as called by nfs_direct_write()
from nfs_direct_IO(), forbids writes to swapfiles.
Fix this by introducing a new kiocb flag, IOCB_SWAP, that's set by the swap
code to indicate that the swapper is doing this operation and so overrule
the check in generic_write_checks().
Without this patch, the following is seen:
Write error on dio swapfile (3800334336)
Altering __swap_writepage() to show the error shows:
Write error (-26) on dio swapfile (3800334336)
Tested by swapping off all swap partitions and then swapping on a prepared
NFS file (CONFIG_NFS_SWAP=y is also needed). Enough copies of the
following program then need to be run to force swapping to occur (at least
one per gigabyte of RAM):
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
int main()
{
unsigned int pid = getpid(), iterations = 0;
size_t i, j, size = 1024 * 1024 * 1024;
char *p;
bool mismatch;
p = malloc(size);
if (!p) {
perror("malloc");
exit(1);
}
srand(pid);
for (i = 0; i < size; i += 4)
*(unsigned int *)(p + i) = rand();
do {
for (j = 0; j < 16; j++) {
for (i = 0; i < size; i += 4096)
*(unsigned int *)(p + i) += 1;
iterations++;
}
mismatch = false;
srand(pid);
for (i = 0; i < size; i += 4) {
unsigned int r = rand();
unsigned int v = *(unsigned int *)(p + i);
if (i % 4096 == 0)
v -= iterations;
if (v != r) {
fprintf(stderr, "mismatch %zx: %x != %x (diff %x)\n",
i, v, r, v - r);
mismatch = true;
}
}
} while (!mismatch);
exit(1);
}
----- End forwarded message -----
next reply other threads:[~2021-08-12 13:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-12 13:20 Matthew Wilcox [this message]
2021-08-13 6:47 ` Testing swap 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=YRUgDfwHNrcL47xu@casper.infradead.org \
--to=willy@infradead.org \
--cc=fstests@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sfrench@samba.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