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.6 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,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 14D62C43603 for ; Thu, 12 Dec 2019 19:01:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C29FF2073B for ; Thu, 12 Dec 2019 19:01:49 +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="IckOWSwJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C29FF2073B 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 EFE578E0009; Thu, 12 Dec 2019 14:01:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E88268E0001; Thu, 12 Dec 2019 14:01:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4FB08E0009; Thu, 12 Dec 2019 14:01:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id BFB678E0001 for ; Thu, 12 Dec 2019 14:01:46 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 6EBD052B3 for ; Thu, 12 Dec 2019 19:01:46 +0000 (UTC) X-FDA: 76257408612.27.pan85_2c8612dfec50b X-HE-Tag: pan85_2c8612dfec50b X-Filterd-Recvd-Size: 7586 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Dec 2019 19:01:45 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id k24so3951271ioc.4 for ; Thu, 12 Dec 2019 11:01:45 -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=GaJCkgUv/B3OET1g1Gk3ujWzgIVpNM0nxRodwjfiGBE=; b=IckOWSwJdM1mRDe5xLg+1QZWh5GjmzKz/7oAhzljHbAQD3IR8KlQNignWa1viyT4en Bh37pENQzkkWfMCAI6BipdGMRo/FeyG1ZLUKPSdW+BN/fp8yr0o4MzfkgwtRhNsjRco+ M09XIHEM+8rPeoSpTB5EtkKznUCHqVeLvbg1q562VXLpYeQgoKspfnzL5cXCMwpaPm9s 64iPUDt8t+FhqGPPjCxwjQKb/UMTjRByOLC6AKfFpFvHPt5TTIbYK8wViTd7F3Hrs/jz F0x/5d299vyhYmAirrEFlRTDD/S4fijWr09sEYNA74raM3wwMiGwx+yKRv9O7TOmRyd4 3+OQ== 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=GaJCkgUv/B3OET1g1Gk3ujWzgIVpNM0nxRodwjfiGBE=; b=Sy4IrkIoyxn9qjF1r1KA3v0vlZTbLvLfCJ5YvvTufuGDefk+kr1x9ai3+85e5MKtqq k34B3Viw6twiRHlp131yOGL9BO4FLOxmASeAjHcj43Pis26jz4jlUkz1jQeiWweFlivv b8WYKwhsLCEFXCqGc8iNJF5SZTQaTVUpd0w+LFchqraTpzSDzIspV1cDm8Bxi4UYXOas sDPtbP+Mj+6k0UJDWX0gX8JXMQr/bzQTdYMN6PUbIZUYhxtg8kJ6mofwZK6mnyZ5zKB4 gLwk8bcOKODZyMSwB2ENitEJ2xU1FXVzZyphW36DpU/p6e3dqUD5nKUiq1szalblcQa0 AtaA== X-Gm-Message-State: APjAAAXmdM8X1z8Lyqlb78oGpsL5QiCJGOpb58nMOU8RAG9g9GSZe+jz FKeFn+lG50FSs5tInEHduRgDdYML9K+JnA== X-Google-Smtp-Source: APXvYqwjTIM6kPV9uE6Psr7sf1orKaXXnKqktbjIaUiI0LaIo8/4HAcLiFgn4bEKliYaVLewxqJuUQ== X-Received: by 2002:a02:a388:: with SMTP id y8mr9511471jak.70.1576177304566; Thu, 12 Dec 2019 11:01:44 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id i22sm1957745ill.40.2019.12.12.11.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2019 11:01:43 -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: Thu, 12 Dec 2019 12:01:33 -0700 Message-Id: <20191212190133.18473-6-axboe@kernel.dk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191212190133.18473-1-axboe@kernel.dk> References: <20191212190133.18473-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 | 23 +++++++++++++++++++---- include/linux/iomap.h | 5 +++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index e76148db03b8..11b6812f7b37 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -92,5 +92,29 @@ iomap_apply(struct iomap_data *data, const struct ioma= p_ops *ops, data->flags, &iomap); } =20 + if (written && (data->flags & IOMAP_UNCACHED)) { + struct address_space *mapping =3D data->inode->i_mapping; + + end =3D data->pos + written; + ret =3D filemap_write_and_wait_range(mapping, data->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, + data->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 0a1a195ed1cc..df9d6002858e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -659,6 +659,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 @@ -675,8 +676,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; @@ -818,6 +822,7 @@ iomap_write_actor(const struct iomap_data *data, stru= ct iomap *iomap, { struct inode *inode =3D data->inode; struct iov_iter *i =3D data->priv; + unsigned flags =3D data->flags; loff_t length =3D data->len; loff_t pos =3D data->pos; long status =3D 0; @@ -851,10 +856,17 @@ iomap_write_actor(const struct iomap_data *data, st= ruct iomap *iomap, 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); @@ -907,6 +919,9 @@ iomap_file_buffered_write(struct kiocb *iocb, struct = iov_iter *iter, }; loff_t ret =3D 0, written =3D 0; =20 + if (iocb->ki_flags & IOCB_UNCACHED) + data.flags |=3D IOMAP_UNCACHED; + while (iov_iter_count(iter)) { data.len =3D iov_iter_count(iter); ret =3D iomap_apply(&data, ops, iomap_write_actor); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 30f40145a9e9..30bb248e1d0d 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.1