From patchwork Thu Nov 14 15:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13875223 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 26E7CD68B31 for ; Thu, 14 Nov 2024 15:28:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 915926B00A6; Thu, 14 Nov 2024 10:28:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6986B00A7; Thu, 14 Nov 2024 10:28:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CB926B00A8; Thu, 14 Nov 2024 10:28:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 44F3A6B00A6 for ; Thu, 14 Nov 2024 10:28:25 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 027901C68C3 for ; Thu, 14 Nov 2024 15:28:24 +0000 (UTC) X-FDA: 82785081372.11.4B65F4E Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by imf12.hostedemail.com (Postfix) with ESMTP id 4086C40006 for ; Thu, 14 Nov 2024 15:28:02 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=SRUGlO5G; dmarc=none; spf=pass (imf12.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.47 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731598039; a=rsa-sha256; cv=none; b=DvnfmlnDCpI6nd3phzjycIEd309kY5mmDc8ftRe/7xFukRtfHcVpY3YTcN0St4INMHCSfH nbPDUpE1mjy9/2KDPDW2JTGcofLDCLGHmzazhWeuAn3r+oCbZGjk54lYg7EJpN9FcFGdQU +syDelhsST73wJD1E3l7oqjKL+S7yQQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=SRUGlO5G; dmarc=none; spf=pass (imf12.hostedemail.com: domain of axboe@kernel.dk designates 209.85.160.47 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=1731598039; 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=JnydZ5ahnoTDPrjopxRhuD9AlpgfRxt1ZJ34FZKhxI0=; b=V0qg5HHqnHgcaNFfbb8MDoKfrEAjvqx7cQSzxbkObIL7Vr25gnjYIn2hp9j5P1MFYLJil1 OETPqSdmfbyxJXoe0MsGeb6oP7lq0V+sjzaHTXl+NWoZOHMxrEFIG9KiG7I3+xQEpl2QhQ qw8vkrMmIbKD61B5apCDPABFzKgpg6E= Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-2958ddf99a7so605806fac.2 for ; Thu, 14 Nov 2024 07:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731598101; x=1732202901; 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=JnydZ5ahnoTDPrjopxRhuD9AlpgfRxt1ZJ34FZKhxI0=; b=SRUGlO5GPyB076ZzCS8l6a1S0rOg95OD678qNAw7bAFkCPmrTLMeFhEUzPbdcGUMEL YKarmzNZq9OtqlPW+ojEhEnuI2RCAXs0N0HmAOx9xxK42C8nYKcdt7SOXHqrRGeHVlkq tSMDID4G1WcJUsfxI1785vx7z7aDHkyr5GKc+DGe3sMOpBYmPzviSQ39gOXudNKud8Dx DkSDR3nKA6QWP0zfiBQ3ZyM6etMxFaeVLcFTiRrEn/bb3+AtEUBJ2lAgBBpNmsH2Wws6 fgINiwZSZdYjSMyx2gtnm+7k7fBA7tmpNU2zHvXfkThEuJzlNEg/v7EMzKboEFYjvKfg IOtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731598101; x=1732202901; 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=JnydZ5ahnoTDPrjopxRhuD9AlpgfRxt1ZJ34FZKhxI0=; b=qJELg8rZ7Z+5CkmBfIp/TPf8ikeM+eOwpEp5Dpi/BL3QFLKn5BkMojcTI5VqqrASJD H2JA9vLf4T8WB4M47lgdLVoEAOPfoWrojrJfhoo9wAGkDvgYDBZDmZXGXnA013xsf4Bg OFVymnCIoawmR39E8OuyAJy7rQBXMmEQQpWNEkH0hACghsFnpK13sy8lWqFTbwSyopuc PL18KSKzzGQXXb76PSMY9Cl1wKQ9nasSVDWWavU7x6pJJKoVDXE2ho6tgoGYD0Pw8LfN nHy0uZc87OPIWZHa7WIK1V3b2tNNXsnlkD3jmI80jGtqIbzG9JoF+enYAiyw1/VklBQt eO2A== X-Gm-Message-State: AOJu0YyVYQFhMvRSqcIePY/OIseDoXB9eDu3Gz0ZMcjY8eEk1G2oVDTQ eTs1P1lf6YqlGyNAFRpXlJ3QXdsoIVsKbw3T1i92Z0u2LkdlsmX8hokfbe7FfUzM52gZRtuxate pbaA= X-Google-Smtp-Source: AGHT+IGNabSsCKonQoe8b+3leqigUS1MxYLou4wkGKabmMMQ9sy0zqR8b1138Alaw/M4bLorq8cnFg== X-Received: by 2002:a05:6870:e2d5:b0:288:2fb6:a385 with SMTP id 586e51a60fabf-295600dc985mr21855599fac.20.1731598101550; Thu, 14 Nov 2024 07:28:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 07:28:20 -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 14/17] iomap: make buffered writes work with RWF_UNCACHED Date: Thu, 14 Nov 2024 08:25:18 -0700 Message-ID: <20241114152743.2381672-16-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-Rspam-User: X-Rspamd-Queue-Id: 4086C40006 X-Rspamd-Server: rspam01 X-Stat-Signature: wx7zxudiuix9ansi9ewkfohuyywguhmh X-HE-Tag: 1731598082-585309 X-HE-Meta: U2FsdGVkX1+hb9UfdWymb8ocx6/Vcau+HAcVN4ai0v86XPGlhg02jAFfW3oWFe1LxELHF3LFuwjQSTZcAAYVhcmSHkJGm1Maa0AqkEnPeJtU6C4Y4CVWmZScCsr6KoD7GFhj1weF57kT/5bmlW4yfOhc1U56DEo97FfELCDljPkq9yycvBNbl8W9dqrQqpJE3+9B81lleARUgnWLmJdVrrsCBfgN2dihm5xTAKYpvfdWzKP1paZwROfBf6WB/K5OV5KbVVfwVssdT6uLKxspK/6suVWos0b72oGsewdhgvq8kmzTHTr+Ezeu3u37En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m@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add iomap buffered write support for RWF_UNCACHED. If RWF_UNCACHED is set for a write, mark the folios being written as uncached. Then writeback completion will drop the pages. The write_iter handler simply kicks off writeback for the pages, and writeback completion will take care of the rest. This still needs the user of the iomap buffered write helpers to call iocb_uncached_write() upon successful issue of the writes. Signed-off-by: Jens Axboe --- fs/iomap/buffered-io.c | 15 +++++++++++++-- include/linux/iomap.h | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ef0b68bccbb6..2f2a5db04a68 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -603,6 +603,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len) if (iter->flags & IOMAP_NOWAIT) fgp |= FGP_NOWAIT; + if (iter->flags & IOMAP_UNCACHED) + fgp |= FGP_UNCACHED; fgp |= fgf_set_order(len); return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, @@ -1023,8 +1025,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, const struct iomap_ops *ops, void *private) { + struct address_space *mapping = iocb->ki_filp->f_mapping; struct iomap_iter iter = { - .inode = iocb->ki_filp->f_mapping->host, + .inode = mapping->host, .pos = iocb->ki_pos, .len = iov_iter_count(i), .flags = IOMAP_WRITE, @@ -1034,9 +1037,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; + if (iocb->ki_flags & IOCB_UNCACHED) + iter.flags |= IOMAP_UNCACHED; - while ((ret = iomap_iter(&iter, ops)) > 0) + while ((ret = iomap_iter(&iter, ops)) > 0) { + if (iocb->ki_flags & IOCB_UNCACHED) + iter.iomap.flags |= IOMAP_F_UNCACHED; iter.processed = iomap_write_iter(&iter, i); + } if (unlikely(iter.pos == iocb->ki_pos)) return ret; @@ -1770,6 +1778,9 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, size_t poff = offset_in_folio(folio, pos); int error; + if (folio_test_uncached(folio)) + wpc->iomap.flags |= IOMAP_F_UNCACHED; + if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, pos)) { new_ioend: error = iomap_submit_ioend(wpc, 0); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index f61407e3b121..0a88043676f2 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -74,9 +74,14 @@ struct vm_fault; * IOMAP_F_STALE indicates that the iomap is not valid any longer and the file * range it covers needs to be remapped by the high level before the operation * can proceed. + * + * IOMAP_F_UNCACHED is set to indicate that writes to the page cache (and + * hence writeback) will result in folios being evicted as soon as the + * updated bytes are written back to the storage. */ #define IOMAP_F_SIZE_CHANGED (1U << 8) #define IOMAP_F_STALE (1U << 9) +#define IOMAP_F_UNCACHED (1U << 10) /* * Flags from 0x1000 up are for file system specific usage: @@ -173,8 +178,9 @@ struct iomap_folio_ops { #define IOMAP_NOWAIT (1 << 5) /* do not block */ #define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */ #define IOMAP_UNSHARE (1 << 7) /* unshare_file_range */ +#define IOMAP_UNCACHED (1 << 8) /* uncached IO */ #ifdef CONFIG_FS_DAX -#define IOMAP_DAX (1 << 8) /* DAX mapping */ +#define IOMAP_DAX (1 << 9) /* DAX mapping */ #else #define IOMAP_DAX 0 #endif /* CONFIG_FS_DAX */