Re: Testing swap

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



On Thu, Aug 12, 2021 at 02:20:13PM +0100, Matthew Wilcox wrote:
> 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?

Dave, can you just submit your test to xfstests?

> ----- Forwarded message from David Howells <dhowells@xxxxxxxxxx> -----
> 
> Date: Thu, 12 Aug 2021 12:57:50 +0100
> From: David Howells <dhowells@xxxxxxxxxx>
> To: willy@xxxxxxxxxxxxx
> Cc: dhowells@xxxxxxxxxx, trond.myklebust@xxxxxxxxxxxxxxx,
> 	darrick.wong@xxxxxxxxxx, hch@xxxxxx, jlayton@xxxxxxxxxx,
> 	sfrench@xxxxxxxxx, torvalds@xxxxxxxxxxxxxxxxxxxx,
> 	linux-nfs@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx,
> 	linux-fsdevel@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
> 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 -----
---end quoted text---



[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux