diff mbox

[3/4] fsstress: do memset randomly before write operations

Message ID 1497629466-22647-3-git-send-email-zlang@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zorro Lang June 16, 2017, 4:11 p.m. UTC
Recently we found a bug by trigger a page fault when io-vector of
writev is in processing. If do memset between malloc() and write
operations, memset will init the pages. So do memset randomly
maybe help to cover above situation.

Signed-off-by: Zorro Lang <zlang@redhat.com>
---
 ltp/fsstress.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Zorro Lang June 19, 2017, 9:52 a.m. UTC | #1
On Sat, Jun 17, 2017 at 12:11:05AM +0800, Zorro Lang wrote:
> Recently we found a bug by trigger a page fault when io-vector of
> writev is in processing. If do memset between malloc() and write
> operations, memset will init the pages. So do memset randomly
> maybe help to cover above situation.
> 
> Signed-off-by: Zorro Lang <zlang@redhat.com>
> ---
>  ltp/fsstress.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> index 4ff90d5..e1b73e4 100644
> --- a/ltp/fsstress.c
> +++ b/ltp/fsstress.c
> @@ -1924,7 +1924,8 @@ do_aio_rw(int opno, long r, int flags)
>  		off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
>  		off -= (off % align);
>  		off %= maxfsize;
> -		memset(buf, nameseq & 0xff, len);
> +		/* randomly memset maybe trigger page fault at write time */
> +		if (random() / 2) memset(buf, nameseq & 0xff, len);

Sorry for my mistake, all "(random() / 2)" should be "random() % 2".

Thanks,
Zorro

>  		io_prep_pwrite(&iocb, fd, buf, len, off);
>  	} else {
>  		off = (off64_t)(lr % stb.st_size);
> @@ -2455,7 +2456,8 @@ dwrite_f(int opno, long r)
>  	buf = memalign(diob.d_mem, len);
>  	off %= maxfsize;
>  	lseek64(fd, off, SEEK_SET);
> -	memset(buf, nameseq & 0xff, len);
> +	/* randomly memset maybe trigger page fault at write time */
> +	if (random() / 2) memset(buf, nameseq & 0xff, len);
>  	e = write(fd, buf, len) < 0 ? errno : 0;
>  	free(buf);
>  	if (v)
> @@ -3672,7 +3674,8 @@ write_f(int opno, long r)
>  	lseek64(fd, off, SEEK_SET);
>  	len = (random() % FILELEN_MAX) + 1;
>  	buf = malloc(len);
> -	memset(buf, nameseq & 0xff, len);
> +	/* randomly memset maybe trigger page fault at write time */
> +	if (random() / 2) memset(buf, nameseq & 0xff, len);
>  	e = write(fd, buf, len) < 0 ? errno : 0;
>  	free(buf);
>  	if (v)
> @@ -3733,7 +3736,8 @@ writev_f(int opno, long r)
>  	lseek64(fd, off, SEEK_SET);
>  	len = (random() % FILELEN_MAX) + 1;
>  	buf = malloc(len);
> -	memset(buf, nameseq & 0xff, len);
> +	/* randomly memset maybe trigger page fault at write time */
> +	if (random() / 2) memset(buf, nameseq & 0xff, len);
>  
>  	iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
>  	iov = malloc(sizeof(struct iovec) * iovcnt);
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 4ff90d5..e1b73e4 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -1924,7 +1924,8 @@  do_aio_rw(int opno, long r, int flags)
 		off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
 		off -= (off % align);
 		off %= maxfsize;
-		memset(buf, nameseq & 0xff, len);
+		/* randomly memset maybe trigger page fault at write time */
+		if (random() / 2) memset(buf, nameseq & 0xff, len);
 		io_prep_pwrite(&iocb, fd, buf, len, off);
 	} else {
 		off = (off64_t)(lr % stb.st_size);
@@ -2455,7 +2456,8 @@  dwrite_f(int opno, long r)
 	buf = memalign(diob.d_mem, len);
 	off %= maxfsize;
 	lseek64(fd, off, SEEK_SET);
-	memset(buf, nameseq & 0xff, len);
+	/* randomly memset maybe trigger page fault at write time */
+	if (random() / 2) memset(buf, nameseq & 0xff, len);
 	e = write(fd, buf, len) < 0 ? errno : 0;
 	free(buf);
 	if (v)
@@ -3672,7 +3674,8 @@  write_f(int opno, long r)
 	lseek64(fd, off, SEEK_SET);
 	len = (random() % FILELEN_MAX) + 1;
 	buf = malloc(len);
-	memset(buf, nameseq & 0xff, len);
+	/* randomly memset maybe trigger page fault at write time */
+	if (random() / 2) memset(buf, nameseq & 0xff, len);
 	e = write(fd, buf, len) < 0 ? errno : 0;
 	free(buf);
 	if (v)
@@ -3733,7 +3736,8 @@  writev_f(int opno, long r)
 	lseek64(fd, off, SEEK_SET);
 	len = (random() % FILELEN_MAX) + 1;
 	buf = malloc(len);
-	memset(buf, nameseq & 0xff, len);
+	/* randomly memset maybe trigger page fault at write time */
+	if (random() / 2) memset(buf, nameseq & 0xff, len);
 
 	iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
 	iov = malloc(sizeof(struct iovec) * iovcnt);