From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6FCC2D0C7 for ; Wed, 11 Dec 2019 15:30:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8650F22B48 for ; Wed, 11 Dec 2019 15:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="qxq/32r1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8650F22B48 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA4B46B32A1; Wed, 11 Dec 2019 10:29:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E55B86B32A2; Wed, 11 Dec 2019 10:29:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6D306B32A3; Wed, 11 Dec 2019 10:29:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id BCE486B32A1 for ; Wed, 11 Dec 2019 10:29:59 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 6BD37499619 for ; Wed, 11 Dec 2019 15:29:59 +0000 (UTC) X-FDA: 76253246118.14.fish14_1cef3fd12523c X-HE-Tag: fish14_1cef3fd12523c X-Filterd-Recvd-Size: 8338 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Dec 2019 15:29:58 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id y14so1959426pfm.13 for ; Wed, 11 Dec 2019 07:29:58 -0800 (PST) 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=/vezaSQ9/HzyiknN4dL3ceKw9qbj13XNQmUHG7g1Svg=; b=qxq/32r1bbzFPXnnxgC3s691AYktTKm89RQV6YfjmLSwapNX/y30/rnNS/vTpMICw0 E0CpPjbr9qyfHH8Vl8o7gSlUP4m/CdU6oSaUyiDPAqu2pKxY/tFE4d2/t/5szdhZa6xy mgCsrrL7ZmnM+ara0lBgrlaZPAGDiDmSnuNt1hgEMrtv7CBtQsYu+T8Ai5t6KdHnIWQ2 /YGi/E7OpVhs4dbPi3Q+rxMKQKGcaoBx5nEtHSh3+a7dk2Th2Wsz8umkDYyO3/HKGSH7 RlMVSN/2SuKzR1au+4VMWCNbYMJFUDUm3ZZEoqnwhewkuwCRTl/E4hYO/l9U/G04102i jkYA== 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=/vezaSQ9/HzyiknN4dL3ceKw9qbj13XNQmUHG7g1Svg=; b=N6FlYahoarEEwNX+xCxwirKGV6b0i4fHr1oGRkB1jqGg2Ol9DjHpDlKYpZv12FPs+H tzCGSffck9pMlssBc+yLh9ypygY8EzHUekJE0w0yGR0MxElinprdjqMHfZb35WeKMWly 5h96eTKA05R1u04BvYzPQ6Z6u0S036TJMRNsv+JNImfTOClH3S9RJEWW4jjb2qLsT03G yUNt2yPDHjYxA9r3r/rmWA+y9MTRSeIMsWPzKFjNCokrx/OhBdkk2UKhhwgtqeqO211x 5/yqKas3dteCgYqU0rkQLnWc6/gmwb2qh+HrolW+tJOQGL45YJnASR3vaMzhHZpZj0wD i7zw== X-Gm-Message-State: APjAAAVzOxgMsaL0Gx4tkW7+1O6L3VskD3qSdCTht0lyhV0yRU52v4E4 NTWyq52PUEkEsBiL9gr/NReDU1Ygt9U= X-Google-Smtp-Source: APXvYqxhzEn4zXSGLljyGdTPmkM/M2dDixk96VcFJMQAKJxxvd643ce1GydOHXqrtciawN+rEIkbEA== X-Received: by 2002:a63:4e22:: with SMTP id c34mr4738177pgb.214.1576078197199; Wed, 11 Dec 2019 07:29:57 -0800 (PST) Received: from x1.thefacebook.com ([2620:10d:c090:180::50da]) by smtp.gmail.com with ESMTPSA id n26sm3661882pgd.46.2019.12.11.07.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:29:56 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: willy@infradead.org, clm@fb.com, torvalds@linux-foundation.org, david@fromorbit.com, Jens Axboe Subject: [PATCH 5/5] iomap: support RWF_UNCACHED for buffered writes Date: Wed, 11 Dec 2019 08:29:43 -0700 Message-Id: <20191211152943.2933-6-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191211152943.2933-1-axboe@kernel.dk> References: <20191211152943.2933-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: This adds support for RWF_UNCACHED for file systems using iomap to perform buffered writes. We use the generic infrastructure for this, by tracking pages we created and calling write_drop_cached_pages() to issue writeback and prune those pages. Signed-off-by: Jens Axboe --- fs/iomap/apply.c | 24 ++++++++++++++++++++++++ fs/iomap/buffered-io.c | 37 +++++++++++++++++++++++++++++-------- include/linux/iomap.h | 5 +++++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index 562536da8a13..966826ad4bb9 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -90,5 +90,29 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t le= ngth, unsigned flags, flags, &iomap); } =20 + if (written && (flags & IOMAP_UNCACHED)) { + struct address_space *mapping =3D inode->i_mapping; + + end =3D pos + written; + ret =3D filemap_write_and_wait_range(mapping, pos, end); + if (ret) + goto out; + + /* + * No pages were created for this range, we're done + */ + if (!(iomap.flags & IOMAP_F_PAGE_CREATE)) + goto out; + + /* + * Try to invalidate cache pages for the range we just wrote. + * We don't care if invalidation fails as the write has still + * worked and leaving clean uptodate pages in the page cache + * isn't a corruption vector for uncached IO. + */ + invalidate_inode_pages2_range(mapping, + pos >> PAGE_SHIFT, end >> PAGE_SHIFT); + } +out: return written ? written : ret; } diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 9b5b770ca4c7..09440f114506 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -566,6 +566,7 @@ EXPORT_SYMBOL_GPL(iomap_migrate_page); =20 enum { IOMAP_WRITE_F_UNSHARE =3D (1 << 0), + IOMAP_WRITE_F_UNCACHED =3D (1 << 1), }; =20 static void @@ -643,6 +644,7 @@ iomap_write_begin(struct inode *inode, loff_t pos, un= signed len, unsigned flags, struct page **pagep, struct iomap *iomap, struct iomap *srcmap) { const struct iomap_page_ops *page_ops =3D iomap->page_ops; + unsigned aop_flags; struct page *page; int status =3D 0; =20 @@ -659,8 +661,11 @@ iomap_write_begin(struct inode *inode, loff_t pos, u= nsigned len, unsigned flags, return status; } =20 + aop_flags =3D AOP_FLAG_NOFS; + if (flags & IOMAP_UNCACHED) + aop_flags |=3D AOP_FLAG_UNCACHED; page =3D grab_cache_page_write_begin(inode->i_mapping, pos >> PAGE_SHIF= T, - AOP_FLAG_NOFS); + aop_flags); if (!page) { status =3D -ENOMEM; goto out_no_page; @@ -670,9 +675,14 @@ iomap_write_begin(struct inode *inode, loff_t pos, u= nsigned len, unsigned flags, iomap_read_inline_data(inode, page, srcmap); else if (iomap->flags & IOMAP_F_BUFFER_HEAD) status =3D __block_write_begin_int(page, pos, len, NULL, srcmap); - else - status =3D __iomap_write_begin(inode, pos, len, flags, page, + else { + unsigned wb_flags =3D 0; + + if (flags & IOMAP_UNCACHED) + wb_flags =3D IOMAP_WRITE_F_UNCACHED; + status =3D __iomap_write_begin(inode, pos, len, wb_flags, page, srcmap); + } =20 if (unlikely(status)) goto out_unlock; @@ -832,10 +842,17 @@ iomap_write_actor(struct inode *inode, loff_t pos, = loff_t length, void *data, break; } =20 - status =3D iomap_write_begin(inode, pos, bytes, 0, &page, iomap, - srcmap); - if (unlikely(status)) +retry: + status =3D iomap_write_begin(inode, pos, bytes, flags, &page, + iomap, srcmap); + if (unlikely(status)) { + if (status =3D=3D -ENOMEM && (flags & IOMAP_UNCACHED)) { + iomap->flags |=3D IOMAP_F_PAGE_CREATE; + flags &=3D ~IOMAP_UNCACHED; + goto retry; + } break; + } =20 if (mapping_writably_mapped(inode->i_mapping)) flush_dcache_page(page); @@ -882,10 +899,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struc= t iov_iter *iter, { struct inode *inode =3D iocb->ki_filp->f_mapping->host; loff_t pos =3D iocb->ki_pos, ret =3D 0, written =3D 0; + unsigned flags =3D IOMAP_WRITE; + + if (iocb->ki_flags & IOCB_UNCACHED) + flags |=3D IOMAP_UNCACHED; =20 while (iov_iter_count(iter)) { - ret =3D iomap_apply(inode, pos, iov_iter_count(iter), - IOMAP_WRITE, ops, iter, iomap_write_actor); + ret =3D iomap_apply(inode, pos, iov_iter_count(iter), flags, + ops, iter, iomap_write_actor); if (ret <=3D 0) break; pos +=3D ret; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 61fcaa3904d4..b5b5cf781eea 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -48,12 +48,16 @@ struct vm_fault; * * IOMAP_F_BUFFER_HEAD indicates that the file system requires the use o= f * buffer heads for this mapping. + * + * IOMAP_F_PAGE_CREATE indicates that pages had to be allocated to satis= fy + * this operation. */ #define IOMAP_F_NEW 0x01 #define IOMAP_F_DIRTY 0x02 #define IOMAP_F_SHARED 0x04 #define IOMAP_F_MERGED 0x08 #define IOMAP_F_BUFFER_HEAD 0x10 +#define IOMAP_F_PAGE_CREATE 0x20 =20 /* * Flags set by the core iomap code during operations: @@ -121,6 +125,7 @@ struct iomap_page_ops { #define IOMAP_FAULT (1 << 3) /* mapping for page fault */ #define IOMAP_DIRECT (1 << 4) /* direct I/O */ #define IOMAP_NOWAIT (1 << 5) /* do not block */ +#define IOMAP_UNCACHED (1 << 6) =20 struct iomap_ops { /* --=20 2.24.0