From patchwork Tue Dec 10 16:24:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11282943 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 EA016109A for ; Tue, 10 Dec 2019 16:25:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD7EC207FF for ; Tue, 10 Dec 2019 16:25:02 +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="hhZ7xYi6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD7EC207FF 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 609CC6B2D38; Tue, 10 Dec 2019 11:25:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5B8946B2D39; Tue, 10 Dec 2019 11:25:00 -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 4F7916B2D3A; Tue, 10 Dec 2019 11:25:00 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 2B8156B2D38 for ; Tue, 10 Dec 2019 11:25:00 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id DEA393D12 for ; Tue, 10 Dec 2019 16:24:59 +0000 (UTC) X-FDA: 76249755918.12.plant30_e7c582802148 X-Spam-Summary: 40,2.5,0,ad1870cb10c5df9c,d41d8cd98f00b204,axboe@kernel.dk,::linux-fsdevel@vger.kernel.org:linux-block@vger.kernel.org:axboe@kernel.dk,RULES_HIT:41:355:379:541:800:960:968:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3865:3866:3867:3870:3871:3872:3874:4118:4250:4321:4605:5007:6261:6653:7875:7903:8531:8957:10011:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13894:14096:14110:14181:14394:14721:21080:21444:21451:21627:21740:21990:30054,0,RBL:209.85.166.194:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: plant30_e7c582802148 X-Filterd-Recvd-Size: 7620 Received: from mail-il1-f194.google.com (mail-il1-f194.google.com [209.85.166.194]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Dec 2019 16:24:59 +0000 (UTC) Received: by mail-il1-f194.google.com with SMTP id b15so16632665ila.7 for ; Tue, 10 Dec 2019 08:24:59 -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=hhZ7xYi6iAcufTEkO6fc43ItaJGoyWZp9Y4vBkYqSNRtCXuWhdjFbxsbu9OktdC0IO nW3gunLzXkKUO8wgJ+0yeoSppeRI+4D7y2tLEMNIdky0dwtNX9fQ4rFUoawcOgFbAgdp 9E0vTmcrsVvH1daaGcCOFDz7jCcGskD3Tp/aKtGTezQEJ9j19GUYbGJplvp7jB8alSM9 leCUbUP7hxo8rytSDGedyPJAe3H4NsHZiigF8DhwcE2J2SfZO82HFed+Pj7kzwG+JQk8 l3AeLqWHAdDGy/QPsdnbrN019CohHLWmjj2JGShCbv+uEBHUxUgsIQ6MAbnS3j1dCpKu lIFw== 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=ACLaUiizwCk+B4lkZ++lCzteJ7FvWdywtSC7SM30SWwbpk70rbukRFQzDnpD/oCA4R LbqiX7q8YRkRF0HKo1ojcrAVN9t1cjsnaPnmliI/eBAonrT8AMfG/m3sdueu+eUdDTX7 tTywPtenDHoLJfObn3sEq48bHtmUdTbSbjhk6+PDYsEmV2Sf4v2D2OpZadAbbxq7pckp zw0EPTi0NPfbphelHqQb96s3are3zp+lEY5SlhwxD0Ej5Z269AZ8+GMMyLjneaRTbVu3 yRvykddVli72ARXPaFPItB3d5ulLEZn69ay2d1VI7pCWFXYRUVPQ6nKi2pNhYRhq5Pg7 Kn4g== X-Gm-Message-State: APjAAAWCqvYjgU5KxLs5HZ0HqMVR7L3+WsoNmHlqF8DctrNtyUOlbx8f 0EvwgHTkkkzGnQbfc4/yBBe77Zum6QP5iQ== X-Google-Smtp-Source: APXvYqwjwuIZVZbUrdsT5Ok1m2EfYH1iKu0ClsiGMys8G17rmQyXyJbWlm1NyAXEqetUUjxlwNaq8A== X-Received: by 2002:a92:84dd:: with SMTP id y90mr31666919ilk.99.1575995098180; Tue, 10 Dec 2019 08:24:58 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id y11sm791174iol.23.2019.12.10.08.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:24:57 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/5] fs: add read support for RWF_UNCACHED Date: Tue, 10 Dec 2019 09:24:50 -0700 Message-Id: <20191210162454.8608-2-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210162454.8608-1-axboe@kernel.dk> References: <20191210162454.8608-1-axboe@kernel.dk> MIME-Version: 1.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: 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 Tue Dec 10 16:24:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11282953 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 E0059188B for ; Tue, 10 Dec 2019 16:25:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96B8C21D7D for ; Tue, 10 Dec 2019 16:25:05 +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="KdJPrK92" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96B8C21D7D 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 4A99D6B2D39; Tue, 10 Dec 2019 11:25:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 459E36B2D3A; Tue, 10 Dec 2019 11:25:02 -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 3245E6B2D3B; Tue, 10 Dec 2019 11:25:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 1DB626B2D39 for ; Tue, 10 Dec 2019 11:25:02 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 93B668249980 for ; Tue, 10 Dec 2019 16:25:01 +0000 (UTC) X-FDA: 76249756002.28.vein88_eb95daab5e1c X-Spam-Summary: 2,0,0,04c5fd9d861515ca,d41d8cd98f00b204,axboe@kernel.dk,::linux-fsdevel@vger.kernel.org:linux-block@vger.kernel.org:axboe@kernel.dk,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1544:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:4117:4321:4605:5007:6261:6653:10004:11026:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12679:12895:12986:13868:13894:14096:14181:14394:14721:21080:21444:21611:21627:21796:21990:30034:30036:30046:30054,0,RBL:209.85.166.65:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:26,LUA_SUMMARY:none X-HE-Tag: vein88_eb95daab5e1c X-Filterd-Recvd-Size: 6971 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Dec 2019 16:25:01 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id t26so7991055ioi.13 for ; Tue, 10 Dec 2019 08:25:00 -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=KdJPrK92FyMA/n5MuNfAlPHd0oImSTZlalWyF+0fuBSmXkKu6+diP7+rdBUbGQpZkk 7JPPl86po9n4aQWQLulc8QiRtO0Sp/qDEcuDRd5TS3VvNXvwp6XS/k+pfbmLHDxWl2f+ AAKVBkYYp9wj6E26MnzpxXrurr2jWtRi0TKky9UukdjDoA7/GdXM6YtsmCFoJ2+Mmr4I XbBcEuaesRjidUVjkNZj6QnpApK1tyWIMPyHHOG7cykF3oHdn2wyrzrk0JwXwBC10ZG8 YNj/QjZkJrssiZZ4EG+YJDYt62y/slOIEv53rD8vHwtBEUZjxJpCV8Qo1jklJy+34ySs iP1A== 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=K36KpfNMdaZjV/E5M24LSja3/lEKJTDLnqRzNkjoC+mUfLA+R0uCfirpDqTPd6IVEf SKNLK5+WXO5adVFEq1EX+6kdwGTA5du4MClx2OJYFQ4hWlHQcXiaUKGTKm80zHcQz30w 0x1lHTFOpPV++0Ddv5Wwk4c5WQaktOG8UIBwUSuQWCMn8H4ax223VfU7q7S/yLoiW7Wi bY0DMllxmtfSub2O6HxTK/p1/R5mhIgAbUL/zjGx/wH9KY0OPSm+xvbngA9xMqWXB0XS QBmXFG/DOX7ktpWhCC+6MXGvVRKFADDzZyoiflzRTSY+8m3PyQwVakNuAyUFcZ4aoeu3 McCw== X-Gm-Message-State: APjAAAXPIFxMXWLYpzVcvEP92ehTrYnUXw6n2djnwt3aQ5AAZuWCnSEK Tlf9ikj1CkaUZeEzOj3uWq6xEVeyL7rJXQ== X-Google-Smtp-Source: APXvYqxLMClXfOrpqdQ+I1lUcEUYXE4y9owWqZYlmjE/yWxjL77FymqW+NlU+FpfZbH+AHoKbGInYA== X-Received: by 2002:a5e:d617:: with SMTP id w23mr25169022iom.98.1575995099536; Tue, 10 Dec 2019 08:24:59 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id y11sm791174iol.23.2019.12.10.08.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:24:58 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/5] mm: make generic_perform_write() take a struct kiocb Date: Tue, 10 Dec 2019 09:24:51 -0700 Message-Id: <20191210162454.8608-3-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210162454.8608-1-axboe@kernel.dk> References: <20191210162454.8608-1-axboe@kernel.dk> MIME-Version: 1.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: 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 Tue Dec 10 16:24:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11282959 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 9493714BD for ; Tue, 10 Dec 2019 16:25:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 544722073B for ; Tue, 10 Dec 2019 16:25:08 +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="Zpixa69l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 544722073B 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 EBEF26B2D3A; Tue, 10 Dec 2019 11:25:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DDD686B2D3D; Tue, 10 Dec 2019 11:25:03 -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 C72096B2D3D; Tue, 10 Dec 2019 11:25:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id B26846B2D3A for ; Tue, 10 Dec 2019 11:25:03 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 54761180AD81F for ; Tue, 10 Dec 2019 16:25:03 +0000 (UTC) X-FDA: 76249756086.15.beam97_ef2745811d38 X-Spam-Summary: 2,0,0,175b5ce168d4eae8,d41d8cd98f00b204,axboe@kernel.dk,::linux-fsdevel@vger.kernel.org:linux-block@vger.kernel.org:axboe@kernel.dk,RULES_HIT:2:41:355:379:541:800:960:968:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1605:1606:1730:1747:1777:1792:2194:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3874:4119:4321:4605:5007:6119:6261:6653:6691:7903:7904:9008:9036:9592:9707:10004:10226:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14110:14394:21080:21324:21444:21451:21611:21627:21795:21987:21990:30012:30046:30051:30054:30079,0,RBL:209.85.166.65:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:24,LUA_SUMMARY:none X-HE-Tag: beam97_ef2745811d38 X-Filterd-Recvd-Size: 8271 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Dec 2019 16:25:02 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id t26so7991166ioi.13 for ; Tue, 10 Dec 2019 08:25:02 -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=o/x6NjL9O5h2Ux7aJEFNccuj0M9CNUr2pjvWBBusJd4=; b=Zpixa69lHW83t2ZbBBOHojQxENx5w2X0sKlji5l+ZpBo6tA/3fj9yn2HfnjrlJQ6Ob U8FY3MOCg7q0XHIPvND9EpFk53qsIhRbPB/9HbD1ilihLRNcBtOuwWUXkIqNVoGnuzdD 5XOtCxdmCCmO2Arsi/KYjMVTyNg6egphSQmKqqQfmQkq1VyVM8Gj0Xtm9JJX4Led8WKe zmbD/SLsl+MyHYWuaQHEb1/hAAYeSbscwPIu0vVxe909vlonZb4pS3Y0AjqklnvTPNnZ 6/Cw7617YWeJqBJwlZJAG0ivRv7q+hmVouVZ8mhUmu2zs+i9PsKCc/s41pHKmnnSHHi9 5YdQ== 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=o/x6NjL9O5h2Ux7aJEFNccuj0M9CNUr2pjvWBBusJd4=; b=ojuJOvsAR4Q0+gTqGUBL5akDSzoaQjB3An0aSW/fMS21iWDMDtBiOvXKvw6YU7FsfN ZRZ5UOs6XMBpjrl2Psw3VfPHCGi9tskZvC7Ay/zBSoYo1qgfZtdMkcmbun7vmJ5ejMl2 0WjlhWlK+tH2DDzfmLFIm6z2/KQ2+m6fJ3mIvIAXzx6hQP9udLa9yMl0dgPuMiMga8Fy +WRg3jMyc6ZAiwhp8clxhNzSizce0k/4ePwGWZn7SOJjdcyEjQuNU+F8zJKgLjNR+a69 xaL7KCifYKL/kBWan22R2gGxndFuG33rhp5+trE6Y5dXq91XsqK2UAbwXZLhGWJI5mnc PLYg== X-Gm-Message-State: APjAAAX20+kVBzMv6D7r+eN8v+uKdGRSsC7z0YARpGyF7CycXKplr5th kr0G4FYqZBO8a0NCl72fAKRe8zqwECL9HA== X-Google-Smtp-Source: APXvYqxxtEmqFA3byjJGnmrQmrrH3TRgfkvrkxj17L5ofRuCP+Z2MTkeccUYnzTdzqEGwVD/DbWwww== X-Received: by 2002:a02:c6d5:: with SMTP id r21mr32752498jan.129.1575995101208; Tue, 10 Dec 2019 08:25:01 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id y11sm791174iol.23.2019.12.10.08.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:25:00 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/5] mm: make buffered writes work with RWF_UNCACHED Date: Tue, 10 Dec 2019 09:24:52 -0700 Message-Id: <20191210162454.8608-4-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210162454.8608-1-axboe@kernel.dk> References: <20191210162454.8608-1-axboe@kernel.dk> MIME-Version: 1.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: 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 | 3 ++ mm/filemap.c | 78 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index bf58db1bc032..bcf486c132a8 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. @@ -3105,6 +3106,8 @@ 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 *, struct kiocb *); +extern void write_drop_cached_pages(struct page **, + struct address_space *mapping, unsigned *); 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 fe37bd2b2630..d6171bf705f9 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)); @@ -3301,21 +3303,67 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, } EXPORT_SYMBOL(grab_cache_page_write_begin); +/* + * Start writeback on the pages in pgs[], and then try and remove those pages + * from the page cached. Used with RWF_UNCACHED. + */ +void write_drop_cached_pages(struct page **pgs, struct address_space *mapping, + unsigned *nr) +{ + loff_t start, end; + int i; + + end = 0; + start = LLONG_MAX; + for (i = 0; i < *nr; i++) { + struct page *page = pgs[i]; + loff_t off; + + off = (loff_t) page_to_index(page) << PAGE_SHIFT; + if (off < start) + start = off; + if (off > end) + end = off; + get_page(page); + } + + __filemap_fdatawrite_range(mapping, start, end, WB_SYNC_NONE); + + for (i = 0; i < *nr; i++) { + struct page *page = pgs[i]; + + lock_page(page); + if (page->mapping == mapping) { + wait_on_page_writeback(page); + if (!page_has_private(page) || + try_to_release_page(page, 0)) + remove_mapping(mapping, page); + } + unlock_page(page); + } + *nr = 0; +} +EXPORT_SYMBOL_GPL(write_drop_cached_pages); + +#define GPW_PAGE_BATCH 16 + ssize_t generic_perform_write(struct file *file, struct iov_iter *i, struct kiocb *iocb) { struct address_space *mapping = file->f_mapping; const struct address_space_operations *a_ops = mapping->a_ops; + struct page *drop_pages[GPW_PAGE_BATCH]; loff_t pos = iocb->ki_pos; long status = 0; ssize_t written = 0; - unsigned int flags = 0; + unsigned int flags = 0, drop_nr = 0; do { struct page *page; unsigned long offset; /* Offset into pagecache page */ unsigned long bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ + bool drop_page = false; /* drop page after IO */ void *fsdata; offset = (pos & (PAGE_SIZE - 1)); @@ -3323,6 +3371,9 @@ ssize_t generic_perform_write(struct file *file, iov_iter_count(i)); again: + if (iocb->ki_flags & IOCB_UNCACHED) + flags |= AOP_FLAG_UNCACHED; + /* * Bring in the user page that we will copy from _first_. * Otherwise there's a nasty deadlock on copying from the @@ -3343,10 +3394,17 @@ 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)) { + drop_page = true; + flags &= ~AOP_FLAG_UNCACHED; + goto retry; + } break; + } if (mapping_writably_mapped(mapping)) flush_dcache_page(page); @@ -3376,12 +3434,22 @@ ssize_t generic_perform_write(struct file *file, iov_iter_single_seg_count(i)); goto again; } + if (drop_page && + ((pos >> PAGE_SHIFT) != ((pos + copied) >> PAGE_SHIFT))) { + drop_pages[drop_nr] = page; + if (++drop_nr == GPW_PAGE_BATCH) + write_drop_cached_pages(drop_pages, mapping, + &drop_nr); + } else + balance_dirty_pages_ratelimited(mapping); + pos += copied; written += copied; - - balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); + if (drop_nr) + write_drop_cached_pages(drop_pages, mapping, &drop_nr); + return written ? written : status; } EXPORT_SYMBOL(generic_perform_write); From patchwork Tue Dec 10 16:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11282961 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 6AACF14BD for ; Tue, 10 Dec 2019 16:25:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D3FC207FF for ; Tue, 10 Dec 2019 16:25:11 +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="wJMPU574" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D3FC207FF 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 4360E6B2D3B; Tue, 10 Dec 2019 11:25:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 397406B2D3C; Tue, 10 Dec 2019 11:25:05 -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 239E06B2D3D; Tue, 10 Dec 2019 11:25:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 92DF56B2D3C for ; Tue, 10 Dec 2019 11:25:04 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 3E8BD8249980 for ; Tue, 10 Dec 2019 16:25:04 +0000 (UTC) X-FDA: 76249756128.20.oven67_f174a15cb51c X-Spam-Summary: 2,0,0,35274e267f2e7e06,d41d8cd98f00b204,axboe@kernel.dk,::linux-fsdevel@vger.kernel.org:linux-block@vger.kernel.org:axboe@kernel.dk,RULES_HIT:1:2:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1605:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3865:3867:3868:3870:3871:3874:4050:4321:4605:5007:6119:6261:6653:7875:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13894:14096:14394:21080:21324:21444:21451:21524:21627:21990:30036:30046:30054:30090,0,RBL:209.85.166.67:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:24,LUA_SUMMARY:none X-HE-Tag: oven67_f174a15cb51c X-Filterd-Recvd-Size: 10792 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Dec 2019 16:25:03 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id z23so19356698iog.11 for ; Tue, 10 Dec 2019 08:25:03 -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=wJMPU5744v6WvxtshLB2YhVTVwEzJUYSVo8Cs1mYZznhz6iXZhCKqfpBrOA7c9NQ/p ZB/rQ/F3tjUQFEKcp0V16keNshFiXhLgvA3BDicpYTn/L60SrB6ppALuRvhkK7il127i GR6GHDlijob8PxzMMJZ6rvs1Gm+EVatZz5hx7EO4+t+7HQe4QGvfugxHPIITaTI7POhe N1+MTHKKXblvBtAXucSwX2tMZ/6Z1M1r3pv4iZwnDBXiFZWOweOGvk0R6e+YhMj+xMb/ ZQB1v8sAO98ubvrrs3ymc3bRjUK1ZdI1b1w87JOW2iT76e5SLhr2CzRf6hz123ily0Zv kp4A== 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=mt6eACyC4exUzcAMLY3KmNu6PV2+MOp1MZvb7vNMd6TQpipFkJ3cX+8OkT7mmkEPUL Ba62BYklIpawxfo2O3vL0+0yQqcV5ekqei8/BV5Tj5OZ/qtl92unqDDabSdqZn8zPYyi G27/ru/JZ2a5uI19H2Yj9s/O6Sr2ltPjYV3piPx7U9yGVjMdele71FcYZ7TVy3CJRVQX 9o/T9hhH1MqKYn2e7qhmVLiQ6+QJs39cYBGFP1N3CCKBg23I8jnpoEFpjhqWBS3VrG9J W3jzSaGIKyMCSxuOCQ+aAibErXMYsmV60GQTXLJ5I+AKC08khA1Vho9uwKIGjhGHFQ79 lHgQ== X-Gm-Message-State: APjAAAVghZmL85MrXp7dZItA9N63rs6fb/9axPQPoYEPNRzOlGKhoYL+ TL8woe0sA38kV/n7bV36rfeeWL1XkX8Y6Q== X-Google-Smtp-Source: APXvYqwbuFT7R6Wu2bsFXx+xszUEd+tIs1J+ms6VwaNAPr1muQEEAbdJXNtKxn1ir2hTG4mTArM/4A== X-Received: by 2002:a5e:8c14:: with SMTP id n20mr1670705ioj.161.1575995102464; Tue, 10 Dec 2019 08:25:02 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id y11sm791174iol.23.2019.12.10.08.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:25:01 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/5] iomap: pass in the write_begin/write_end flags to iomap_actor Date: Tue, 10 Dec 2019 09:24:53 -0700 Message-Id: <20191210162454.8608-5-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210162454.8608-1-axboe@kernel.dk> References: <20191210162454.8608-1-axboe@kernel.dk> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Tue Dec 10 16:24:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 11282963 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 0E4DC109A for ; Tue, 10 Dec 2019 16:25:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4DC92073B for ; Tue, 10 Dec 2019 16:25:14 +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="eQQkP4Qn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4DC92073B 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 C71336B2D3C; Tue, 10 Dec 2019 11:25:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BFB076B2D3D; Tue, 10 Dec 2019 11:25:05 -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 B0F9B6B2D3E; Tue, 10 Dec 2019 11:25:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 9C30B6B2D3C for ; Tue, 10 Dec 2019 11:25:05 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 561C652A3 for ; Tue, 10 Dec 2019 16:25:05 +0000 (UTC) X-FDA: 76249756170.12.crow16_f48207f4bf29 X-Spam-Summary: 2,0,0,77c0f0eae46afb50,d41d8cd98f00b204,axboe@kernel.dk,::linux-fsdevel@vger.kernel.org:linux-block@vger.kernel.org:axboe@kernel.dk,RULES_HIT:2:41:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1605:1606:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3865:3867:3868:4119:4321:5007:6261:6653:7875:9036:9592:10004:10226:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14110:14394:21080:21444:21451:21627:21795:21990:30046:30051:30054,0,RBL:209.85.166.194:@kernel.dk:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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:2,LUA_SUMMARY:none X-HE-Tag: crow16_f48207f4bf29 X-Filterd-Recvd-Size: 8236 Received: from mail-il1-f194.google.com (mail-il1-f194.google.com [209.85.166.194]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Dec 2019 16:25:04 +0000 (UTC) Received: by mail-il1-f194.google.com with SMTP id r81so16682081ilk.0 for ; Tue, 10 Dec 2019 08:25:04 -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=c6xGL0+Pvg+YsVb4S081GX/xoxEhKO3Eq64Kq716fjY=; b=eQQkP4QniithxoS/TSUmlbKRATm/UWwPjKu5OwiUIOCJnp7KCYci+TRhGXB2cQgZHU vHFvXlmoWh1qn7u+pFpAtwDxLp41TidswikH0e6NbtPVWF29qmIQ3bdsEWqXZPZmIR9Z 6gY4C4Rasj5MSB0KWqLtkVkQSIkuBLs++jKv9q0NmceTz08mPxux8e8dfYP3hE7jkQdD q6U/WDMVmItC5Vvi0A3vdrBcdTdTCtY0d8UoKfyKioyzQdB3d68aBCRrzFpgwT5qs3k6 kgD/FAXk3Ij9DJsVFyjkMVDgc80SniX11+vaw8WiF+SqbnwSBW41klh453qhmAf+Q5r1 CQ4A== 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=c6xGL0+Pvg+YsVb4S081GX/xoxEhKO3Eq64Kq716fjY=; b=DnOm2TGovEfqyEUvci8aTnA27tKhlshZGvZFEBsT1JBu8YXrQonzyYQdRO/dYBmd2e KdMW7Ep4zosafX5faD95S4Bc6MK4vu5K/f0qN4CPlHOe9TyADpEOKnT7TCJkbdBh/zgK 1alCV8C/hvnOwrlOFnNSuNrt5nF4xPbknA6aS9ZJi+Ta11vTuCWFZ2+SeMgg2cOUUXzk Sqlb5BUPd5i7ElUrbu5SRx+M1OHyg+IEcRphqzQi8wz6VlpLp8DvK7iBCYlB3mxhg4OE rEIN33YA/0gUpBr0Rkm77isUk3uxehtZouYvxp9gadtL/o9hSGAyLUI+54PxKE+C4YGb /+qA== X-Gm-Message-State: APjAAAVi/A7qAEL6M/hzxv6vvRiRo+e6KM5QfhYAli9FBeWC67AiNt5F rPku1fgNWs+u6DH9MebqOHMR3whNfDDp3Q== X-Google-Smtp-Source: APXvYqwqBizrk9IOVrpYwJOag6Se2wpP/F4l2DgMAcpgdzdYcJmV/WSCppXecARpMQ2a9wTOWWefmA== X-Received: by 2002:a92:3d49:: with SMTP id k70mr33109866ila.246.1575995103774; Tue, 10 Dec 2019 08:25:03 -0800 (PST) Received: from x1.thefacebook.com ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id y11sm791174iol.23.2019.12.10.08.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:25:03 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/5] iomap: support RWF_UNCACHED for buffered writes Date: Tue, 10 Dec 2019 09:24:54 -0700 Message-Id: <20191210162454.8608-6-axboe@kernel.dk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210162454.8608-1-axboe@kernel.dk> References: <20191210162454.8608-1-axboe@kernel.dk> MIME-Version: 1.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: 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/buffered-io.c | 58 ++++++++++++++++++++++++++++++++++-------- include/linux/iomap.h | 1 + 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 9b5b770ca4c7..c8d36b280ff2 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; @@ -796,19 +806,25 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, unsigned copied, return ret; } +#define GPW_PAGE_BATCH 16 + static loff_t iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, unsigned flags, struct iomap *iomap, struct iomap *srcmap) { + struct address_space *mapping = inode->i_mapping; + struct page *drop_pages[GPW_PAGE_BATCH]; struct iov_iter *i = data; long status = 0; ssize_t written = 0; + unsigned drop_nr = 0; do { struct page *page; unsigned long offset; /* Offset into pagecache page */ unsigned long bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ + bool drop_page = false; /* drop page after IO */ offset = offset_in_page(pos); bytes = min_t(unsigned long, PAGE_SIZE - offset, @@ -832,10 +848,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)) { + drop_page = true; + flags &= ~IOMAP_UNCACHED; + goto retry; + } break; + } if (mapping_writably_mapped(inode->i_mapping)) flush_dcache_page(page); @@ -866,13 +889,24 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data, iov_iter_single_seg_count(i)); goto again; } + + if (drop_page && + ((pos >> PAGE_SHIFT) != ((pos + copied) >> PAGE_SHIFT))) { + drop_pages[drop_nr] = page; + if (++drop_nr == GPW_PAGE_BATCH) + write_drop_cached_pages(drop_pages, mapping, + &drop_nr); + } else + balance_dirty_pages_ratelimited(inode->i_mapping); + pos += copied; written += copied; length -= copied; - - balance_dirty_pages_ratelimited(inode->i_mapping); } while (iov_iter_count(i) && length); + if (drop_nr) + write_drop_cached_pages(drop_pages, mapping, &drop_nr); + return written ? written : status; } @@ -882,10 +916,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..833dd43507ac 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -121,6 +121,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 { /*