From patchwork Thu Nov 14 15:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875222 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 E9BF3D68B30 for ; Thu, 14 Nov 2024 15:28:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCF8C6B00A4; Thu, 14 Nov 2024 10:28:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7FC76B00A5; Thu, 14 Nov 2024 10:28:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BACB06B00A6; Thu, 14 Nov 2024 10:28:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9B44A6B00A4 for ; Thu, 14 Nov 2024 10:28:23 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6298FA1293 for ; Thu, 14 Nov 2024 15:28:23 +0000 (UTC) X-FDA: 82785079818.07.E26280E Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) by imf26.hostedemail.com (Postfix) with ESMTP id DFE13140019 for ; Thu, 14 Nov 2024 15:27:47 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Ms8EYliF; spf=pass (imf26.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.48 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731598045; 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=rF419cnvCI1sSo/lAda6/Cm28hf6CisfTzw5UCKZsOU=; b=NvsMdHnCL0EuvaN05xvrlmhuAaL42d8tQzxBMClHIwRS3mXVrVtiXOjU+TDHrrJmqPtpUO hj84jOf93NoPCt+UMuH6Lc8AAE3UUSwtTkG72gduUMRqqOGV2nfspkWf9uBLwyia8m8vqU XUUkgUel836c6Jc/CFU4Dcz2w9TrbWA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731598045; a=rsa-sha256; cv=none; b=iwUB7gOJFqY4nTxOLbcXhGQalLsnfqTKoonL3McFnVYJqeGkHysAooMXzYNwpK7K5ooOMi fFM5RyPRI4wnmWeTjktJ8bLY8B3kAK9KLbJxhqQE+LcPO45HnH6kHZcGtfvSBhpbiWz7jq sQgwdAmSVGrnudBadkwmOTwBqABqvlY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Ms8EYliF; spf=pass (imf26.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.48 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-288d70788d6so301301fac.1 for ; Thu, 14 Nov 2024 07:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598100; x=1732202900; 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=rF419cnvCI1sSo/lAda6/Cm28hf6CisfTzw5UCKZsOU=; b=Ms8EYliFLER4ec5aigixeWXUMue87neawzLxNHsNd/VG/gQF4HexL2/zRqaslaaoSK GCglUoXfJaZY4evb68FU7aEE+edInd8cqQ07ZWxm1Ibm5N1jHftj9c6gSlmm0/IcmOeB JTasPca0qlSTkOGYN9x4IBHf3uibj3RpuoD363+9au42j0IO8cTtfx2M/MKXNUK+63nc BHwk/b4coLzbioM8AUzF/YvoHkoRc4vMITDRmu2D5fqt7pk/RzlTOFYED2809PI9HkZA cGYw+CBIB6f4lzCQeosIHpwuuX9JDKT1xr1eHvtyyQGazX4J1sWjF1tEOu+pxZQERMlI /yig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598100; x=1732202900; 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=rF419cnvCI1sSo/lAda6/Cm28hf6CisfTzw5UCKZsOU=; b=pPWkVr9lc2v5ibi6vcYg7Zpj3CDQ1WhAQ1DSG0WJVp+h43eFt2/kLmXeHn78lQo+wI 5SzTKtzs0ljdkGVPleNJYCN4W2/F/SToKdkDNLxm4ejZ05xjXtnoOP4kQm0pY/qaXAy0 ADY+v0CDP2qJS7CsU1G6puvlUS9T9++L0SjNTXn6LL7F/aSvrqD+nt1ONJwjgtD4FDhC FLOmEaRZzQ6I3w3hQT1H8vzkkn9kHXfzKKERkP2Uqu+WekVELK5BB0OQ5+iLkCqXON1Y Gl/CyA6lXYUIcGh5HalZ3Bal10EudMjOZLgeBQddEW/Zx1IaPWUEmm+cBuTZfPEcTeWh W1Ag== X-Gm-Message-State: AOJu0YxRtm+orMBoh81D4c7PZ3q5hfX21c0PNnX/sKH+ChSZupCUsaD0 19PV7Hy2SFqyF3kFUeF33dno8eWv83lFzEIDQuRXLbNd16ZISHkmb/234MjUTnt4ykBF9nmEAY4 x7UE= X-Google-Smtp-Source: AGHT+IFrxjJdmj36oQy6UzPIhY6HkDZabl7PIZsT4CTZLD+yls1jl9nPP1SVyU+w5pEmbGgfnynQrw== X-Received: by 2002:a05:6870:e0c6:b0:261:b48:3c99 with SMTP id 586e51a60fabf-29560143149mr21908350fac.23.1731598099964; Thu, 14 Nov 2024 07:28:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:19 -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 13/17] ext4: add RWF_UNCACHED write support Date: Thu, 14 Nov 2024 08:25:17 -0700 Message-ID: <20241114152743.2381672-15-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: hctwnhh84nxehia39tgseuw5kg966ysf X-Rspam-User: X-Rspamd-Queue-Id: DFE13140019 X-Rspamd-Server: rspam02 X-HE-Tag: 1731598067-15004 X-HE-Meta: U2FsdGVkX18eR9dcA2m2PdmNL9QIqLDU7wbCHlYQxDAC2bKcEManr2agslV6Dv6tbb1Rk3Aiz9KUFVCOJKCId+jTD4mbGKz7TMNJ/1VpEVDeQSBioH5wfV38/6gxRCrznYs88KQwRCIJ/mvbE3gTmxhntqhZY6tmkPWfB9rGFbvAwRC1V6aXjZerBiAIEWjmY8HeKJXS2u57iBroG27pkVM4eCMc9LoBWQNVIRGAT5ooDWuVOm7oLtus+bj9hnC57G5vOtfGWNo6KtSmhheMJlofbR3nUMGdmFoGnu+qzGxVWNyXvUiSv+uwbdM8tNIKnceVc/UOo2FWLITWQaMdw1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-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: IOCB_UNCACHED IO needs to prune writeback regions on IO completion, and hence need the worker punt that ext4 also does for unwritten extents. Add an io_end flag to manage that. If foliop is set to foliop_uncached in ext4_write_begin(), then set FGP_UNCACHED so that __filemap_get_folio() will mark newly created folios as uncached. That in turn will make writeback completion drop these ranges from the page cache. Now that ext4 supports both uncached reads and writes, add the fop_flag FOP_UNCACHED to enable it. Signed-off-by: Jens Axboe --- fs/ext4/ext4.h | 1 + fs/ext4/file.c | 2 +- fs/ext4/inline.c | 7 ++++++- fs/ext4/inode.c | 18 ++++++++++++++++-- fs/ext4/page-io.c | 28 ++++++++++++++++------------ 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 44b0d418143c..60dc9ffae076 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -279,6 +279,7 @@ struct ext4_system_blocks { * Flags for ext4_io_end->flags */ #define EXT4_IO_END_UNWRITTEN 0x0001 +#define EXT4_IO_UNCACHED 0x0002 struct ext4_io_end_vec { struct list_head list; /* list of io_end_vec */ diff --git a/fs/ext4/file.c b/fs/ext4/file.c index f14aed14b9cf..0ef39d738598 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -944,7 +944,7 @@ const struct file_operations ext4_file_operations = { .splice_write = iter_file_splice_write, .fallocate = ext4_fallocate, .fop_flags = FOP_MMAP_SYNC | FOP_BUFFER_RASYNC | - FOP_DIO_PARALLEL_WRITE, + FOP_DIO_PARALLEL_WRITE | FOP_UNCACHED, }; const struct inode_operations ext4_file_inode_operations = { diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 3536ca7e4fcc..500bfb6d4860 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -667,6 +667,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, handle_t *handle; struct folio *folio; struct ext4_iloc iloc; + fgf_t fgp_flags; if (pos + len > ext4_get_max_inline_size(inode)) goto convert; @@ -702,7 +703,11 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, if (ret) goto out; - folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS, + fgp_flags = FGP_WRITEBEGIN | FGP_NOFS; + if (foliop_is_uncached(foliop)) + fgp_flags |= FGP_UNCACHED; + + folio = __filemap_get_folio(mapping, 0, fgp_flags, mapping_gfp_mask(mapping)); if (IS_ERR(folio)) { ret = PTR_ERR(folio); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 54bdd4884fe6..9b815137fb2c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1138,6 +1138,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, int ret, needed_blocks; handle_t *handle; int retries = 0; + fgf_t fgp_flags; struct folio *folio; pgoff_t index; unsigned from, to; @@ -1164,6 +1165,15 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, return 0; } + /* + * Set FGP_WRITEBEGIN, and FGP_UNCACHED if foliop is marked as + * uncached. That's how generic_perform_write() informs us that this + * is an uncached write. + */ + fgp_flags = FGP_WRITEBEGIN; + if (foliop_is_uncached(foliop)) + fgp_flags |= FGP_UNCACHED; + /* * __filemap_get_folio() can take a long time if the * system is thrashing due to memory pressure, or if the folio @@ -1172,7 +1182,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, * the folio (if needed) without using GFP_NOFS. */ retry_grab: - folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, + folio = __filemap_get_folio(mapping, index, fgp_flags, mapping_gfp_mask(mapping)); if (IS_ERR(folio)) return PTR_ERR(folio); @@ -2903,6 +2913,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, struct folio *folio; pgoff_t index; struct inode *inode = mapping->host; + fgf_t fgp_flags; if (unlikely(ext4_forced_shutdown(inode->i_sb))) return -EIO; @@ -2926,8 +2937,11 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, return 0; } + fgp_flags = FGP_WRITEBEGIN; + if (foliop_is_uncached(foliop)) + fgp_flags |= FGP_UNCACHED; retry: - folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, + folio = __filemap_get_folio(mapping, index, fgp_flags, mapping_gfp_mask(mapping)); if (IS_ERR(folio)) return PTR_ERR(folio); diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index ad5543866d21..10447c3c4ff1 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -226,8 +226,6 @@ static void ext4_add_complete_io(ext4_io_end_t *io_end) unsigned long flags; /* Only reserved conversions from writeback should enter here */ - WARN_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN)); - WARN_ON(!io_end->handle && sbi->s_journal); spin_lock_irqsave(&ei->i_completed_io_lock, flags); wq = sbi->rsv_conversion_wq; if (list_empty(&ei->i_rsv_conversion_list)) @@ -252,7 +250,7 @@ static int ext4_do_flush_completed_IO(struct inode *inode, while (!list_empty(&unwritten)) { io_end = list_entry(unwritten.next, ext4_io_end_t, list); - BUG_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN)); + BUG_ON(!(io_end->flag & (EXT4_IO_END_UNWRITTEN|EXT4_IO_UNCACHED))); list_del_init(&io_end->list); err = ext4_end_io_end(io_end); @@ -287,14 +285,15 @@ ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags) void ext4_put_io_end_defer(ext4_io_end_t *io_end) { - if (refcount_dec_and_test(&io_end->count)) { - if (!(io_end->flag & EXT4_IO_END_UNWRITTEN) || - list_empty(&io_end->list_vec)) { - ext4_release_io_end(io_end); - return; - } - ext4_add_complete_io(io_end); + if (!refcount_dec_and_test(&io_end->count)) + return; + if ((!(io_end->flag & EXT4_IO_END_UNWRITTEN) || + list_empty(&io_end->list_vec)) && + !(io_end->flag & EXT4_IO_UNCACHED)) { + ext4_release_io_end(io_end); + return; } + ext4_add_complete_io(io_end); } int ext4_put_io_end(ext4_io_end_t *io_end) @@ -348,7 +347,7 @@ static void ext4_end_bio(struct bio *bio) blk_status_to_errno(bio->bi_status)); } - if (io_end->flag & EXT4_IO_END_UNWRITTEN) { + if (io_end->flag & (EXT4_IO_END_UNWRITTEN|EXT4_IO_UNCACHED)) { /* * Link bio into list hanging from io_end. We have to do it * atomically as bio completions can be racing against each @@ -417,8 +416,13 @@ static void io_submit_add_bh(struct ext4_io_submit *io, submit_and_retry: ext4_io_submit(io); } - if (io->io_bio == NULL) + if (io->io_bio == NULL) { io_submit_init_bio(io, bh); + if (folio_test_uncached(folio)) { + ext4_io_end_t *io_end = io->io_bio->bi_private; + io_end->flag |= EXT4_IO_UNCACHED; + } + } if (!bio_add_folio(io->io_bio, io_folio, bh->b_size, bh_offset(bh))) goto submit_and_retry; wbc_account_cgroup_owner(io->io_wbc, &folio->page, bh->b_size);