Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp264113ybm; Tue, 26 May 2020 16:21:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzW5OgogqtdUX+nT4mDvPQWQQppxztfgRDkyFfrdkkLutFEE6h2V3i2Mhz3Gh8llnZrEAcZ X-Received: by 2002:a17:906:4d0d:: with SMTP id r13mr3380142eju.282.1590535294717; Tue, 26 May 2020 16:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590535294; cv=none; d=google.com; s=arc-20160816; b=fot3jggA4E7uZy6M7dsWyC9o3aRM3TPKVOo+50+25AzFaQV8gedLpauLXCxPHfRVUO cIB3GqYCtZfWU0uOxRcGu0PYyJMLbQNemkyMTW4GhkcdFSthH0BpkPsxGSgSQB16xz7Q Xf4i6yiNfsMZ0+sS7hAEwDEPHHuwgAvbHYHPmDnSxIqSk4d4CuNNhOQJwn6he0Nxoczb jIrNTcQElyCZF2Cf7xbKcHvNjAVp9LQ6LACS0xmIcpqCw+NgD14iKYcykXbyqHf9ByzE 54U1ctusMJKQykdVbGEz1V6WFCTR0PlEthxeoeGsJnXl+WjuAtD/xbFmwOk6EM7wiKlO 4s0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ooHBrOZD/3Y3JOqiI+j5WGnGx9rNLKp4UPlTrA3k0fA=; b=CW9JNM+9oC4bq3pmE2y/Cz71V0RcNqJ4sOZcioUB5ALeJCTW9ezb2vqVaMRJBXFNCw MNYvLEPkZVO4uWgC9YOcClE9s3ECJLNK3B3pH+sd6mHc0xVj7jQyIZnd0a43OtirUERh 7mdcwzXDM8Y5xiLugKEOhlVyKyPpJYI39t1IRRKbabyyQBPvSlaIdW4iBRM4a7vLsbkl OR4piFV1lRXEg059FchcV1al39IxxW4bfTjygi8tuWNGelguUkyPQVzdmlEGXD1YeEI2 SR9i+KsMMxUGhj27CxQDdtmCG0kylwZ9vutbNABITJkxCA7SaAWklWXxR/s9wExkzb/y +yXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=bmGfUVJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx14si756348ejb.442.2020.05.26.16.21.12; Tue, 26 May 2020 16:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=bmGfUVJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389176AbgEZTvi (ORCPT + 99 others); Tue, 26 May 2020 15:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389183AbgEZTvf (ORCPT ); Tue, 26 May 2020 15:51:35 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A499C03E96D for ; Tue, 26 May 2020 12:51:34 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id l73so276622pjb.1 for ; Tue, 26 May 2020 12:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ooHBrOZD/3Y3JOqiI+j5WGnGx9rNLKp4UPlTrA3k0fA=; b=bmGfUVJWYu6f/+lClc0yvwBvsEefc8SiuJxE38gUHmvCG67ZCMQ1ZoFC93WjnhwWQ4 yZg7fQlvm/Sucx7ncKy3qvV98rMGm86zWQnvA8hq14lOsPQmzOry1k+ft5gveL4FUJQL gaUBcnu8T8B55uU9BUZgRqOrmN0p82G3CTFOtVxJUrhxYK5Gn/8JEk4HKkHRhEAIvpxF 8iJj/6xBx4Ipgxa4B/+4ClHWKS0rVZdsYpFYzgcgIZxh9GvRIk8QENgpCADWhtcWb7U6 btJvYpMYxIv2afcSGCvbCXlq8oQ8SvKxQmlD9hcdrFZzniK3vSqmkl4k4ZoCvIJr0Avu Vabw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ooHBrOZD/3Y3JOqiI+j5WGnGx9rNLKp4UPlTrA3k0fA=; b=Ni/OzHWhYQBTkejEgS1IFY/Y8NWt8DS8dEwP3U3RaCgoT7NFWJ2wabpS5MOEnbILfF 9ZXTd3De0chQBhQ8JFOtIcvQbHr6bANTqMpxq7bhdP7kOhZnrpVxJsuiRTxviTJ3nqvH +As8eatFSRH2jN+TQOVL8rIYRCwG2oC1879r4+6egTZb+UWIxw55b0mGEaGxHJ6dO27f kgXTMiGG+8UUUkNLwlDjfzq38IFiHmFc87AxU0DOXhOgRp+lqyoCbuCnndQ+a/SB9iau IEANWgXcQ2Cfwkj2pmYKyrVY5ufwRyYsz/ZmzzYVaAgVExSfVBEdDDE/+G/+YeQNyKH2 MbpQ== X-Gm-Message-State: AOAM532mmNdxyDo9XBs96MvXlXu7gOJQm68yYuQ9xeSLE7gUqs7/8AeX /zZMzgSQ0dQOyI0BmxKgsVcfng== X-Received: by 2002:a17:902:b110:: with SMTP id q16mr1318137plr.221.1590522693552; Tue, 26 May 2020 12:51:33 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:94bb:59d2:caf6:70e1]) by smtp.gmail.com with ESMTPSA id c184sm313943pfc.57.2020.05.26.12.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 12:51:33 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 05/12] mm: support async buffered reads in generic_file_buffered_read() Date: Tue, 26 May 2020 13:51:16 -0600 Message-Id: <20200526195123.29053-6-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526195123.29053-1-axboe@kernel.dk> References: <20200526195123.29053-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- mm/filemap.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index c746541b1d49..18022de7dc33 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->ki_waitq); + } else { + if (iocb->ki_flags & IOCB_NOWAIT) { + put_page(page); + goto would_block; + } + error = wait_on_page_locked_killable(page); + } if (unlikely(error)) goto readpage_error; if (PageUptodate(page)) @@ -2156,7 +2172,10 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, page_not_up_to_date: /* Get exclusive access to the page ... */ - error = lock_page_killable(page); + if (iocb->ki_flags & IOCB_WAITQ) + error = lock_page_async(page, iocb->ki_waitq); + else + error = lock_page_killable(page); if (unlikely(error)) goto readpage_error; -- 2.26.2