Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp519171ybs; Sun, 24 May 2020 12:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnSfbTn0lb4gVZEG0qE1z9o+RgqZdIwF/lAKPopZVVi4VQvAln5T2GpoE+xMdZhOpRoAGR X-Received: by 2002:a17:906:b31a:: with SMTP id n26mr15699297ejz.441.1590348433691; Sun, 24 May 2020 12:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590348433; cv=none; d=google.com; s=arc-20160816; b=rszlzTVWsSMr/UkT/oFm9WNAgEpCtpn7Ux0y81PmvA2alVLnjhWnCrcoOCt4dK+n0r BWhHt9ok5ahpvlVSIlkXG1e0VYa/nHQwCEal7eWFDCNbxXPLPri5sUyyDUJwn1D4bKLB nX8Ze6aHzIyd25lqTzy6jvuHqZD/gNB9kDdx25hA4KXf78TMuJQaqUaffhZ7usjJATY7 qesTP0/TnobEFpPpcfDYJCwFVTfd06QXH/1C0CIyImqimtf7c5LxbuwVyLFWLOvBIA/s Ku3yI6gZYq0TNFAv5Zj9Tvm35xQG4lFeGcMGc3kcRrES8y6tRi41adXZdMPn5GkV4Ky9 wnJg== 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=mmowDPCWP1Mz3nQuWmn2FV0o0QoC9Kst4NFsH9GHT03sxQJD4zEffctf5MPEloWUzE yrmbpWLARxD6XC4cjXXX7BC5XcFGmITEeoiWoLrKyJTHHsrmGiNrWYn0Y911QjKBriku N9xkv/PSdTCzmRN2GAr3hPix7Z5v+yDlJ4Y++buUWfp6lpzx+Ae/Vo+r1qZlih3lnaP1 XR9RFuYl0i3xBIHEbp+LqjysDJS9M5r1hocj/onl6/gUUDWk7cepmeayMZTC/XBalSnr uGLNo+gjND9jpAKj4Nldb+MFAzynUePXkElyMKme4qoRcOuiSKR773eOWQynjZWYCSFz /Eng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=OxFpYtFB; 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 bo6si8074542edb.586.2020.05.24.12.26.51; Sun, 24 May 2020 12:27:13 -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=OxFpYtFB; 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 S2388193AbgEXTWW (ORCPT + 99 others); Sun, 24 May 2020 15:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388144AbgEXTWV (ORCPT ); Sun, 24 May 2020 15:22:21 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED032C08C5C3 for ; Sun, 24 May 2020 12:22:19 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id u5so7784714pgn.5 for ; Sun, 24 May 2020 12:22:19 -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=OxFpYtFBwzHltasPWMU+lcpGv4rU/W2vOx/T4krzJTwDePkK92WnP8Q9D4KmLLpY6f Gd2powlWYp6amNjj/pqEmErKe4G4P2gbejJam6uJcPC941s8l3j4LkrKcWofDhf2REGi YTJZ81xesGaQk5qxaVPuAbcllAJUCMysF5nbqjuG4CmorTuNG9vIpk0d1uNk8acf8Rff 1jlX4yGiljx2GdZ16Qma2k/cZGqRuC3kacJw2yDCzjvloXbodfZK/edA2Q6I/0OGROAn 1nP5uZaH7v6Ns2RKRSS6SiYvJFi0QZwo9hTw2Aqe4//xgAmUbZgp7F+hMebtqROV82zc 2Wlw== 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=hmAqYKAd1WTqamdBFRMUk3t1rnlZT3LetRSOc10RO26CbCPFirmiKl6j6qTwU52yqQ AEo+TPHxbOxlVMVYvSov9e8Sk/qeQxSuF533vaWPKxToPm/h+MrjCQjhcDtLR7BwKtCq 107XpSX4qgssUhuzgeNqejpQftXzonQHaMo0lnXKiyc9xzrKdJUaNNBDDGyP7sU8im1b xGJ2opRkBzKydjN8oLqSHHXQzPxYy001p1cj2dW31j2kZSxgdnqaGYNxP8tQnvcYic9f 3AkL90Oq4SzyvgLZJPOGMP7Qbcpp/euXh/sSfksOUk+iQcrgQSvR1l6JIUlJnxNmCsoY V7/g== X-Gm-Message-State: AOAM532pvn6VXJdkYzPLgjoWYdKqztGj4jTQSz+vQJn/KMXe9C46AJI3 v3oNx5aNRlmO2mpGfPLuIX6XMA== X-Received: by 2002:a63:381c:: with SMTP id f28mr22576826pga.361.1590348139455; Sun, 24 May 2020 12:22:19 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:c871:e701:52fa:2107]) by smtp.gmail.com with ESMTPSA id t21sm10312426pgu.39.2020.05.24.12.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 12:22:18 -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, Jens Axboe Subject: [PATCH 05/12] mm: support async buffered reads in generic_file_buffered_read() Date: Sun, 24 May 2020 13:21:59 -0600 Message-Id: <20200524192206.4093-6-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200524192206.4093-1-axboe@kernel.dk> References: <20200524192206.4093-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