Re: Expense of read_iter

From: Matthew Wilcox
Date: Sun Jan 10 2021 - 19:19:36 EST


On Sun, Jan 10, 2021 at 04:19:15PM -0500, Mikulas Patocka wrote:
> I put counters into vfs_read and vfs_readv.
>
> After a fresh boot of the virtual machine, the counters show "13385 4".
> After a kernel compilation they show "4475220 8".
>
> So, the readv path is almost unused.
>
> My reasoning was that we should optimize for the "read" path and glue the
> "readv" path on the top of that. Currently, the kernel is doing the
> opposite - optimizing for "readv" and glueing "read" on the top of it.

But it's not about optimising for read vs readv. read_iter handles
a host of other cases, such as pread(), preadv(), AIO reads, splice,
and reads to in-kernel buffers.

Some device drivers abused read() vs readv() to actually return different
information, depending which you called. That's why there's now a
prohibition against both.

So let's figure out how to make iter_read() perform well for sys_read().