public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_io: fix random pread/pwrite to honor offset
@ 2014-04-09 19:15 Eric Sandeen
  2014-04-09 20:48 ` Mark Tinguely
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sandeen @ 2014-04-09 19:15 UTC (permalink / raw)
  To: xfs-oss

xfs_io's pread & pwrite claim to support a random IO mode
where it will do random IOs between offset & offset+len.

However, offset was ignored, and we did the IOs between 0
and len instead.

Clang caught this by pointing out that the calculated/normalized
"offset" variable was never read.

(NB: If the range is larger than RAND_MAX, these functions don't
work, but that's always been true, so I'll leave it for another
day...)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

I haven't tested this w/ xfstests but I don't see anyone who calls
pread/pwrite with "-R" (and it's not documented in the manpage!)

diff --git a/io/pread.c b/io/pread.c
index a42baed..465c22b 100644
--- a/io/pread.c
+++ b/io/pread.c
@@ -246,7 +246,7 @@ read_random(
 
 	*total = 0;
 	while (count > 0) {
-		off = ((random() % range) / buffersize) * buffersize;
+		off = ((offset + (random() % range)) / buffersize) * buffersize;
 		bytes = do_pread(fd, off, buffersize, buffersize);
 		if (bytes == 0)
 			break;
diff --git a/io/pwrite.c b/io/pwrite.c
index a2f0a81..f8a0b1e 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -129,7 +129,7 @@ write_random(
 
 	*total = 0;
 	while (count > 0) {
-		off = ((random() % range) / buffersize) * buffersize;
+		off = ((offset + (random() % range)) / buffersize) * buffersize;
 		bytes = do_pwrite(file->fd, off, buffersize, buffersize);
 		if (bytes == 0)
 			break;

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs_io: fix random pread/pwrite to honor offset
  2014-04-09 19:15 [PATCH] xfs_io: fix random pread/pwrite to honor offset Eric Sandeen
@ 2014-04-09 20:48 ` Mark Tinguely
  2014-04-09 20:55   ` Eric Sandeen
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Tinguely @ 2014-04-09 20:48 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs-oss

On 04/09/14 14:15, Eric Sandeen wrote:
> xfs_io's pread & pwrite claim to support a random IO mode
> where it will do random IOs between offset & offset+len.
>
> However, offset was ignored, and we did the IOs between 0
> and len instead.
>
> Clang caught this by pointing out that the calculated/normalized
> "offset" variable was never read.
>
> (NB: If the range is larger than RAND_MAX, these functions don't
> work, but that's always been true, so I'll leave it for another
> day...)
>
> Signed-off-by: Eric Sandeen<sandeen@redhat.com>
> ---
>
> I haven't tested this w/ xfstests but I don't see anyone who calls
> pread/pwrite with "-R" (and it's not documented in the manpage!)
>
> diff --git a/io/pread.c b/io/pread.c
> index a42baed..465c22b 100644
> --- a/io/pread.c
> +++ b/io/pread.c
> @@ -246,7 +246,7 @@ read_random(

offset can be the end of file offset. Do we care that the read (/write)
could start or end past the end of file?

>
>   	*total = 0;
>   	while (count > 0) {
> -		off = ((random() % range) / buffersize) * buffersize;
> +		off = ((offset + (random() % range)) / buffersize) * buffersize;
>   		bytes = do_pread(fd, off, buffersize, buffersize);
>   		if (bytes == 0)
>   			break;

Looks like this was introduced in:
commit 8fb2237e65555ff540e8b6108ffccfffefe239ac
Author: Nathan Scott <nathans@sgi.com>
Date:   Fri Nov 11 14:25:18 2005 +0000

Provide further debugging options and tweaks for analysing the 
read/write paths.
Merge of master-melb:xfs-cmds:24372a by kenmcd.

  ---

If it was broken for 8.5 years, I think it could be removed.

--Mark.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs_io: fix random pread/pwrite to honor offset
  2014-04-09 20:48 ` Mark Tinguely
