[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a2ad7401f76645648861563d51122798@AcuMS.aculab.com>
Date: Fri, 15 Sep 2023 13:08:40 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'David Howells' <dhowells@...hat.com>
CC: Al Viro <viro@...iv.linux.org.uk>, Linus Torvalds
<torvalds@...ux-foundation.org>, Jens Axboe <axboe@...nel.dk>, "Christoph
Hellwig" <hch@....de>, Christian Brauner <christian@...uner.io>, "Matthew
Wilcox" <willy@...radead.org>, Brendan Higgins <brendanhiggins@...gle.com>,
David Gow <davidgow@...gle.com>, "linux-fsdevel@...r.kernel.org"
<linux-fsdevel@...r.kernel.org>, "linux-block@...r.kernel.org"
<linux-block@...r.kernel.org>, "linux-mm@...ck.org" <linux-mm@...ck.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
"kunit-dev@...glegroups.com" <kunit-dev@...glegroups.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Andrew Morton
<akpm@...ux-foundation.org>, Christian Brauner <brauner@...nel.org>, "David
Hildenbrand" <david@...hat.com>, John Hubbard <jhubbard@...dia.com>
Subject: RE: [RFC PATCH 9/9] iov_iter: Add benchmarking kunit tests for
UBUF/IOVEC
From: David Howells
> Sent: 15 September 2023 13:36
>
> David Laight <David.Laight@...LAB.COM> wrote:
>
> > I was thinking of import_iovec() - or whatever its current
> > name is.
>
> That doesn't actually access the buffer described by the iovec[].
>
> > That really needs a single structure that contains the iov_iter
> > and the cache[] (which the caller pretty much always allocates
> > in the same place).
>
> cache[]?
Ah it is usually called iovstack[].
That is the code that reads the iovec[] from user.
For small counts there is an on-stack cache[], for large
counts it has call kmalloc().
So when the io completes you have to free the allocated buffer.
A canonical example is:
static ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
unsigned long vlen, loff_t *pos, rwf_t flags)
{
struct iovec iovstack[UIO_FASTIOV];
struct iovec *iov = iovstack;
struct iov_iter iter;
ssize_t ret;
ret = import_iovec(ITER_DEST, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter);
if (ret >= 0) {
ret = do_iter_read(file, &iter, pos, flags);
kfree(iov);
}
return ret;
}
If 'iter' and 'iovstack' are put together in a structure the
calling sequence becomes much less annoying.
The kfree() can (probably) check iter.iovec != iovsatack (as an inline).
But io_uring manages to allocate the iov_iter and iovstack[] in
entirely different places - and then copies them about.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists