From patchwork Thu Nov 14 15:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875263 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 988B9D68B30 for ; Thu, 14 Nov 2024 15:29:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78FF36B00AA; Thu, 14 Nov 2024 10:28:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 740F16B00AB; Thu, 14 Nov 2024 10:28:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56D026B00AC; Thu, 14 Nov 2024 10:28:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2F1CA6B00AA for ; Thu, 14 Nov 2024 10:28:30 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E350C120B06 for ; Thu, 14 Nov 2024 15:28:29 +0000 (UTC) X-FDA: 82785081456.16.B2A7470 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) by imf20.hostedemail.com (Postfix) with ESMTP id E5B2A1C0011 for ; Thu, 14 Nov 2024 15:27:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=d3YygrcX; dmarc=none; spf=pass (imf20.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.49 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731597929; a=rsa-sha256; cv=none; b=8aR9HMHHALnAFNjLD8wddYXR4PBYCBuczy3qpT26m16UJ7d1Y5Dg5uWehb2AijhX+wtIyv MmHzc6JvoUxW1ePyVXNpPa7Z7H6GF0vByjT4j6Jm11SIrr5nOlKWXnm5OZb2Kejn7trvq1 eQEPHI0tprv9VcMvO870zx+PIZ9V6sk= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=d3YygrcX; dmarc=none; spf=pass (imf20.hostedemail.com: domain of axboe@kernel.dk designates 209.85.161.49 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=1731597929; 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=jsUz6pEpY+ox9az2F5q2xnny+koVz5fK77xTMpol5Tk=; b=l1jwco9T1x8mtkakDiGe8440pxCldWHVX2zL8Ynq4AjSxi+qHRu9xS1YkRPABntW/Xrb0w r2KgLTIvf3qbsMG3cFRJKDDQPfIgwGWT3QRLpLh6UaifBJFOCOCe3QJxWE8cFzAEiTTMhP bvCe4hrLF3VKQI3w8VTc8f0VmJxxQuU= Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5ee763f9779so379380eaf.1 for ; Thu, 14 Nov 2024 07:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598107; x=1732202907; 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=jsUz6pEpY+ox9az2F5q2xnny+koVz5fK77xTMpol5Tk=; b=d3YygrcXMUO0IJs4Sd5yHlivpGI0l8R1y4UwIO12XA4m3Rb3G0opRJOCAerrQFvEsp ZSkbLgLTFJQzG28S9MP9EIPcVsqIQE7XU9AqWtzQ9YKxYRdwE0vXUo0zmkP8OE7pbK+L QTUMqhMFhZcPwf4h5rJ3hW8d50i6P3wPgB4+mjLM1gDH16YbY51LFTQwdH7yfl46qtB5 3lBBOF82c4yTuIpWRi4odtXGLVQcAyjvmDlDgjUGiVjOlPqrxmu8DBLpaAWEZvqLQMU+ 5DJbqrKPhFiBqZnsgxrcPHa3m8lvJF5alksORyYFgWNwXnSg294iUYhGAsPj5ubhWAYC vvGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598107; x=1732202907; 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=jsUz6pEpY+ox9az2F5q2xnny+koVz5fK77xTMpol5Tk=; b=UjFqTDonSWXianeDK0T/V9/Pl2/jaXhzo7QMemOu1swKgCuymqUqwK3LjCssD00IP1 JdpT42wvpwjUmH2XXT0JoJk5rNiF+3mS0rM1VUb5xvf739So6DcBrmQszdji9ao37jFt uRUKni46iLydbcmtKR6lwetzcLzG06CAJlnLmqgVywZOqULtDA0rL+kGAWD9q5OF+Kg3 Ocixn4v9rQVcJ6WJtb997wFpsDKOtPTpH038cVIhn3Oa5q6pIlIz58IkCAuxaKnbcyFI J1xg0SmhrPq1kwNjCkGq4yLMIfZbnSt07i1E2hAYJSM3UfoO58EAL6bPgTLxzSec5DR+ 75Qg== X-Gm-Message-State: AOJu0YyaIkenR2iYPB3Zmn0LmF+Bqo1Z/FwjKk02/yG+HwQluX3WMCk4 C19qN+7f3qZgrgAJRZzyjWX3sDPDi3xMo57z+pcFYvmng96EoWN49jK74ZBHFWAYVLaytUkLkJq FJO8= X-Google-Smtp-Source: AGHT+IFc1nzkbPZXQe4aKtw+LtP2VNQBWJFtVjU1qLyGyhTsHecVf/ilzi9Wv0164LJAdz5N+SGBoQ== X-Received: by 2002:a05:6820:1b08:b0:5ee:a5b:d172 with SMTP id 006d021491bc7-5ee57c530cdmr17735794eaf.5.1731598106027; Thu, 14 Nov 2024 07:28:26 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eea026eb41sm368250eaf.39.2024.11.14.07.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:25 -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, bfoster@redhat.com, Jens Axboe Subject: [PATCH 17/17] btrfs: add support for uncached writes Date: Thu, 14 Nov 2024 08:25:21 -0700 Message-ID: <20241114152743.2381672-19-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241114152743.2381672-2-axboe@kernel.dk> References: <20241114152743.2381672-2-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: 36nqi4p7wm7ixsntig63xp3sdgs7fame X-Rspamd-Queue-Id: E5B2A1C0011 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731598052-542000 X-HE-Meta: U2FsdGVkX1+RB4tWXqCyC7HiNR+V0BevlrcACDCskmXlaxpYZfEbXUdSqseIT7t95/Wzet4+25nVx7mjhWU+BdB4j2WGdXbVthMkk/fXf363+jEYb2Ep45uylWPKs2WfDooEP8CKyha/TylkACdkc8rdtqZPBj0Ru18fv//x7NC6GDiEuhwmsLQSj/0l1N0NWlyl2Xp7NWoWox4OephTNbEgE6S7GG/uxheTtXXf+g/nRpoUIZSef5eEpxr1BjQ+0I4sa70cjBijUuAphIFVduPM00qpWs8ONV/vp3m3h+ORrL5eijfoF44Tkc5DLzwMzWr+Kjm3Y2Q90yjt+6vgox4hnduacQj8YcABYapdwisFOQkevJtmN7rf8lC2KOcsCzgu6TcKiOAGlbMXsWcMFuAC0CP6lk8X7QKDULxona/HyNCk0ii1CKMIlHyH9UWxD/zOeS9qFu7nQ65MwnTQz3U1pOW+VGSldPtAzz1rL7MKlmqomwYDc2Z4P5ox0UWK7e7vkrI6VT53hF45I6ttuagDc871y8GCfy2sdKryUDwmhxb5RjEmQNFo0oyzWqMz3qep029V7Ra/ORS1ir4T0RHLtGUxj6F7l+M/Kd4AYttFJeQGQBbzq2ZR/dz8kpjHieROkqFFHD6xJS1jTmJ2koKrkuPcm2i+eLraIfekTZae6n0IK0bwjqc7rYJWrMma7zsElXa+XoBUNy5Pyasnna3EOO5gwm7AZ/7hpIGJmm056mkMcm2ED4D/XEQVjznrM254bXVhHBArBDgOGeJK2uwkp8kNNrQW/kax7Vmu8HO1RzqiP9t2TIRZ2zntoj8wXUQaGIgWM803+jlv/zUgYcnz3NI7fZhVMnQrX+v1E6Lv94WN2zOGhZRveYjB2sNbQnuogS/ma4Hrz4no9ZvyP9duLYZOA44120PzeBHli5qh9eIurTKP7lWhG07uOrQLZwLOQTPiBiH1QjZeC5o +gzP5sOu V/YHWmoYZIqvqnegKyKOhkccgGy8KW55HFQTgV7QQyGX0RGmjvvW3GxR9v1ovs6q8c8t5kGrTzOtNspvO4ekCBAljqBOvMF8Pu/6TXzRA2lWQPPPOLO4T28o8s8gF4BwYNeacrwi5uIR+1BHiUhWvn/1RlKUV+hW+9S41OAds4ikNvJzQHzdgWVfcuMhWomIS6HvrVk2St6F+MUS2Qw2kPSVaJf+vtFkuls9xRFhqSlj/niPe2UpdleJ6j/GOlqxI9yj0cSqT3mjL2O7OrlyJKK9k6ECIsbmnSe0sogc7oK/Q17gwTfO4oSydIA== 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. 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 | 9 ++++++--- 4 files changed, 17 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..cfee783f4c4d 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); @@ -3802,7 +3805,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)