From mboxrd@z Thu Jan 1 00:00:00 1970 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 D5531D41D41 for ; Tue, 12 Nov 2024 01:30:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B93A6B009E; Mon, 11 Nov 2024 20:30:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 669FC6B00A2; Mon, 11 Nov 2024 20:30:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E38E6B00BA; Mon, 11 Nov 2024 20:30:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2CA896B009E for ; Mon, 11 Nov 2024 20:30:34 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CAC0681AA4 for ; Tue, 12 Nov 2024 01:30:33 +0000 (UTC) X-FDA: 82775712348.04.B76A501 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 1622F180010 for ; Tue, 12 Nov 2024 01:29:50 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=P7+mnp2E; dmarc=none; spf=pass (imf16.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.181 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731374969; a=rsa-sha256; cv=none; b=jitZIf7lzm8hXGQO1ueYBMW95XNnNQbxCNYXi5XKMjEsB+8Lu53kLHq3Pjm7hizPNR/wIb JrtILOrZG+rRWvAR/pJG7biUGQLvnjoqjnj0H6Jwr5zt+IZnmUnXnDNNiezaA8TQjnGY2v 4MqQEdDBr56hnGsYw2WEUTFPGt13hsU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=P7+mnp2E; dmarc=none; spf=pass (imf16.hostedemail.com: domain of axboe@kernel.dk designates 209.85.167.181 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=1731374969; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+PDg0tSjlFeUxAIPTtiAToLxkA/17c0lKKw7nT3lUQk=; b=vJrd3EPtGg8+coS7LuIZXebbJh1hQnBkoiudjihZLRvLW5mSDEXx/SHAUoF1l7COc3K0lM ryFuUnABQRmBp6KDG5djaaa/DuM3sg8OeYCTEPMW8gvRk3ZaNotjJva3yo+jyewt6CA33e dHz9KKFubg6cJPiiFtvG/KUMja68LJY= Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3e602994635so3240000b6e.0 for ; Mon, 11 Nov 2024 17:30:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731375031; x=1731979831; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+PDg0tSjlFeUxAIPTtiAToLxkA/17c0lKKw7nT3lUQk=; b=P7+mnp2ETZGUNEf80csqR3EtkvfUpEpw9rmCE6DrO1Uf3l2OaVHsZHK5p7/mMk8Pc9 jAIx9Ip9CQO+R3SGoQobFi8kZtV/olhkMteup3HELtw2puO+HQjBKWibNXaRGj8lhjlp qim+GjbWiym/fdRdtnWQCg50lDzBRdwgs5dX6UTzMw+UF4SMyQqOGRb/tu8SyqcWElbV xjCN6AHCz1GzeEoPvd/d5ofCwqwUByxl6W0/3FgdLe4nyRdL7glWyCdr20F2jqEDewcK /wYLgb3RE+BfGreCkXTrmmDphCFecD5JMUL0JDjPIpTymt+/+6r56eDSD4jHsKyAiJyG uBmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731375031; x=1731979831; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+PDg0tSjlFeUxAIPTtiAToLxkA/17c0lKKw7nT3lUQk=; b=TSt9bTQD/ssFFjN3bdpbFbvfJKZ6Wao5MKP4zakVV0QwQ8MjG38yFXJnXmWLdHt7ZJ Exq6RWBIlQpCzw58LhbDtWqABjQ6ayOAVtP7JkuxAP1TODPHqMrilo9hM5dYOejW+m1g FkJxX2FqMIYR/vvrabe8nRxki3/b6kexqVm3F5AR7ydkBVRxl8IPytdVwK8MB2k4NVuf 6SBz4tyOr9FgT9z85HsaK1arXjMpX9XwNTWIzwUR7I2UaGI4lkUvSnecxqWud9d9+b7G dZtLDDMyya6ZIJS9bhvvXYwEyeK/dLMAWDhuMctQDwDNOOn4pUK9PbVwuznvUdNvLYTz Y5jQ== X-Gm-Message-State: AOJu0YywI1ywdVYawiUXKw6nTn9073F3jHpeqbLI10kv7rsHywCxH75X EQDaotArfRnHhdl6sPgZPe/RMobC/2HIfNBmNdLlCsdgXsB3n3VqXCe2FS1HJLY= X-Google-Smtp-Source: AGHT+IGqvUXkNxRMjm59FWmOZDWXVanWGq+s8EdfS0LHz4JsCQ8CypwipkdKBom80N4jBII4HAWS8A== X-Received: by 2002:a05:6871:5808:b0:288:b7f0:f8fc with SMTP id 586e51a60fabf-2956032e2f1mr10688895fac.41.1731375030823; Mon, 11 Nov 2024 17:30:30 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f41f643cddsm7841408a12.54.2024.11.11.17.30.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Nov 2024 17:30:30 -0800 (PST) Message-ID: Date: Mon, 11 Nov 2024 18:30:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 13/16] iomap: make buffered writes work with RWF_UNCACHED To: "Darrick J. Wong" Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, 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 References: <20241111234842.2024180-1-axboe@kernel.dk> <20241111234842.2024180-14-axboe@kernel.dk> <20241112010157.GE9421@frogsfrogsfrogs> Content-Language: en-US From: Jens Axboe In-Reply-To: <20241112010157.GE9421@frogsfrogsfrogs> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 1622F180010 X-Rspamd-Server: rspam01 X-Stat-Signature: 7rh9xmw57nfyqj6zkfcf9fqpoty3nkn5 X-HE-Tag: 1731374990-4266 X-HE-Meta: U2FsdGVkX18HzaKzHOB5ssqxysVDChVCQO/XRjU2jQPu1oKFJw7cs6khwhMo4phHUuvcG4HEH5Pt0It4eRzTAPEWoIzrcZeNDz3Zn2QANcYKunRxjIsZUOoiBFjEYlWNEht6BSaeiTnaia/iYUT9mV9EU9XLRiQqvNBreqWjL3wBOPDiN2rSKa3b6x5p8kct7zHgjdRTN6UMXQLHPt4YJC0On88hOFK0Ee2+a4NmqWNNgaRWngwsLpFDDjR9idQPn+kHlu7TEM2UWtP6QBlz34G+45fujAAh+lqKQxj2ezFtdLu6RUMU3wTmFiVD8xi1bOQpwxH6MAd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-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: On 11/11/24 6:01 PM, Darrick J. Wong wrote: > On Mon, Nov 11, 2024 at 04:37:40PM -0700, Jens Axboe wrote: >> Add iomap buffered write support for RWF_UNCACHED. If RWF_UNCACHED is >> set for a write, mark the folios being written with drop_writeback. 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 | 4 +++- >> 2 files changed, 16 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..2efc72df19a2 100644 >> --- a/include/linux/iomap.h >> +++ b/include/linux/iomap.h >> @@ -64,6 +64,7 @@ struct vm_fault; >> #define IOMAP_F_BUFFER_HEAD 0 >> #endif /* CONFIG_BUFFER_HEAD */ >> #define IOMAP_F_XATTR (1U << 5) >> +#define IOMAP_F_UNCACHED (1U << 6) > > This value ^^^ is set only by the core iomap code, right? Correct >> /* >> * Flags set by the core iomap code during operations: > > ...in which case it should be set down here. It probably ought to have > a description of what it does, too: Ah yes indeed, good point. I'll move it and add a description. > "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." Excellent, I'll go with that. > If the writeback fails, does that mean that the dirty data will /not/ be > retained in the page cache? IIRC we finally got to the point where the > major filesystems leave pagecache alone after writeback EIO. Good question - didn't change any of those bits. It currently relies on writeback completion to prune the ranges. So if an EIO completion triggers writeback completion, then it'll get pruned. But for that case, I suspect the range is still dirty, and hence the pruning would not succeed, for obvious reasons. So you'd need further things on top of that, I'm afraid. > The rest of the mechanics looks nifty to me; there's plenty of places > where this could be useful to me personally. :) For sure, I think there are tons of use cases for this as well. Thanks for taking a look! -- Jens Axboe