From patchwork Mon Nov 11 23:37:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13871499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A330D3ABF4 for ; Mon, 11 Nov 2024 23:49:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F7EA6B0093; Mon, 11 Nov 2024 18:49:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9562B6B0096; Mon, 11 Nov 2024 18:49:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CF916B00E8; Mon, 11 Nov 2024 18:49:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 596376B0093 for ; Mon, 11 Nov 2024 18:49:17 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 201701201E8 for ; Mon, 11 Nov 2024 23:49:17 +0000 (UTC) X-FDA: 82775456358.06.E0A1E15 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf28.hostedemail.com (Postfix) with ESMTP id 8A947C0006 for ; Mon, 11 Nov 2024 23:48:33 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=mzNil4tJ; dmarc=none; spf=pass (imf28.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.177 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731368780; a=rsa-sha256; cv=none; b=XpCJpbmifGINpaop4T7d/cvDZqR8uakIpapIXEjasA2tnvSr89wM2mWwBvMezU2dbouGrJ +8OhTIuum4Tvl8DYUvtVI9kaU3ynhHLdY/QLcxSqRRWPk0Tq+g+4m2LyfUJHNj7nK7YRiS PinJ6l9C0jSYgfD/Rc9MOM3KHZB3odk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=mzNil4tJ; dmarc=none; spf=pass (imf28.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.177 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731368780; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F8VuOfX6p9OA5iVa4jUFPNHPqu8A2RaR+lAgXUtkcVc=; b=zO2rBKvIp5xkV0jZAsCVrTBDtl80v9JANNLWFylbsqiAhe7DAb8U7pzm+0p5E6Mx0wEt5c /e5m7sT/H6AgufdcOm4mMyNfaHSUTxI7e/dvmLCfZG1FYyy7NW4WBSzW7WYl7wgFV4Crdw e3CrK94WlbFZbZYsFaeYDWjzF0JeNag= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7240d93fffdso4130017b3a.2 for ; Mon, 11 Nov 2024 15:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731368954; x=1731973754; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F8VuOfX6p9OA5iVa4jUFPNHPqu8A2RaR+lAgXUtkcVc=; b=mzNil4tJSBhsYVhagvk16RKrIPRcZfqIc6TP4ORForefCWd8WcLzoQ1rbF/6gOfO+4 Ul/UIiRk493Az19xg96nXAkEGXFrD1rguDtwGCGr9W5uLM3jzZE4JBOevogKf1vN/pNh 0lBm+lwMu5JWToBmIseH0xNPgK+H0coLd393I3qrlpoNFoL8G8InI5x9oAjcz1WokYlY euRLm+2C1whCDiMnUV02kMJjcq/7IIP4LxvPauS1cUaij92c08CVWUcKPE8CY/0AWTFa UzTJKdVOmndopp57el6zjvicK4TixCRmUaaWJ/3VNIy3EHDvWEXHYYJj4vW1R9gqVS+1 bhdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731368954; x=1731973754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F8VuOfX6p9OA5iVa4jUFPNHPqu8A2RaR+lAgXUtkcVc=; b=g6TZW8dk0h1vb74RIm20jNJtQLDBlFYftNM8tWsE1SOWLDuaDcd1mPxIDLS5EShpBA JQiUXL/1k4+K74D7H1T/vno1gj0B9kPZDGwkxrxjDxUFhzlbMwphBwKca3iQ24COJ5xW 0EMMuDG7SawtOEdb0XJzO87rurj5PHHbkblwXYYAoh0qma300uWqiViQ2SCvLP4co/6b nV6gErpMaQOXINWl/OaR74FWfC0Fsw3jEX+jsUcj0oDItgvSoBcMHZxtu6s4DIMtJkX/ AeGc+ofphbAlgTJGW6zRwA3BMEHMAu65hFcm7YWshmBLK21ys+sQ4PQ31+d/QFMG74LB 4bog== X-Gm-Message-State: AOJu0YwaiImJ8/iViakbj9eH9hFIRDACh8dGWf0azwhlNBAHq+xbLn/V 46uarybnzrOv0ZLr1+gEUBax+b/ao9D6EssRcBI6ImFEb+PeF5A2oxsxc5IZ/Xa5iNdVFyNKqo9 mYu0= X-Google-Smtp-Source: AGHT+IF2+wW3TLckV7VSNmFRA6TqTX3hVCOrji7S4MicSJHEM7Y626gshLEQCdd+Y+7SrufulOQgng== X-Received: by 2002:a05:6a00:2354:b0:71e:60fc:ad11 with SMTP id d2e1a72fcca58-72413354230mr19707325b3a.16.1731368953536; Mon, 11 Nov 2024 15:49:13 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a7ee9sm10046057b3a.64.2024.11.11.15.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:49:12 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: hannes@cmpxchg.org, clm@meta.com, linux-kernel@vger.kernel.org, willy@infradead.org, kirill@shutemov.name, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, Jens Axboe Subject: [PATCH 16/16] btrfs: add support for uncached writes Date: Mon, 11 Nov 2024 16:37:43 -0700 Message-ID: <20241111234842.2024180-17-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241111234842.2024180-1-axboe@kernel.dk> References: <20241111234842.2024180-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: ajcubymspb18aqbie83mfte7ampyuaeq X-Rspamd-Queue-Id: 8A947C0006 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731368913-448601 X-HE-Meta: U2FsdGVkX18zw8MOwBwP+TY9u4HTGPqxEPQRG1uBolDlhuPnfyy2HCyzuPsC9vccB4gRgfgkZgOOrBuaxPCzslmZQ/ouzYbwMB2cGl6GdB/KvxGmnp1eKEDr2P7udQ6ZFbcSveC1A9iN/lYndD0OCY7QRKqlJCTIGJqaEMFnYvmsNALs9XrbuHsNA3b8FpR4Ecio6TmPOZn/S+EtWFR7P4/HPgX/FLc7AFDuiEc+7FqLViDR8XHaMyZMNV68euiQ6dYEZCJ2ajfOJ7re5KF/gwAooT4DZZxK2qyjf6zLwCIRuVsIxJ9fmTK/ZoMR0B/uhBgqmNKu3y/+dySutiyZnn+BXvUkvzXZ+86rxnZy3NyHG2VEJAJkUGeHqFG2Zur5/ub+vAOhrhg6q9AsdP+eI3iCLmC85RTVkitSZl+Y/hmJs81LwqXSwXq16rNdA0MLkNdPdHc/atl8EmJ3KTN+ksnidtTQG+th6L2hSGUkGKkErW/TPIaao6Iptn28q1aAnZmvMshu5g5Rh0iWrlSQzOb9Dc7NcRlHJ0w9LUI8VNQUGJVBbA9R8gTiiPrOtvYCiHIVjzvg/n7t6Nu0nnDzVvnh5vKlwPaEHi0yNIQe/EXROUZC5eHShregd5T7y1BBOhNOPZvCJXzAvtbb315tm2wLeK/VPZevNJCdTBSbQl8VP5249sL2TupghaAMD8HTC7+FN7mHeG2VC9k3MprpFqOQm5EeMx/t3LQ307WXpBC1LM4Evit7r+6q26T8dp/gsYnG61M0AnGmARRuubnF26dkTtfFDs7FNE2Rzj21HfWnQ0YeQIQaIPBxUfDLLE6RX7mdQm9nniRVOe8q38DQkWKYcDqy0+dsfqm50K2inQKRb6KPUGJ7nY33ou2f049aRtGUzbHK0mRLg/vS/vD2zPueVHZ/uaCy2JHM9oLXUN/oympAHhAJh+v7eFtH7IdFEL6gx09k7vBFn8MSWjw Iy5Snryj bMH1v7MMmyJelXJJMsMg3wTVyEFcOAwAcedWlxa/YLSLdO+BbJoolwtXX/HrV7SZWSvmPllZotK1t79FUV8SZMDySBePEOmwjvbCt6HBEs2Svz0WETxht/ebDgd7+TJAMaS+d+oZojy2Bd9H+6GkJBaRl0DjWFR5stYcaWeQUZ4tJ0/vNwi3W7TCGf302GY9C3UitrPyYycEILXOVUs9JNnQPtSg1GGl0nvJ8FoYTxgJc/4zIHLukc1OVSSG626mhfUJJ5GI1PPqmanw3WZMhRDHwO0WqJH+d904hD5nH6oGW6YpfLGzpAmbMZg== 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: List-Subscribe: List-Unsubscribe: The read side is already covered as btrfs uses the generic filemap helpers. For writes, just pass in FGP_UNCACHED if uncached IO is being done, then the folios created should be marked appropriately. For IO completion, ensure that writing back folios that are uncached gets punted to one of the btrfs workers, as task context is needed for that. Add an 'uncached_io' member to struct btrfs_bio to manage that. Outside of that, call generic_uncached_write() upon successful completion of a buffered write. With that, add FOP_UNCACHED to the btrfs file_operations fop_flags structure, enabling use of RWF_UNCACHED. Signed-off-by: Jens Axboe --- fs/btrfs/bio.c | 4 ++-- fs/btrfs/bio.h | 2 ++ fs/btrfs/extent_io.c | 8 +++++++- fs/btrfs/file.c | 10 +++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 7e0f9600b80c..253e1a656934 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -334,7 +334,7 @@ static void btrfs_end_bio_work(struct work_struct *work) struct btrfs_bio *bbio = container_of(work, struct btrfs_bio, end_io_work); /* Metadata reads are checked and repaired by the submitter. */ - if (is_data_bbio(bbio)) + if (bio_op(&bbio->bio) == REQ_OP_READ && is_data_bbio(bbio)) btrfs_check_read_bio(bbio, bbio->bio.bi_private); else btrfs_bio_end_io(bbio, bbio->bio.bi_status); @@ -351,7 +351,7 @@ static void btrfs_simple_end_io(struct bio *bio) if (bio->bi_status) btrfs_log_dev_io_error(bio, dev); - if (bio_op(bio) == REQ_OP_READ) { + if (bio_op(bio) == REQ_OP_READ || bbio->uncached_io) { INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work); } else { diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index e2fe16074ad6..39b98326c98f 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -82,6 +82,8 @@ struct btrfs_bio { /* Save the first error status of split bio. */ blk_status_t status; + bool uncached_io; + /* * This member must come last, bio_alloc_bioset will allocate enough * bytes for entire btrfs_bio but relies on bio being last. diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 872cca54cc6c..b97b21178ed7 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -760,8 +760,11 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl, ASSERT(bio_ctrl->end_io_func); if (bio_ctrl->bbio && - !btrfs_bio_is_contig(bio_ctrl, folio, disk_bytenr, pg_offset)) + !btrfs_bio_is_contig(bio_ctrl, folio, disk_bytenr, pg_offset)) { + if (folio_test_uncached(folio)) + bio_ctrl->bbio->uncached_io = true; submit_one_bio(bio_ctrl); + } do { u32 len = size; @@ -779,6 +782,9 @@ static void submit_extent_folio(struct btrfs_bio_ctrl *bio_ctrl, len = bio_ctrl->len_to_oe_boundary; } + if (folio_test_uncached(folio)) + bio_ctrl->bbio->uncached_io = true; + if (!bio_add_folio(&bio_ctrl->bbio->bio, folio, len, pg_offset)) { /* bio full: move on to a new one */ submit_one_bio(bio_ctrl); diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 4fb521d91b06..a27d194a28e0 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -919,7 +919,7 @@ static gfp_t get_prepare_gfp_flags(struct inode *inode, bool nowait) static noinline int prepare_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, bool force_uptodate, - bool nowait) + bool nowait, bool uncached) { int i; unsigned long index = pos >> PAGE_SHIFT; @@ -928,6 +928,8 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages, int ret = 0; int faili; + if (uncached) + fgp_flags |= FGP_UNCACHED; for (i = 0; i < num_pages; i++) { again: pages[i] = pagecache_get_page(inode->i_mapping, index + i, @@ -1323,7 +1325,8 @@ ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) * contents of pages from loop to loop */ ret = prepare_pages(inode, pages, num_pages, - pos, write_bytes, force_page_uptodate, false); + pos, write_bytes, force_page_uptodate, + false, iocb->ki_flags & IOCB_UNCACHED); if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); @@ -1512,6 +1515,7 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from, btrfs_set_inode_last_sub_trans(inode); if (num_sync > 0) { + generic_uncached_write(iocb, num_sync); num_sync = generic_write_sync(iocb, num_sync); if (num_sync < 0) num_written = num_sync; @@ -3802,7 +3806,7 @@ const struct file_operations btrfs_file_operations = { .compat_ioctl = btrfs_compat_ioctl, #endif .remap_file_range = btrfs_remap_file_range, - .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC, + .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC | FOP_UNCACHED, }; int btrfs_fdatawrite_range(struct btrfs_inode *inode, loff_t start, loff_t end)