public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <aelder@sgi.com>
To: xfs@oss.sgi.com
Subject: [PATCH 02/11] xfstests: randholes: only allocate write buffer when needed
Date: Thu, 14 Oct 2010 09:49:52 -0500	[thread overview]
Message-ID: <1287067792.2362.214.camel@doink> (raw)

If nothing is being written (i.e., in "test" mode), there's no need
for "randholes" to allocate a write buffer.  But to do this we make
this series of changes:
- When "very" verbose (> 1), there's no point in printing the values
  that have just been written to the file.  They are just the file
  offset, and the buffer will not have changed between initializing
  those values and writing it out.
- If we don't print the values at those offsets, then there's no
  need to fill them in at all when we're in test mode.
- Now we only use the write buffer if we're not in test mode,
  so we can skip the allocation.

Signed-off-by: Alex Elder <aelder@sgi.com>

---
 src/randholes.c |   45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

Index: b/src/randholes.c
===================================================================
--- a/src/randholes.c
+++ b/src/randholes.c
@@ -233,17 +233,21 @@ writeblks(char *fname, int fd)
 	int block;
 	struct flock64 fl;
 
-	if (direct)
-		buffer = memalign(diob.d_mem, blocksize);
-	else
-		buffer = malloc(blocksize);
-	if (buffer == NULL) {
-		perror("malloc");
-		exit(1);
+	if (test)
+		buffer = NULL;
+	else {
+		if (direct)
+			buffer = memalign(diob.d_mem, blocksize);
+		else
+			buffer = malloc(blocksize);
+		if (buffer == NULL) {
+			perror("malloc");
+			exit(1);
+		}
+		memset(buffer, 0, blocksize);
 	}
-	memset(buffer, 0, blocksize);
 
-	for (  ; count > 0; count--) {
+	do {
 		if (verbose && ((count % 100) == 0)) {
 			printf(".");
 			fflush(stdout);
@@ -285,23 +289,26 @@ bozo!
 			        perror("lseek");
 			        exit(1);
 		        }
-                }
-		*(__uint64_t *)buffer = *(__uint64_t *)(buffer+256) =
-			fileoffset + offset;
-                if (!test) {
+			/*
+			 * Before writing, record offset at the base
+			 * of the buffer and at offset 256 bytes
+			 * into it.  We'll verify this when we read
+			 * it back in again.
+			 */
+			*(__uint64_t *) buffer = fileoffset + offset;
+			*(__uint64_t *) (buffer + 256) = fileoffset + offset;
+
 		        if (write(fd, buffer, blocksize) < blocksize) {
 			        perror("write");
 			        exit(1);
 		        }
                 }
-                if (test && verbose>1) printf("NOT ");
 		if (verbose > 1) {
-			printf("writing data at offset=%llx, value 0x%llx and 0x%llx\n",
-			       (unsigned long long)(fileoffset + offset),
-			       *(unsigned long long *)buffer,
-			       *(unsigned long long *)(buffer+256));
+			printf("%swriting data at offset=%llx\n",
+				test ? "NOT " : "",
+				(unsigned long long) (fileoffset + offset));
 		}
-	}
+	} while (--count);
 
 	free(buffer);
 }


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

                 reply	other threads:[~2010-10-14 14:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1287067792.2362.214.camel@doink \
    --to=aelder@sgi.com \
    --cc=xfs@oss.sgi.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