From patchwork Wed Dec 11 15:29:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11285371 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 9402714BD for ; Wed, 11 Dec 2019 15:30:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 663AC22B48 for ; Wed, 11 Dec 2019 15:30:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="hIShSVgu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733306AbfLKP3v (ORCPT ); Wed, 11 Dec 2019 10:29:51 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38084 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732839AbfLKP3u (ORCPT ); Wed, 11 Dec 2019 10:29:50 -0500 Received: by mail-pg1-f194.google.com with SMTP id a33so10715121pgm.5 for ; Wed, 11 Dec 2019 07:29:50 -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=g934jRFitGK2n249ARajPKYt/UpPdfJOZffggpxpM9A=; b=hIShSVguWXwm0y2cL0ju6hNSTjgZP3jIvU5CANQeaBbbgcdD6PfmACfAi4kfMs+Sqx nATEMWbANyYz5uspreNDCqQMAz2eCalKMGWZm21O9mpV7mCH/K4jmhnX/pB/lM1aE0vM Xm/hmRQamtmiB6Pj9UPRaQ2DAIiLu2Qy0H/4qEegJZeOX1p+Yl2jRURAqxI866AIvP3Y 3UkbbAU+/7GJlWj/F02kfTmothrYFyD0N89sVtF04WTWIQx7aeucl6rRkCb2zrxepLZQ xP8vmSzTeiLhDUm2cExVT4HSFl9BTSNUR3f3NiK51XVhiZASq3GK9ydsAXSn+aeHt6A5 Ghsg== 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=g934jRFitGK2n249ARajPKYt/UpPdfJOZffggpxpM9A=; b=RT6blFNReg1gWip6g5aFzHMUaLYk3Jj7XIoPIEhN/fvRCdJFibcg0iZhaP7cV86QQf AC+5vvGVEfmz2Ok8V25occWzHO46XvQctxylQhCB97ipey2gyjjdldQW2aQAgg9nwo0t b8pBBWlGlQMLdvMMREZZij2gXBBWiVK2pVqoG7JKECkj8Sh5t4EWpwluT06fhjo7Gp2j kiccpNEWrkHyV7vNm1sVCf6x5cnZnAdG4dgjSVePArOfjAop73fgf05XNIF7lc5Efwts Z8wUIvjU8RVaLINpnl4uu4a7ltSGgdeVUYMJLe+JRnuB37AWTqr1bG1yiVfD8Azx06Do 6yhw== X-Gm-Message-State: APjAAAWv8trnasaLGsBW2mvbhWrUM6tA0UTdDRWWUtI1nMterm8g9qNw zXFQ8nhot2kclHxKKOGhUQongQ== X-Google-Smtp-Source: APXvYqwpF6dGCPhavv63RwYf+8PYYsJTF9C7RX+z8Jolg/cVO5+K6nTPhv4+p5ass14DlFh2i74SoA== X-Received: by 2002:a63:a707:: with SMTP id d7mr4668981pgf.93.1576078189951; Wed, 11 Dec 2019 07:29:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:29:48 -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 1/5] fs: add read support for RWF_UNCACHED Date: Wed, 11 Dec 2019 08:29:39 -0700 Message-Id: <20191211152943.2933-2-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If RWF_UNCACHED is set for io_uring (or preadv2(2)), we'll drop the cache for buffered reads if we are the ones instantiating it. If the data is already cached, we leave it cached. Signed-off-by: Jens Axboe --- include/linux/fs.h | 3 +++ include/uapi/linux/fs.h | 5 ++++- mm/filemap.c | 46 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 98e0349adb52..092ea2a4319b 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_UNCACHED (1 << 8) struct kiocb { struct file *ki_filp; @@ -3418,6 +3419,8 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC); if (flags & RWF_APPEND) ki->ki_flags |= IOCB_APPEND; + if (flags & RWF_UNCACHED) + ki->ki_flags |= IOCB_UNCACHED; return 0; } diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 379a612f8f1d..357ebb0e0c5d 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -299,8 +299,11 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* drop cache after reading or writing data */ +#define RWF_UNCACHED ((__force __kernel_rwf_t)0x00000040) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_UNCACHED) #endif /* _UAPI_LINUX_FS_H */ diff --git a/mm/filemap.c b/mm/filemap.c index bf6aa30be58d..ed23a11b3e34 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -933,8 +933,8 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping, } EXPORT_SYMBOL(add_to_page_cache_locked); -int add_to_page_cache_lru(struct page *page, struct address_space *mapping, - pgoff_t offset, gfp_t gfp_mask) +static int __add_to_page_cache(struct page *page, struct address_space *mapping, + pgoff_t offset, gfp_t gfp_mask, bool lru) { void *shadow = NULL; int ret; @@ -956,9 +956,17 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping, WARN_ON_ONCE(PageActive(page)); if (!(gfp_mask & __GFP_WRITE) && shadow) workingset_refault(page, shadow); - lru_cache_add(page); + if (lru) + lru_cache_add(page); } return ret; + +} + +int add_to_page_cache_lru(struct page *page, struct address_space *mapping, + pgoff_t offset, gfp_t gfp_mask) +{ + return __add_to_page_cache(page, mapping, offset, gfp_mask, true); } EXPORT_SYMBOL_GPL(add_to_page_cache_lru); @@ -2032,6 +2040,7 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, offset = *ppos & ~PAGE_MASK; for (;;) { + bool drop_page = false; struct page *page; pgoff_t end_index; loff_t isize; @@ -2048,6 +2057,9 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, if (!page) { if (iocb->ki_flags & IOCB_NOWAIT) goto would_block; + /* UNCACHED implies no read-ahead */ + if (iocb->ki_flags & IOCB_UNCACHED) + goto no_cached_page; page_cache_sync_readahead(mapping, ra, filp, index, last_index - index); @@ -2147,6 +2159,26 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, offset &= ~PAGE_MASK; prev_offset = offset; + /* + * If we're dropping this page due to drop-behind, then + * lock it first. Ignore errors here, we can just leave it + * in the page cache. Note that we didn't add this page to + * the LRU when we added it to the page cache. So if we + * fail removing it, or lock it, add to the LRU. + */ + if (drop_page) { + bool addlru = true; + + if (!lock_page_killable(page)) { + if (page->mapping == mapping) + addlru = !remove_mapping(mapping, page); + else + addlru = false; + unlock_page(page); + } + if (addlru) + lru_cache_add(page); + } put_page(page); written += ret; if (!iov_iter_count(iter)) @@ -2234,8 +2266,12 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, error = -ENOMEM; goto out; } - error = add_to_page_cache_lru(page, mapping, index, - mapping_gfp_constraint(mapping, GFP_KERNEL)); + if (iocb->ki_flags & IOCB_UNCACHED) + drop_page = true; + + error = __add_to_page_cache(page, mapping, index, + mapping_gfp_constraint(mapping, GFP_KERNEL), + !drop_page); if (error) { put_page(page); if (error == -EEXIST) { From patchwork Wed Dec 11 15:29:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11285361 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 D312C188B for ; Wed, 11 Dec 2019 15:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B145B22B48 for ; Wed, 11 Dec 2019 15:29:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="mRirhKAW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387725AbfLKP35 (ORCPT ); Wed, 11 Dec 2019 10:29:57 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35818 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387678AbfLKP3w (ORCPT ); Wed, 11 Dec 2019 10:29:52 -0500 Received: by mail-pf1-f193.google.com with SMTP id b19so1984854pfo.2 for ; Wed, 11 Dec 2019 07:29:52 -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=2SQjS8rVUv97zNNTlgrJhbpMsmZd4fG/GoKGJP3eAKE=; b=mRirhKAWFljYMiRUx194SXEFEtebKFxO5ZD0NK7T1mtl+xUBGQ0Yst6hneUUfMFIM4 CJHbOUUL+TVItwq3msVkfmRDrIS9KiqYgo2pNJJbrxDuK8F/gG/+yjfC8g7Psp/LVVnu myC59YfNOnR6SVVu7c6EDfdojaNua5fvpx4rj4fe07ntRzZFwGGBF3ERckadrGtL+6lw 9/cmBdu5Lle5khBqRxuFR4w8QZDVienwJjKpMPXGvei+PZCY5rtWrPZ+bf6sr/rgrYx3 W+9MN296zoxWbl0Fw2HGYe5l30oDTQtOkwoyyR2k9l3iBbeMx/iDPfDQ6H6ySMx/jIry 0I/w== 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=2SQjS8rVUv97zNNTlgrJhbpMsmZd4fG/GoKGJP3eAKE=; b=IRsBZipCRDBFG1MUim7wMYDPUYDk9XTYtdrdodUn3+AFcBg0pn/EAN7dSPKcEP+Dvn QLntpeV7zA3R3Bue3JPP+ZI+rrmIBNLtVectX4EcrOEs6aGjQZrNPXoWRWi2JZSswhKT i0zQF20QMRoUBj1vFoeoXDKqf94/YP6VayHa+Q4G9a3jcbb81x4y87S6cuC+clDsppe7 Wtt3hKrONbQmboqI0h42mEb45o243ib1L0IS4b4CI12n2l8rbnaFKBejiyuepNPJTd45 3Pt9f/Y50/NflxECn2yN7f7/A8MYyFM0aQZBkPRC1NVZsvPAzpxiWi9+pNWlupBlwWXK 1YYg== X-Gm-Message-State: APjAAAVTvGio79cV25KCwi38iUogLogjqDPLUMcz+pm6DrEX62p8+1yE qHkwwwfa4yzLm99ZLiv1lRA/AgrB1Aw= X-Google-Smtp-Source: APXvYqxfuUbnRf2Sjrpa01+W+GiMj+MkirsJ7dKPdEmqQOm6hBolB0IKP27YH+ADkKThXrnkx7OuJw== X-Received: by 2002:a63:1d1a:: with SMTP id d26mr4544893pgd.98.1576078191917; Wed, 11 Dec 2019 07:29:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:29:50 -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 2/5] mm: make generic_perform_write() take a struct kiocb Date: Wed, 11 Dec 2019 08:29:40 -0700 Message-Id: <20191211152943.2933-3-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Right now all callers pass in iocb->ki_pos, just pass in the iocb. This is in preparation for using the iocb flags in generic_perform_write(). Signed-off-by: Jens Axboe --- fs/ceph/file.c | 2 +- fs/ext4/file.c | 2 +- fs/nfs/file.c | 2 +- include/linux/fs.h | 3 ++- mm/filemap.c | 8 +++++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 11929d2bb594..096c009f188f 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1538,7 +1538,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) * are pending vmtruncate. So write and vmtruncate * can not run at the same time */ - written = generic_perform_write(file, from, pos); + written = generic_perform_write(file, from, iocb); if (likely(written >= 0)) iocb->ki_pos = pos + written; ceph_end_io_write(inode); diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 6a7293a5cda2..9ffb857765d5 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -249,7 +249,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, goto out; current->backing_dev_info = inode_to_bdi(inode); - ret = generic_perform_write(iocb->ki_filp, from, iocb->ki_pos); + ret = generic_perform_write(iocb->ki_filp, from, iocb); current->backing_dev_info = NULL; out: diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 8eb731d9be3e..d8f51a702a4e 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -624,7 +624,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) result = generic_write_checks(iocb, from); if (result > 0) { current->backing_dev_info = inode_to_bdi(inode); - result = generic_perform_write(file, from, iocb->ki_pos); + result = generic_perform_write(file, from, iocb); current->backing_dev_info = NULL; } nfs_end_io_write(inode); diff --git a/include/linux/fs.h b/include/linux/fs.h index 092ea2a4319b..bf58db1bc032 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3103,7 +3103,8 @@ extern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *); -extern ssize_t generic_perform_write(struct file *, struct iov_iter *, loff_t); +extern ssize_t generic_perform_write(struct file *, struct iov_iter *, + struct kiocb *); ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, rwf_t flags); diff --git a/mm/filemap.c b/mm/filemap.c index ed23a11b3e34..fe37bd2b2630 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3302,10 +3302,11 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, EXPORT_SYMBOL(grab_cache_page_write_begin); ssize_t generic_perform_write(struct file *file, - struct iov_iter *i, loff_t pos) + struct iov_iter *i, struct kiocb *iocb) { struct address_space *mapping = file->f_mapping; const struct address_space_operations *a_ops = mapping->a_ops; + loff_t pos = iocb->ki_pos; long status = 0; ssize_t written = 0; unsigned int flags = 0; @@ -3439,7 +3440,8 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (written < 0 || !iov_iter_count(from) || IS_DAX(inode)) goto out; - status = generic_perform_write(file, from, pos = iocb->ki_pos); + pos = iocb->ki_pos; + status = generic_perform_write(file, from, iocb); /* * If generic_perform_write() returned a synchronous error * then we want to return the number of bytes which were @@ -3471,7 +3473,7 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) */ } } else { - written = generic_perform_write(file, from, iocb->ki_pos); + written = generic_perform_write(file, from, iocb); if (likely(written > 0)) iocb->ki_pos += written; } From patchwork Wed Dec 11 15:29:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11285359 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 A78C015AB for ; Wed, 11 Dec 2019 15:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8689E22B48 for ; Wed, 11 Dec 2019 15:29:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="b7eZVja6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387956AbfLKP34 (ORCPT ); Wed, 11 Dec 2019 10:29:56 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:35575 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387953AbfLKP3y (ORCPT ); Wed, 11 Dec 2019 10:29:54 -0500 Received: by mail-pl1-f194.google.com with SMTP id s10so1559209plp.2 for ; Wed, 11 Dec 2019 07:29:54 -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=es9BSJvoDpT3WZtR0L+ZV+Or+1xGCPbWn6QJpLr3Xx4=; b=b7eZVja6aKMDWQsCKiYnvs5qkkMtb4DoRhvZH0mwJvk9LESKsse6xmT3WWlILNTvSh v88npyxYy5/e7tLfGcgiIVXEYnv46FT50sPnEQt69UhDuyJOSuVNzLSlAXpUWTdkrJku nBpk9ZFk1qOaWPCwwhIIUbpQcT9k4a3aWUlDts7fPgZxFfbctK2wZluabjrrFqSzFkdb ugqNIWkF1i16/QrpWLX9gvSlMh+w4/NfxFGOtFaxQnCkEmSB/wopkF4l1CCYgv3FmwBY 8JMlN5D7vigbmAU/36SNoC65YkKfas3+j+3P0Mey+EpgI+uJdC4zZ8pPIn6ofe48cSq8 fYrw== 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=es9BSJvoDpT3WZtR0L+ZV+Or+1xGCPbWn6QJpLr3Xx4=; b=OTql8V+lOizKMLIOFO14JClMsQxXBYBDZlvca5haTgRsTK9UWCbpmtmSqHe/WiVpfI j/xheoIwlB73dSY3qn/rDTMz6tO1uSM6Spoh6/xnvJvn3goSdcLKXDCQS7LhEhh3cxfd Q+ltQ9meIahPQHu8g+jZQfGfbVbIMfDP6SxCaOvYk+sokX6f9RM3OAFtk3NDVFVpl4+K 0+7xYB/DrYHH5qqRLt22dUnIHaEe6uAUOh87gaI3VtfNWeYHNWDSrBsQ5/xn2FBsYjua g4roN3mxiwPkoUhdfeVoqNkC49Q9G5MGeHhCqJdbB7V5jMvpWqStW4DA18tImw3gKn/B m+OQ== X-Gm-Message-State: APjAAAU34S2oCrSsccu/Som7PjIQkvFRsDOtjin/TjLCyjHgG2R2XSIu kGrnzftGTiy8xQJJA8AYGiUJ6w== X-Google-Smtp-Source: APXvYqwO4KCx+Py7lrwxvyOY5WGp+WpfJGvARNpLtItIFsqOyOUndXtXBekGEuoMQQchwtmsNvTWrg== X-Received: by 2002:a17:902:8d8a:: with SMTP id v10mr3929048plo.282.1576078193740; Wed, 11 Dec 2019 07:29:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:29:52 -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 3/5] mm: make buffered writes work with RWF_UNCACHED Date: Wed, 11 Dec 2019 08:29:41 -0700 Message-Id: <20191211152943.2933-4-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If RWF_UNCACHED is set for io_uring (or pwritev2(2)), we'll drop the cache instantiated for buffered writes. If new pages aren't instantiated, we leave them alone. This provides similar semantics to reads with RWF_UNCACHED set. Signed-off-by: Jens Axboe --- include/linux/fs.h | 1 + mm/filemap.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index bf58db1bc032..5ea5fc167524 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -285,6 +285,7 @@ enum positive_aop_returns { #define AOP_FLAG_NOFS 0x0002 /* used by filesystem to direct * helper code (eg buffer layer) * to clear GFP_FS from alloc */ +#define AOP_FLAG_UNCACHED 0x0004 /* * oh the beauties of C type declarations. diff --git a/mm/filemap.c b/mm/filemap.c index fe37bd2b2630..4dadd1a4ca7c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3287,10 +3287,12 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index, unsigned flags) { struct page *page; - int fgp_flags = FGP_LOCK|FGP_WRITE|FGP_CREAT; + int fgp_flags = FGP_LOCK|FGP_WRITE; if (flags & AOP_FLAG_NOFS) fgp_flags |= FGP_NOFS; + if (!(flags & AOP_FLAG_UNCACHED)) + fgp_flags |= FGP_CREAT; page = pagecache_get_page(mapping, index, fgp_flags, mapping_gfp_mask(mapping)); @@ -3311,6 +3313,9 @@ ssize_t generic_perform_write(struct file *file, ssize_t written = 0; unsigned int flags = 0; + if (iocb->ki_flags & IOCB_UNCACHED) + flags |= AOP_FLAG_UNCACHED; + do { struct page *page; unsigned long offset; /* Offset into pagecache page */ @@ -3343,10 +3348,16 @@ ssize_t generic_perform_write(struct file *file, break; } +retry: status = a_ops->write_begin(file, mapping, pos, bytes, flags, &page, &fsdata); - if (unlikely(status < 0)) + if (unlikely(status < 0)) { + if (status == -ENOMEM && (flags & AOP_FLAG_UNCACHED)) { + flags &= ~AOP_FLAG_UNCACHED; + goto retry; + } break; + } if (mapping_writably_mapped(mapping)) flush_dcache_page(page); @@ -3382,6 +3393,32 @@ ssize_t generic_perform_write(struct file *file, balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); + if (written && (iocb->ki_flags & IOCB_UNCACHED)) { + loff_t end; + + pos = iocb->ki_pos; + end = pos + written; + + status = filemap_write_and_wait_range(mapping, pos, end); + if (status) + goto out; + + /* + * No pages were created for this range, we're done + */ + if (flags & AOP_FLAG_UNCACHED) + 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 : status; } EXPORT_SYMBOL(generic_perform_write); From patchwork Wed Dec 11 15:29:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11285367 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 2D0A114BD for ; Wed, 11 Dec 2019 15:30:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 085332173E for ; Wed, 11 Dec 2019 15:30:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="zn3Mpc2f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387493AbfLKP37 (ORCPT ); Wed, 11 Dec 2019 10:29:59 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:38459 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731514AbfLKP34 (ORCPT ); Wed, 11 Dec 2019 10:29:56 -0500 Received: by mail-pj1-f67.google.com with SMTP id l4so9063951pjt.5 for ; Wed, 11 Dec 2019 07:29:56 -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=s8zjCrJz5ZRdYBpdQDfhxTslxtlYCGJ1G+7YBvhVfgI=; b=zn3Mpc2fwIWc8pDQB7gP4q1pc2X/iEkrHaHLDGQcQNv4SUM1gMOlKSJWO0Qa9fumRn V93Ai4CIFs5tfbxv50V+C5LCLzKT/QO6RS+DTBKmRX7+h1Dekabh/e2BZnzXhKE9S96x k3oSrULLsUS4G7/WB6wdu3oxW39bMMOsbwkueMFJz+qwizVg9wpSXOfu1930JZNE5Sv/ 6B39S5oZSQAXvfDAIWA77wQxq+5o76S+lrOCmQgsIqfxXsmEqmUGMbl9+nGbnpmaVXcQ RmPtQ1ltav6gOMXmPA1F0P/TsJTdPjXwvQFKacyLYt6XtYlH0WwanpyqHoeuJksP1Kjn kiyQ== 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=s8zjCrJz5ZRdYBpdQDfhxTslxtlYCGJ1G+7YBvhVfgI=; b=P9CfpXpLLp8dZ1IPTOWAoUxswo1vXrNyNFYLmHWnMh2IhhZafQIlj4dv+Z1ChPYNnJ JGtUMrXU2uvUoISK+O8H7v2c9JymAJ6jzk2RKS5f60c34y+x9ySArIefq8f6tfUQbFXn E9PttATIh1155mr+1tgAAEAryGE4Ipcwn43z7NWwxLSORI20pSk5hTZZznsyReoPheu8 v0M8iBc3O/ItyolyRHlC5IHuYZASpsjAhViq+s3s0HAYcLoacGwChCAe6IsH5Mcv0eBc t+9GpVKjOplnSfpVuYJolnuPj782eYZXgluwteVmJZNZ1ZNZVgHZTl27fYD5deBPbASv RyGQ== X-Gm-Message-State: APjAAAX6qx1x7Wy1YUfIip+XmHwuOfzBnJvmEBX5qEtsK+lpUXn5m8TW IYswfJU554PGZuw0UxVA94iZpw== X-Google-Smtp-Source: APXvYqzNcqVyVbZb9ulz0Wi2/V5mzS/cYQorx+P9Kc7sv7G0jLWljuOrg76Dj1hLiJyji1gF1tDCJA== X-Received: by 2002:a17:90a:62ca:: with SMTP id k10mr4171295pjs.59.1576078195498; Wed, 11 Dec 2019 07:29:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:29:54 -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 4/5] iomap: pass in the write_begin/write_end flags to iomap_actor Date: Wed, 11 Dec 2019 08:29:42 -0700 Message-Id: <20191211152943.2933-5-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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is in preparation for passing in a flag to the iomap_actor, which currently doesn't support that. No functional changes in this patch. Signed-off-by: Jens Axboe --- fs/dax.c | 2 +- fs/iomap/apply.c | 2 +- fs/iomap/buffered-io.c | 17 ++++++++++------- fs/iomap/direct-io.c | 3 ++- fs/iomap/fiemap.c | 5 +++-- fs/iomap/seek.c | 6 ++++-- fs/iomap/swapfile.c | 2 +- include/linux/iomap.h | 5 +++-- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 1f1f0201cad1..30a20b994140 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1091,7 +1091,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range); static loff_t dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, - struct iomap *iomap, struct iomap *srcmap) + unsigned flags, struct iomap *iomap, struct iomap *srcmap) { struct block_device *bdev = iomap->bdev; struct dax_device *dax_dev = iomap->dax_dev; diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index 76925b40b5fd..562536da8a13 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -77,7 +77,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, * iomap into the actors so that they don't need to have special * handling for the two cases. */ - written = actor(inode, pos, length, data, &iomap, + written = actor(inode, pos, length, data, flags, &iomap, srcmap.type != IOMAP_HOLE ? &srcmap : &iomap); /* diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 828444e14d09..9b5b770ca4c7 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -249,7 +249,7 @@ static inline bool iomap_block_needs_zeroing(struct inode *inode, static loff_t iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, - struct iomap *iomap, struct iomap *srcmap) + unsigned flags, struct iomap *iomap, struct iomap *srcmap) { struct iomap_readpage_ctx *ctx = data; struct page *page = ctx->cur_page; @@ -397,7 +397,8 @@ iomap_next_page(struct inode *inode, struct list_head *pages, loff_t pos, static loff_t iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { struct iomap_readpage_ctx *ctx = data; loff_t done, ret; @@ -417,7 +418,7 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, ctx->cur_page_in_bio = false; } ret = iomap_readpage_actor(inode, pos + done, length - done, - ctx, iomap, srcmap); + ctx, 0, iomap, srcmap); } return done; @@ -797,7 +798,7 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, unsigned copied, static loff_t iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, - struct iomap *iomap, struct iomap *srcmap) + unsigned flags, struct iomap *iomap, struct iomap *srcmap) { struct iov_iter *i = data; long status = 0; @@ -897,7 +898,7 @@ EXPORT_SYMBOL_GPL(iomap_file_buffered_write); static loff_t iomap_unshare_actor(struct inode *inode, loff_t pos, loff_t length, void *data, - struct iomap *iomap, struct iomap *srcmap) + unsigned flags, struct iomap *iomap, struct iomap *srcmap) { long status = 0; ssize_t written = 0; @@ -983,7 +984,8 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes, static loff_t iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { bool *did_zero = data; loff_t written = 0; @@ -1053,7 +1055,8 @@ EXPORT_SYMBOL_GPL(iomap_truncate_page); static loff_t iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { struct page *page = data; int ret; diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 23837926c0c5..2525997b09aa 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -365,7 +365,8 @@ iomap_dio_inline_actor(struct inode *inode, loff_t pos, loff_t length, static loff_t iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { struct iomap_dio *dio = data; diff --git a/fs/iomap/fiemap.c b/fs/iomap/fiemap.c index bccf305ea9ce..04de960259d0 100644 --- a/fs/iomap/fiemap.c +++ b/fs/iomap/fiemap.c @@ -44,7 +44,7 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi, static loff_t iomap_fiemap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, - struct iomap *iomap, struct iomap *srcmap) + unsigned flags, struct iomap *iomap, struct iomap *srcmap) { struct fiemap_ctx *ctx = data; loff_t ret = length; @@ -111,7 +111,8 @@ EXPORT_SYMBOL_GPL(iomap_fiemap); static loff_t iomap_bmap_actor(struct inode *inode, loff_t pos, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { sector_t *bno = data, addr; diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c index 89f61d93c0bc..a5cbf04e8cb3 100644 --- a/fs/iomap/seek.c +++ b/fs/iomap/seek.c @@ -119,7 +119,8 @@ page_cache_seek_hole_data(struct inode *inode, loff_t offset, loff_t length, static loff_t iomap_seek_hole_actor(struct inode *inode, loff_t offset, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { switch (iomap->type) { case IOMAP_UNWRITTEN: @@ -165,7 +166,8 @@ EXPORT_SYMBOL_GPL(iomap_seek_hole); static loff_t iomap_seek_data_actor(struct inode *inode, loff_t offset, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap) { switch (iomap->type) { case IOMAP_HOLE: diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c index a648dbf6991e..774bfc3e59e1 100644 --- a/fs/iomap/swapfile.c +++ b/fs/iomap/swapfile.c @@ -76,7 +76,7 @@ static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi) * distinction between written and unwritten extents. */ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, - loff_t count, void *data, struct iomap *iomap, + loff_t count, void *data, unsigned flags, struct iomap *iomap, struct iomap *srcmap) { struct iomap_swapfile_info *isi = data; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 8b09463dae0d..61fcaa3904d4 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -113,7 +113,7 @@ struct iomap_page_ops { }; /* - * Flags for iomap_begin / iomap_end. No flag implies a read. + * Flags for iomap_begin / iomap_end / factor. No flag implies a read. */ #define IOMAP_WRITE (1 << 0) /* writing, must allocate blocks */ #define IOMAP_ZERO (1 << 1) /* zeroing operation, may skip holes */ @@ -146,7 +146,8 @@ struct iomap_ops { * Main iomap iterator function. */ typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len, - void *data, struct iomap *iomap, struct iomap *srcmap); + void *data, unsigned flags, struct iomap *iomap, + struct iomap *srcmap); loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data, From patchwork Wed Dec 11 15:29:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11285375 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 96318138D for ; Wed, 11 Dec 2019 15:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B03B24679 for ; Wed, 11 Dec 2019 15:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="qxq/32r1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731516AbfLKPaD (ORCPT ); Wed, 11 Dec 2019 10:30:03 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40943 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387678AbfLKP36 (ORCPT ); Wed, 11 Dec 2019 10:29:58 -0500 Received: by mail-pf1-f193.google.com with SMTP id q8so1970876pfh.7 for ; Wed, 11 Dec 2019 07:29:57 -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=C/YOP1JzuEwR95hY4nJ4aJsOgQQMqw1WJpm9WXrlBuZ5/5oN1PCzp5389EyLuWgs/L QTdZMOPzEeh9G80BWfADhVQCufBUzlojJB6OYHeirKIAkQch3JD7j0V+ttXnd4f1oxdp DhrYRl6+gqO2T5QA9tOQvk/n54T//iib1gcFw+M/16zDEnxc25EK0CiKAuU8YlHjQwuk GZnQB0fodw/EhpYvFrUxKfcrst2lHJbrZxcFqJ0VVeSYUHGOklq6KIgamBTucEqT49UV Tb4ORwXgVzOjTaN7JJSLo0idUudX4R6n7QayVpbMJZUK33301jN3OFhUZHFZ+nT/UjlV hO0A== X-Gm-Message-State: APjAAAWSxkGKocAQYAQs5LEqb+i1qzJmvf3Y2dPZJC3lBo3XaYXYwg+S /oI99tR/Ich43sQAMSCqvuRJ5w== 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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 length, unsigned flags, flags, &iomap); } + if (written && (flags & IOMAP_UNCACHED)) { + struct address_space *mapping = inode->i_mapping; + + end = pos + written; + ret = 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); enum { IOMAP_WRITE_F_UNSHARE = (1 << 0), + IOMAP_WRITE_F_UNCACHED = (1 << 1), }; static void @@ -643,6 +644,7 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, struct page **pagep, struct iomap *iomap, struct iomap *srcmap) { const struct iomap_page_ops *page_ops = iomap->page_ops; + unsigned aop_flags; struct page *page; int status = 0; @@ -659,8 +661,11 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, return status; } + aop_flags = AOP_FLAG_NOFS; + if (flags & IOMAP_UNCACHED) + aop_flags |= AOP_FLAG_UNCACHED; page = grab_cache_page_write_begin(inode->i_mapping, pos >> PAGE_SHIFT, - AOP_FLAG_NOFS); + aop_flags); if (!page) { status = -ENOMEM; goto out_no_page; @@ -670,9 +675,14 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, iomap_read_inline_data(inode, page, srcmap); else if (iomap->flags & IOMAP_F_BUFFER_HEAD) status = __block_write_begin_int(page, pos, len, NULL, srcmap); - else - status = __iomap_write_begin(inode, pos, len, flags, page, + else { + unsigned wb_flags = 0; + + if (flags & IOMAP_UNCACHED) + wb_flags = IOMAP_WRITE_F_UNCACHED; + status = __iomap_write_begin(inode, pos, len, wb_flags, page, srcmap); + } 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; } - status = iomap_write_begin(inode, pos, bytes, 0, &page, iomap, - srcmap); - if (unlikely(status)) +retry: + status = iomap_write_begin(inode, pos, bytes, flags, &page, + iomap, srcmap); + if (unlikely(status)) { + if (status == -ENOMEM && (flags & IOMAP_UNCACHED)) { + iomap->flags |= IOMAP_F_PAGE_CREATE; + flags &= ~IOMAP_UNCACHED; + goto retry; + } break; + } if (mapping_writably_mapped(inode->i_mapping)) flush_dcache_page(page); @@ -882,10 +899,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *iter, { struct inode *inode = iocb->ki_filp->f_mapping->host; loff_t pos = iocb->ki_pos, ret = 0, written = 0; + unsigned flags = IOMAP_WRITE; + + if (iocb->ki_flags & IOCB_UNCACHED) + flags |= IOMAP_UNCACHED; while (iov_iter_count(iter)) { - ret = iomap_apply(inode, pos, iov_iter_count(iter), - IOMAP_WRITE, ops, iter, iomap_write_actor); + ret = iomap_apply(inode, pos, iov_iter_count(iter), flags, + ops, iter, iomap_write_actor); if (ret <= 0) break; pos += 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 of * buffer heads for this mapping. + * + * IOMAP_F_PAGE_CREATE indicates that pages had to be allocated to satisfy + * 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 /* * 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) struct iomap_ops { /*