RE: [PATCH] fs/select.c: batch user writes in do_sys_poll

From: David Laight
Date: Thu Aug 13 2020 - 05:01:54 EST


From: Christoph Hellwig
> Sent: 13 August 2020 08:32
>
> On Thu, Aug 13, 2020 at 05:11:20PM +1000, Daniel Axtens wrote:
> > When returning results to userspace, do_sys_poll repeatedly calls
> > put_user() - once per fd that it's watching.
> >
> > This means that on architectures that support some form of
> > kernel-to-userspace access protection, we end up enabling and disabling
> > access once for each file descripter we're watching. This is inefficent
> > and we can improve things by batching the accesses together.
> >
> > To make sure there's not too much happening in the window when user
> > accesses are permitted, we don't walk the linked list with accesses on.
> > This leads to some slightly messy code in the loop, unfortunately.
> >
> > Unscientific benchmarking with the poll2_threads microbenchmark from
> > will-it-scale, run as `./poll2_threads -t 1 -s 15`:
> >
> > - Bare-metal Power9 with KUAP: ~48.8% speed-up
> > - VM on amd64 laptop with SMAP: ~25.5% speed-up
> >
> > Signed-off-by: Daniel Axtens <dja@xxxxxxxxxx>
>
> Seem like this could simply use a copy_to_user to further simplify
> things?

That would copy out 8 bytes/fd instead of 2.
So a slight change for 32bit kernels.
However the 'user copy hardening' checks that copy_to_user()
does probably make a measurable difference.

> Also please don't pointlessly add overly long lines.

Shorten the error label?

David

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