From patchwork Fri Nov 22 23:53:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11258673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1637113A4 for ; Fri, 22 Nov 2019 23:53:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D5F2B20637 for ; Fri, 22 Nov 2019 23:53:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EuBBMcP3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5F2B20637 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D84756B052D; Fri, 22 Nov 2019 18:53:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D34746B052E; Fri, 22 Nov 2019 18:53:43 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C722D6B052F; Fri, 22 Nov 2019 18:53:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id B3D576B052D for ; Fri, 22 Nov 2019 18:53:43 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 654735832 for ; Fri, 22 Nov 2019 23:53:43 +0000 (UTC) X-FDA: 76185568326.23.foot27_77b790d85124e X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,agruenba@redhat.com,:torvalds@linux-foundation.org:swhiteho@redhat.com:khlebnikov@yandex-team.ru:kirill@shutemov.name::akpm@linux-foundation.org:linux-kernel@vger.kernel.org:linux-fsdevel@vger.kernel.org:viro@zeniv.linux.org.uk:hannes@cmpxchg.org:cluster-devel@redhat.com:lsahlber@redhat.com:sfrench@samba.org:rpeterso@redhat.com:agruenba@redhat.com,RULES_HIT:30012:30034:30054,0,RBL:207.211.31.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:30,LUA_SUMMARY:none X-HE-Tag: foot27_77b790d85124e X-Filterd-Recvd-Size: 6061 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 23:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574466821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rvAGjXKzggaIcjor/eU/2AoEyqgwEZJGtnOKutcJ+6k=; b=EuBBMcP3R9KIehvnddA7lDPlfznXcpOCwY1T4dFsmK56aSaOB9pme7DAMJiwx7Y1ZOyHnr jdL/ewlnEgAN745LCCd55cp5c/OSItcY4y6oVwQ4NYnswvjkUxHw3wrdkriiWo1hITJXi/ /obLBqa2cs9XyUyOWp0nidt88QRviIw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-ZgnG4BKfPseZDtuQScqjhQ-1; Fri, 22 Nov 2019 18:53:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73D761005509; Fri, 22 Nov 2019 23:53:38 +0000 (UTC) Received: from max.com (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E21FE5C1BB; Fri, 22 Nov 2019 23:53:34 +0000 (UTC) From: Andreas Gruenbacher To: Linus Torvalds Cc: Steven Whitehouse , Konstantin Khlebnikov , "Kirill A. Shutemov" , linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexander Viro , Johannes Weiner , cluster-devel@redhat.com, Ronnie Sahlberg , Steve French , Bob Peterson , Andreas Gruenbacher Subject: [RFC PATCH 1/3] fs: Add IOCB_CACHED flag for generic_file_read_iter Date: Sat, 23 Nov 2019 00:53:22 +0100 Message-Id: <20191122235324.17245-2-agruenba@redhat.com> In-Reply-To: <20191122235324.17245-1-agruenba@redhat.com> References: <20191122235324.17245-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: ZgnG4BKfPseZDtuQScqjhQ-1 X-Mimecast-Spam-Score: 0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add an IOCB_CACHED flag which indicates to generic_file_read_iter that it should only look at the page cache, without triggering any filesystem I/O for the actual request or for readahead. When filesystem I/O would be triggered, an error code should be returned instead. This allows the caller to perform a tentative read out of the page cache, and to retry the read after taking the necessary steps when the requested pages are not cached. When readahead would be triggered, we return -ECANCELED instead of -EAGAIN. This allows to distinguish attempted readheads from attempted reads (with IOCB_NOWAIT). Signed-off-by: Andreas Gruenbacher --- include/linux/fs.h | 1 + mm/filemap.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index e0d909d35763..4ca5e2885452 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -314,6 +314,7 @@ enum rw_hint { #define IOCB_SYNC (1 << 5) #define IOCB_WRITE (1 << 6) #define IOCB_NOWAIT (1 << 7) +#define IOCB_CACHED (1 << 8) struct kiocb { struct file *ki_filp; diff --git a/mm/filemap.c b/mm/filemap.c index 85b7d087eb45..024ff0b5fcb6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2046,7 +2046,7 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, page = find_get_page(mapping, index); if (!page) { - if (iocb->ki_flags & IOCB_NOWAIT) + if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_CACHED)) goto would_block; page_cache_sync_readahead(mapping, ra, filp, @@ -2056,12 +2056,16 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, goto no_cached_page; } if (PageReadahead(page)) { + if (iocb->ki_flags & IOCB_CACHED) { + error = -ECANCELED; + goto out; + } page_cache_async_readahead(mapping, ra, filp, page, index, last_index - index); } if (!PageUptodate(page)) { - if (iocb->ki_flags & IOCB_NOWAIT) { + if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_CACHED)) { put_page(page); goto would_block; } @@ -2266,6 +2270,13 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, * * This is the "read_iter()" routine for all filesystems * that can use the page cache directly. + * + * In the IOCB_NOWAIT flag in iocb->ki_flags indicates that -EAGAIN should be + * returned if completing the request would require I/O; this does not prevent + * readahead. The IOCB_CACHED flag indicates that -EAGAIN should be returned + * as under the IOCB_NOWAIT flag, and that -ECANCELED should be returned when + * readhead would be triggered. + * * Return: * * number of bytes copied, even for partial reads * * negative error code if nothing was read @@ -2286,7 +2297,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) loff_t size; size = i_size_read(inode); - if (iocb->ki_flags & IOCB_NOWAIT) { + if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_CACHED)) { if (filemap_range_has_page(mapping, iocb->ki_pos, iocb->ki_pos + count - 1)) return -EAGAIN;