2022-05-20 22:37:07

by David Laight

[permalink] [raw]
Subject: RE: [PATCH] fs: prefer read_iter over read and write_iter over write

From: Jason A. Donenfeld
> Sent: 20 May 2022 22:31
>
> Hi David,
>
> On Fri, May 20, 2022 at 09:24:50PM +0000, David Laight wrote:
> > From: Jason A. Donenfeld
> > > Sent: 20 May 2022 14:51
> > >
> > > Most kernel code prefers read_iter over read and write_iter over write,
> > > yet the read function pointer is tested first. Reverse these so that the
> > > iter function is always used first.
> >
> > There will be a measurable performance hit for the xxx_iter versions.
>
> Indeed. We now have the misfortune of a 3% hit on random.c, per this
> sub-thread:

I wrote that a few hours ago and forgot to send it :-(

> https://lore.kernel.org/lkml/[email protected]/
>
> The hope is that it eventually becomes faster... :-\

I suspect all the xxx_iter functions need optimising for
the common case of a single buffer in userspace.

That also includes the code to read the iov[] from usespace.
At the moment I think the 32bit compat code is actually
faster than the native amd64 version!
I've written some patches to speed that up.
But the bigger improvements all hit massive changes
to the ioring code.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


2022-05-23 06:45:53

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] fs: prefer read_iter over read and write_iter over write

On 5/20/22 4:08 PM, David Laight wrote:
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> The hope is that it eventually becomes faster... :-\
>
> I suspect all the xxx_iter functions need optimising for
> the common case of a single buffer in userspace.
>
> That also includes the code to read the iov[] from usespace.
> At the moment I think the 32bit compat code is actually
> faster than the native amd64 version!
> I've written some patches to speed that up.
> But the bigger improvements all hit massive changes
> to the ioring code.

Do you have a link to those patches? I can certainly help with the
io_uring side of things, and I have a genuine interest in improving the
core and getting the iter side up to snuff.

--
Jens Axboe


2022-05-23 08:50:29

by David Laight

[permalink] [raw]
Subject: RE: [PATCH] fs: prefer read_iter over read and write_iter over write

From: Jens Axboe
> Sent: 20 May 2022 23:18
>
> On 5/20/22 4:08 PM, David Laight wrote:
> >> https://lore.kernel.org/lkml/[email protected]/
> >>
> >> The hope is that it eventually becomes faster... :-\
> >
> > I suspect all the xxx_iter functions need optimising for
> > the common case of a single buffer in userspace.
> >
> > That also includes the code to read the iov[] from usespace.
> > At the moment I think the 32bit compat code is actually
> > faster than the native amd64 version!
> > I've written some patches to speed that up.
> > But the bigger improvements all hit massive changes
> > to the ioring code.
>
> Do you have a link to those patches? I can certainly help with the
> io_uring side of things, and I have a genuine interest in improving the
> core and getting the iter side up to snuff.

I'll see if I can find them.
Some bits of the last patch set did get applied.

One aim was to change all the callers of import_iovec()
to use a structure than contained both the 'iov_iter' and
the 'iovstack[]'.
The lifetimes of the two structures are effectively identical.
usually they are both allocated on stack together.

Merging them would significantly simplify the callers
and reduce the number of parameters passed through
multiple layers of functions - especially pointers
passed by value.

That change needs work done to the io_uring code to sanitise
the way it uses the iovstack[] cache and any extended kmalloc()ed
copy.

I need to look elsewhere for the optimisation to import_iovec()
itself.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)