lkml.org 
[lkml]   [2020]   [May]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 05/12] mm: support async buffered reads in generic_file_buffered_read()
From
Date
On 5/24/20 8:05 AM, Trond Myklebust wrote:
> On Sat, 2020-05-23 at 12:57 -0600, Jens Axboe wrote:
>> Use the async page locking infrastructure, if IOCB_WAITQ is set in
>> the
>> passed in iocb. The caller must expect an -EIOCBQUEUED return value,
>> which means that IO is started but not done yet. This is similar to
>> how
>> O_DIRECT signals the same operation. Once the callback is received by
>> the caller for IO completion, the caller must retry the operation.
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>> ---
>> mm/filemap.c | 33 ++++++++++++++++++++++++++-------
>> 1 file changed, 26 insertions(+), 7 deletions(-)
>>
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index c746541b1d49..a3b86c9acdc8 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -1219,6 +1219,14 @@ static int __wait_on_page_locked_async(struct
>> page *page,
>> return ret;
>> }
>>
>> +static int wait_on_page_locked_async(struct page *page,
>> + struct wait_page_queue *wait)
>> +{
>> + if (!PageLocked(page))
>> + return 0;
>> + return __wait_on_page_locked_async(compound_head(page), wait,
>> false);
>> +}
>> +
>> /**
>> * put_and_wait_on_page_locked - Drop a reference and wait for it to
>> be unlocked
>> * @page: The page to wait for.
>> @@ -2058,17 +2066,25 @@ static ssize_t
>> generic_file_buffered_read(struct kiocb *iocb,
>> index, last_index - index);
>> }
>> if (!PageUptodate(page)) {
>> - if (iocb->ki_flags & IOCB_NOWAIT) {
>> - put_page(page);
>> - goto would_block;
>> - }
>> -
>> /*
>> * See comment in do_read_cache_page on why
>> * wait_on_page_locked is used to avoid
>> unnecessarily
>> * serialisations and why it's safe.
>> */
>> - error = wait_on_page_locked_killable(page);
>> + if (iocb->ki_flags & IOCB_WAITQ) {
>> + if (written) {
>> + put_page(page);
>> + goto out;
>> + }
>> + error = wait_on_page_locked_async(page,
>> + iocb-
>>> private);
>
> If it is being used in 'generic_file_buffered_read()' as storage for a
> wait queue, then it is hard to consider this a 'private' field.

private isn't the prettiest, and in fact this one in particular is a bit
of a mess. It's not clear if it's caller or callee owned. It's generally
not used, outside of the old usb gadget code, iomap O_DIRECT, and ocfs2.
With FMODE_BUF_RASYNC, the fs obviously can't set it if it uses
->private for buffered IO.

> Perhaps either rename and add type checking, or else add a separate
> field altogether to struct kiocb?

I'd hate to add a new field and increase the size of the kiocb... One
alternative is to do:

union {
void *private;
struct wait_page_queue *ki_waitq;
};

and still use IOCB_WAITQ to say that ->ki_waitq is valid.

There's also 4 bytes of padding in the kiocb struct. And some fields are
only used for O_DIRECT as well, eg ->ki_cookie which is just used for
polled O_DIRECT. So we could also do:

union {
unsigned int ki_cookie;
struct wait_page_queue *ki_waitq;
};

and still not grow the kiocb. How about we go with this approach, and
also add:

if (kiocb->ki_flags & IOCB_HIPRI)
return -EOPNOTSUPP;

to kiocb_wait_page_queue_init() to make sure that this combination isn't
valid?

--
Jens Axboe

\
 
 \ /
  Last update: 2020-05-24 18:31    [W:0.086 / U:8.724 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site