@ 2014-04-09 20:55   ` Eric Sandeen
  2014-04-11  4:48     ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sandeen @ 2014-04-09 20:55 UTC (permalink / raw)
  To: Mark Tinguely; +Cc: xfs-oss

On 4/9/14, 3:48 PM, Mark Tinguely wrote:
> On 04/09/14 14:15, Eric Sandeen wrote:
>> xfs_io's pread & pwrite claim to support a random IO mode
>> where it will do random IOs between offset & offset+len.
>>
>> However, offset was ignored, and we did the IOs between 0
>> and len instead.
>>
>> Clang caught this by pointing out that the calculated/normalized
>> "offset" variable was never read.
>>
>> (NB: If the range is larger than RAND_MAX, these functions don't
>> work, but that's always been true, so I'll leave it for another
>> day...)
>>
>> Signed-off-by: Eric Sandeen<sandeen@redhat.com>
>> ---
>>
>> I haven't tested this w/ xfstests but I don't see anyone who calls
>> pread/pwrite with "-R" (and it's not documented in the manpage!)
>>
>> diff --git a/io/pread.c b/io/pread.c
>> index a42baed..465c22b 100644
>> --- a/io/pread.c
>> +++ b/io/pread.c
>> @@ -246,7 +246,7 @@ read_random(
> 
> offset can be the end of file offset. Do we care that the read (/write)
> could start or end past the end of file?

It now behaves the same as a normal forward read does if you tell it
to go past EOF:

xfs_io> truncate 1g
xfs_io> pread 1g 1m
read 0/1048576 bytes at offset 1073741824
0.000000 bytes, 0 ops; 0.0000 sec (0.000000 bytes/sec and 0.0000 ops/sec)
xfs_io> pread -R 1g 1m
read 0/1048576 bytes at offset 1073741824
0.000000 bytes, 0 ops; 0.0000 sec (0.000000 bytes/sec and 0.0000 ops/sec)

so I think it's ok?

>>
>>       *total = 0;
>>       while (count > 0) {
>> -        off = ((random() % range) / buffersize) * buffersize;
>> +        off = ((offset + (random() % range)) / buffersize) * buffersize;
>>           bytes = do_pread(fd, off, buffersize, buffersize);
>>           if (bytes == 0)
>>               break;
> 
> Looks like this was introduced in:
> commit 8fb2237e65555ff540e8b6108ffccfffefe239ac
> Author: Nathan Scott <nathans@sgi.com>
> Date:   Fri Nov 11 14:25:18 2005 +0000
> 
> Provide further debugging options and tweaks for analysing the read/write paths.
> Merge of master-melb:xfs-cmds:24372a by kenmcd.
> 
>  ---
> 
> If it was broken for 8.5 years, I think it could be removed.

Eh, could, or we could fix it.  :)  I suppose this means it needs a test... :/

-Eric

> --Mark.
> 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xfs_io: fix random pread/pwrite to honor offset
  2014-04-09 20:55   ` Eric Sandeen
@ 2014-04-11  4:48     ` Dave Chinner
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Chinner @ 2014-04-11  4:48 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Mark Tinguely, xfs-oss

On Wed, Apr 09, 2014 at 03:55:09PM -0500, Eric Sandeen wrote:
> On 4/9/14, 3:48 PM, Mark Tinguely wrote:
> > On 04/09/14 14:15, Eric Sandeen wrote:
> >> xfs_io's pread & pwrite claim to support a random IO mode
> >> where it will do random IOs between offset & offset+len.
> >>
> >> However, offset was ignored, and we did the IOs between 0
> >> and len instead.
> >>
> >> Clang caught this by pointing out that the calculated/normalized
> >> "offset" variable was never read.
> >>
> >> (NB: If the range is larger than RAND_MAX, these functions don't
> >> work, but that's always been true, so I'll leave it for another
> >> day...)
> >>
> >> Signed-off-by: Eric Sandeen<sandeen@redhat.com>
> >> ---
....
> > 
> > Looks like this was introduced in:
> > commit 8fb2237e65555ff540e8b6108ffccfffefe239ac
> > Author: Nathan Scott <nathans@sgi.com>
> > Date:   Fri Nov 11 14:25:18 2005 +0000
> > 
> > Provide further debugging options and tweaks for analysing the read/write paths.
> > Merge of master-melb:xfs-cmds:24372a by kenmcd.
> > 
> >  ---
> > 
> > If it was broken for 8.5 years, I think it could be removed.
> 
> Eh, could, or we could fix it.  :)  I suppose this means it needs a test... :/

And document it ;)

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-11  4:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-09 19:15 [PATCH] xfs_io: fix random pread/pwrite to honor offset Eric Sandeen
2014-04-09 20:48 ` Mark Tinguely
2014-04-09 20:55   ` Eric Sandeen
2014-04-11  4:48     ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox