Received: by 2002:a25:d80d:0:0:0:0:0 with SMTP id p13csp218609ybg; Sat, 23 May 2020 12:02:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFFQzuVIKsjKl/SEYnIvJHXY6x6I89K/tWhqh3z9BkqniPbNbLvvwvp/bQBieBC9GIYnCo X-Received: by 2002:a05:6402:c10:: with SMTP id co16mr8282362edb.315.1590260542530; Sat, 23 May 2020 12:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590260542; cv=none; d=google.com; s=arc-20160816; b=rdJQtFj5VAudPsphv01Kgz+lptu7j4IhgEH2C76312GEaWUPq8TyjQOs4D0UBr/5GV Hlt78ePMYVPQ87Oi5J+kKBLPsipKTLvoIjUHe5rNkY1gdQo6YTkkyl+d0h8SnmP20zjE AZhYaDheSVM7Rsacfiz6D4Qhf2LbBPh9X8RgTVMOFxITIn0qP6IQprRnl/pxNnuDZMBw 2w4trP87W6lUROLCxcjkJkqhedq3EorU65ZaGoUOyf5He00TWqKH9bx4OQ0fFWga/Sgy IutGDQpp5t4hVSHxXuW7kL7rv8ojp/ZiSNF4cYIZVCz9kHTlM1ZdGKPOI+Vk8AhDHaDO TZzw== 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=QLIKOC51UDi6y8ydZtCT2FsP1dt+ucWxar6wAIDn3TQ=; b=paE6RL3M76gus8eDCpnCivQdHcmjsgRZjsk5ZhOC0Q4TBt0ErIw20O/gN2N0O76QQ9 PzYqITFB5n/D0AEIIYIx/AAkPGcnZnUKY4w4agbaqQa15CJHSAZrwCX+ej6BWntdRM9m IAmiKesGHMlFu7NhXgk0It19ysRfoRqE5p+g0kNdLVqZ3JS//po621M2HJ8vnhEKrlhk 6I/gOSVZeFjhKLGCcrmqUHdKXQi6GguCkd4scJGTJibhd92gvPiLYQRhaARQvJ5xGunt UHtNFm/imS+H0puDYvysRm3HCd437T6hGE8M+jAnUv5oZquhC1tMLEgLDHiaNh6nAlT6 C+hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=MWKaekWv; 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 o19si6439747ejc.483.2020.05.23.12.01.59; Sat, 23 May 2020 12:02:22 -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=MWKaekWv; 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 S2388062AbgEWS6p (ORCPT + 99 others); Sat, 23 May 2020 14:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728688AbgEWS6H (ORCPT ); Sat, 23 May 2020 14:58:07 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 528E1C061A0E for ; Sat, 23 May 2020 11:58:06 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id t11so6591884pgg.2 for ; Sat, 23 May 2020 11:58:06 -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=QLIKOC51UDi6y8ydZtCT2FsP1dt+ucWxar6wAIDn3TQ=; b=MWKaekWvtx+WTMH7SA8TxEwVGEMQRZ6Y3Djw7RNC7oEYUCXetIPXBjtiJgnyF71Y0b UMa3s3nv9VNBNz/E5zE58K6odN5gP1YpWtoRtR26Jtt0hxzlYhRsfCdDXvyf1atMh5bs o3zeYxTrMI80Xwj9+WtyiI7NO1qDg3KQpO4qdC3SwkxvfVqMOsKdB1CW997onc1jjj0s glvIv02sptmvS0nrlsCIZFZqjJuVPnwA32f5p/IDDJg82jymdpaM0DYrJhhfbQg3g/lN 7krBmUvtb5GR2kiVrgRdtyjFenuM4+KBhSnVAZc+Y4QeRkSFLNE8OUmPmx2atAUI+eH/ IZtQ== 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=QLIKOC51UDi6y8ydZtCT2FsP1dt+ucWxar6wAIDn3TQ=; b=U3x26zyWQ/c3OvTRyFjnNBx6l3Pasy/xlYiu9rNjyjB1d+uCZkXa7d2sev+T5/6RuC d6LM7k3IKuWHiGinsYmWGwv11FQRgagCtp3Xl3tw/lyCauTJ6a59fYdI/n7ucISJpkoy mWghxHaQ+dREdUs+6s4N139i7OBOYLDr8+iqapp1sdeqCRIM0bAdCkPm53blbXUPx/L0 wceotz190p6z3+59COtR7l6XLcVZ07fw8/n7bvTSI1UKKVdw4Iu2qnm5/nkn5xHPdh0m 7mnAwQAMuYXg/GmrYt13PoC35HdvpJmW8I8b06yeHsL+rBSCnqfV4+85dOZrVeAvEiKA Rqjw== X-Gm-Message-State: AOAM5329uOGhGWkEmTZz7tK81TwQY12krdCK+9rEm0+p+Wnn6qk9zYQH 0gW4FiSLzH4gykATLmENGduJlw== X-Received: by 2002:a65:66d5:: with SMTP id c21mr18973961pgw.155.1590260285870; Sat, 23 May 2020 11:58:05 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:c94:a67a:9209:cf5f]) by smtp.gmail.com with ESMTPSA id 25sm9297319pjk.50.2020.05.23.11.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2020 11:58:05 -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: Sat, 23 May 2020 12:57:48 -0600 Message-Id: <20200523185755.8494-6-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200523185755.8494-1-axboe@kernel.dk> References: <20200523185755.8494-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..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); + } 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->private); + else + error = lock_page_killable(page); if (unlikely(error)) goto readpage_error; -- 2.26.2