From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE73E606A32F for ; Sat, 5 Dec 2026 07:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bctXu5Rc Received: by kanga.kvack.org (Postfix) id 02B236B05B1; Sat, 5 Dec 2026 02:39:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F16EC6B05B2; Sat, 5 Dec 2026 02:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E046A6B05B3; Sat, 5 Dec 2026 02:39:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B942F6B05B1 for ; Sat, 5 Dec 2026 02:39:56 -0500 (EST) Received: from smtpin14.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4EF64A0315 for ; Sat, 5 Dec 2026 07:39:56 +0000 (UTC) X-FDA: 85509130392.14.350864C Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf08.hostedemail.com (Postfix) with ESMTP id B46CD16000F for ; Sat, 5 Dec 2026 07:39:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=bctXu5Rc; spf=pass (imf08.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796456394; b=mnh2Usn01hrn0xYHW8fKEg+zXMXka/3obWoBGMdqJBiwuBEZaPn0WNuWMlabA5Lleaa1I3 1i0jipNclrZgssXvNUrqE3P+R9JotK6RcvvY/f4HQSfGTU4waVlj644D86zwBuRkPDsA9k InQiVkfab2y5mNnsegO2tuwO5Sa+w7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796456394; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hOM8WbLECDRYt6ygtVKtrp7tOj2wZFqkR5jbDPp6QJw=; b=yoWA0KT3x5Z33rj/nZUIqCwEt8EtEq/v6ccgEBWLmfOM4xH3OVW22kdGSNwYHAQCT8PGGE KqASpic8Dh3WXSfTn2rDHUSJY+KNfRbYd1D/3k5zUHIN3PIAxQXGInMOBU1nK3cQLdAztS 1X+pa5TOh+1YstPSV3CpCPwrKSl2kZU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=bctXu5Rc; spf=pass (imf08.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 3B83661380; Sat, 5 Dec 2026 07:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB0841F0092B; Sat, 5 Dec 2026 07:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796456394; bh=hOM8WbLECDRYt6ygtVKtrp7tOj2wZFqkR5jbDPp6QJw=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=bctXu5RcZ7sgusEb4nA6ycjS7AsJU204+aDDxWi9HskeVsFHHfvbZuXKWV60Oyqdc ViX0jnzZZDxo5fiMKGxakLGW+DQTPjeYG3xK8r1cK2c9IlFh31kHpwXUu8yxpFQxmb HQL4SBj9e2SVGYPQGue+dxJ4cBVadoTqujh1usuuHvto6ICpjudgm9NTn54QZXC8mK TvJuq28ssWtdAmsjyR4y7khRmevbtAlbPJQo4ZJbp9UlgFCdiRHcU9iLEK/cyPUzzp fklWUcYPGgT/MOHd98BgiCv92pMVbQIvS+vtR+MOLZBEsTRlT23dwcL1i0nePE9Ef3 tT+z2oqp/m/pw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 5/7] iomap: keep a DONTCACHE edge folio until a write completes it Reply-To: sashiko-reviews@lists.linux.dev To: "Mike Snitzer" , "Matthew Wilcox" , "Jan Kara" , linux-mm@kvack.org, "Christian Brauner" In-Reply-To: <077b73a253ca413d615b8d53be147efee84f78c8.1796367526.git.snitzer@kernel.org> References: <077b73a253ca413d615b8d53be147efee84f78c8.1796367526.git.snitzer@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 07:39:53 +0000 X-Stat-Signature: huxrh5z1pq9n5tzqie7g14rtoq3cgs7c X-Rspam-User: X-Rspamd-Queue-Id: B46CD16000F X-Rspamd-Server: rspam09 X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796456394-671088 X-HE-Meta: U2FsdGVkX18+/tDB0GJu37Ic0Uu5cO7bvFrj5lKpjftqp8pFEc/YePrKsDGHDirBj+X4ON93RIUrYrK9lmsgJfi7X/2DccvCEEK5Shmx0DULhmxQ9lgT0QX77W0mLb7i/ysg9U5nX4N+mC5U5UZC5CX85ko1vn4KmOS+rUOYkluPxz5GKJQxJLjm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Z6QXGYye/vT0QpH6POAHjwREPNnjC0AsJJMcy+I4ge4A2FFfVIsh/Oj0kACeGU+XrnIYr1eIQ1D1vTJQAlJPTqwaA4zpy/1e5fcMdf4ImkzvF/UoPP9PbZfLKbvhYKwgYKITbZMAjMxR8tkpb79Y7HHqu1Yoeb88dRNqpnurpabPhE4fu1wU1/Pw6ApDBuZP255XmyspY7v4NcdK1y5bIMA9iaPIrelOsAJPugAT3lyOBvEBQFnfj3rFxATFND3Yf6stTM0N5tf6aUMGS65BVrh7HDTBEqkC2ngusWAuINRcPvnHzrEt3T0mfjy0ycFe36EL/xfsq6QXUcr3s2C8yT6GujjbELZnGRDYHALJQuldaiPeI/Rc1O7lfVy2m+qx+4+z92LgGg7JmY4Lg0uzgAhKwfMnicO173AKSo6ub7dJ1L4O/QupLsfVRgKKdP3Cn1HKec7YEjlcsgBIIF+CGOc0maFir0w12JcQzQydhv1g9Hwo7UmsMa+tI6lpdmdhg+PnHOLFM1s5HGO38Tbnhj0LkcMmqTbrq3fcVyA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [Medium] iomap: partial RWF_DONTCACHE writes evict pre-existing cached folios - [Medium] iomap: unaligned RWF_DONTCACHE writes clear dropbehind on large folios - [Medium] iomap: iomap_write_begin() marks edge folio dropbehind when len < edge - [Medium] iomap: iomap_get_folio() sets FGP_DONTCACHE on partial-folio writes - [Medium] iomap: buffer_head type confusion in iomap_dontcache_edge_written() - [Medium] iomap: iomap_get_folio() disables RWF_DONTCACHE for random sub-folio writes - [Medium] iomap: uncompleted DONTCACHE edge writes trigger spurious flusher wakeups - [Medium] iomap: WB_DONTCACHE_DIRTY race with unlocked buffer_head and PTE dirtying - [Medium] iomap: iomap_get_folio() causes dropbehind xa_lock ping-pong on edge writes -- commit e3882c700ba2d4aad3d4984efed64e1a1dcf1087 Author: Mike Snitzer iomap: keep a DONTCACHE edge folio until a write completes it This commit changes iomap buffered writes with IOMAP_DONTCACHE so that partial writes to a minimum-size edge folio look up the folio without FGP_DONTCACHE and only mark it dropbehind via folio_mark_dropbehind() once the rest of the folio below EOF is already uptodate. > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > index 25915c0f5e1cc..65e48e99f234c 100644 > --- a/fs/iomap/buffered-io.c > +++ b/fs/iomap/buffered-io.c > @@ -787,6 +787,63 @@ bool iomap_is_partially_uptodate(struct folio *folio= , size_t from, size_t count) > } > EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); > =20 > +/* > + * Have the other writes written the parts of this edge folio that this = write > + * does not cover? The unit the writes share is the smallest folio the = mapping > + * allows. Call before the write, while i_size does not include it yet. > + */ > +static bool iomap_dontcache_edge_written(struct folio *folio, loff_t pos, > + size_t len) > +{ > + struct inode *inode =3D folio->mapping->host; > + size_t size =3D folio_size(folio); > + loff_t fpos =3D folio_pos(folio); > + loff_t isize =3D i_size_read(inode); > + size_t from, to, bs; > + > + if (folio_nr_pages(folio) !=3D mapping_min_folio_nrpages(folio->mapping= )) > + return false; > + /* > + * Past EOF the folio holds zeroes, not the data of the other writes. = An > + * appending write makes it uptodate with those zeroes, so the next > + * append would find it uptodate. > + */ > + if ((pos > fpos && pos > isize) || > + (pos + len < fpos + size && fpos + size > isize)) > + return false; > + if (folio_test_uptodate(folio)) > + return true; [Severity: Medium] Can this evict pre-existing cached folios that were populated by normal buffered I/O? Because iomap_get_folio() looks up edge folios without FGP_DONTCACHE, an uptodate min-order folio below EOF from an earlier cached read or write cannot be distinguished from one created by an earlier RWF_DONTCACHE edge write. iomap_dontcache_edge_written() returns true, so iomap_write_iter() marks it dropbehind and writeback evicts it, inverting the FGP_DONTCACHE contract where an aligned write leaves a hot cached folio resident while a partial-folio write evicts it. [ ... ] > +/* > + * For a DONTCACHE write: the bytes it covers of the unit at @pos if it > + * covers that unit only partially, else 0. > + */ > +static size_t iomap_dontcache_edge(const struct iomap_iter *iter, loff_t= pos) > +{ > + size_t unit =3D mapping_min_folio_nrbytes(iter->inode->i_mapping); > + size_t offset =3D pos & (unit - 1); > + > + if (!offset && iter->len >=3D unit) > + return 0; > + return min_t(u64, iter->len, unit - offset); > +} [Severity: Medium] Should iomap_dontcache_edge() check the current iteration's len rather than iter->len? Even when pos is unit-aligned and iter->len >=3D unit, len can be smaller t= han unit when a sub-folio extent ends mid-folio (iomap_length(iter) < unit) or on a short-copy retry. Returning 0 causes iomap_get_folio() to set FGP_DONTCACHE and allocate a new folio already marked dropbehind, even though this iteration only writes len bytes and unlocks the folio before the rest of the unit is written. [ ... ] > @@ -802,8 +859,20 @@ struct folio *iomap_get_folio(struct iomap_iter *ite= r, loff_t pos, size_t len) > =20 > if (iter->flags & IOMAP_NOWAIT) > fgp |=3D FGP_NOWAIT; > - if (iter->flags & IOMAP_DONTCACHE) > - fgp |=3D FGP_DONTCACHE; > + if (iter->flags & IOMAP_DONTCACHE) { > + size_t edge =3D iomap_dontcache_edge(iter, pos); > + > + /* > + * Other writes may cover the rest of this unit. Look it up > + * without FGP_DONTCACHE, as one unit, so that a new folio is > + * not marked. If this write completes it, iomap_write_iter() > + * marks it once the write has written its part. > + */ > + if (edge) > + len =3D min(len, edge); > + else > + fgp |=3D FGP_DONTCACHE; > + } [Severity: Medium] Doesn't omitting FGP_DONTCACHE here strip PG_dropbehind from existing large dropbehind folios? When an unaligned or sub-unit RWF_DONTCACHE write lands in an existing large folio marked PG_dropbehind (such as one from RWF_DONTCACHE readahead), __filemap_get_folio_mpol() treats the lookup as a cached access and calls filemap_clear_dropbehind(). iomap_dontcache_edge_written() then returns false for every folio larger than mapping_min_folio_nrpages(), so the mark is never restored and the large folio stays pinned in cache until reclaim, contradicting the commit message's statement that larger folios are left alone. [Severity: Medium] Does this disable RWF_DONTCACHE eviction altogether for random sub-folio writes? When every write is smaller than mapping_min_folio_nrbytes()=E2=80=94such a= s 4 KiB random writes on 16 KiB/64 KiB page kernels or large-block-size XFS/ext4=E2= =80=94 iomap_get_folio() omits FGP_DONTCACHE on every cold allocation, and iomap_dontcache_edge_written() always returns false on the newly allocated non-uptodate folio. None of those folios get PG_dropbehind or WB_DONTCACHE_DIRTY accounting, so 100% of touched folios remain cached until memory reclaim. [Severity: Medium] Can uncompleted edge writes trigger repeated spurious flusher wakeups? Because an uncompleted edge folio stays unmarked, WB_DONTCACHE_DIRTY remains 0 while dirtying the folio still sets WB_has_dirty_io. generic_write_sync() still calls filemap_dontcache_kick_writeback(), which checks wb_has_dirty_io(wb) and wakes bdi_wq; wb_check_start_dontcache() then clears WB_start_dontcache, runs an O(NR_CPUS) wb_stat_sum(wb, WB_DONTCACHE_DIRTY), finds 0 pages, and re-arms the delayed timer under wb->work_lock=E2=80=94re= peating on every subsequent uncompleted sub-folio write. [ ... ] > @@ -1099,6 +1170,15 @@ static int iomap_write_begin(struct iomap_iter *it= er, > =20 > pos =3D iomap_trim_folio_range(iter, folio, poffset, &len); > =20 > + /* > + * Decide now, before __iomap_write_begin() reads or zeroes the rest of > + * the folio, whether this write completes a folio it shares with other > + * writes. > + */ > + if (pdontcache_edge) > + *pdontcache_edge =3D iomap_dontcache_edge(iter, pos) && > + iomap_dontcache_edge_written(folio, pos, len); > + > if (srcmap->type =3D=3D IOMAP_INLINE) > status =3D iomap_write_begin_inline(iter, folio); > else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) [Severity: Medium] Should this check len =3D=3D edge instead of treating iomap_dontcache_edge(= ) as a boolean? When a mid-folio extent boundary (iomap_length(iter) < edge) or a short-copy retry shrinks len below edge on an uptodate folio below EOF, iomap_dontcache_edge_written() returns true and iomap_write_iter() marks the folio dropbehind and unlocks it before the rest of this write's edge runs, allowing writeback to drop it prematurely or leaving it marked dropbehind if the remaining part fails. [Severity: Medium] Is it safe to call iomap_dontcache_edge_written() when IOMAP_F_BUFFER_HEAD is set? Block device buffered writes advertise FOP_DONTCACHE in def_blk_fops and set IOMAP_F_BUFFER_HEAD in blkdev_iomap_begin(), so folio->private holds a struct buffer_head * rather than a struct iomap_folio_state *. On a non-uptodate block-device folio, iomap_dontcache_edge_written() calls iomap_is_partially_uptodate(), which casts folio->private to struct iomap_folio_state * and reads unrelated buffer_head fields as an uptodate bitmap, causing wrong dropbehind decisions and KCSAN data races. Skipping iomap_dontcache_edge_written() (or checking buffer heads) when IOMAP_F_BUFFER_HEAD is set would avoid the type confusion. [ ... ] > @@ -1247,6 +1329,13 @@ static int iomap_write_iter(struct iomap_iter *ite= r, struct iov_iter *i, > copied =3D copy_folio_from_iter_atomic(folio, offset, bytes, i); > written =3D iomap_write_end(iter, bytes, copied, folio) ? > copied : 0; > + /* > + * Mark a folio this write completes only now, with the folio > + * still locked: a stale mapping or a short copy can make the > + * write give the folio up without writing its part. > + */ > + if (dontcache_edge && written =3D=3D bytes) > + folio_mark_dropbehind(folio); [Severity: Medium] Won't clearing dropbehind in iomap_get_folio() and re-marking it here cause xa_lock ping-pong on edge overwrites? When a sub-folio RWF_DONTCACHE overwrite hits an existing min-order dropbehind folio below EOF, __filemap_get_folio_mpol() calls filemap_clear_dropbehind() (taking xa_lock_irqsave(&mapping->i_pages) and decrementing WB_DONTCACHE_DIRTY) and folio_mark_dropbehind() immediately takes xa_lock_irqsave() again to re-set it and re-increment WB_DONTCACHE_DIRTY. On block devices where blkdev_buffered_write() holds only inode_lock_shared(), concurrent sub-folio writers now contend on mapping->i_pages twice per write where already-dirty overwrites previously took no per-mapping spinlocks. [Severity: Medium] Can folio_mark_dropbehind() and filemap_clear_dropbehind() drift WB_DONTCACHE_DIRTY when racing with unlocked buffer-head dirtying? Both helpers assume that under folio_lock() and xa_lock, seeing PG_dirty and PAGECACHE_TAG_DIRTY set proves folio_account_dirtied() has already run. On a block device with IOMAP_F_BUFFER_HEAD, an unlocked mark_buffer_dirty() can set PG_dirty between folio_clear_dirty_for_io() and __folio_start_writeback() (which then preserves PAGECACHE_TAG_DIRTY), leaving both set before folio_account_dirtied() runs: CPU0 (writeback) CPU1 (buffer dirty) CPU2 (DONTCACHE write) blkdev_writepages() folio_lock(folio) folio_clear_dirty_for_io() mark_buffer_dirty() folio_test_set_dirty() (preempted) __folio_start_writeback() (keeps DIRTY tag) folio_unlock(folio) iomap_write_iter() folio_lock(folio) folio_mark_dropbehind() wb_stat_mod(+nr) folio_unlock(folio) __folio_mark_dirty() folio_account_dirtied() wb_stat_mod(+nr) <-- double count If PG_dropbehind was already set and the edge write clears it via filemap_clear_dropbehind() without re-marking, the same window underflows WB_DONTCACHE_DIRTY by -nr, causing wb_check_start_dontcache() to pass a negative count and skip writeback. A similar underflow occurs in filemap_clear_dropbehind() on a mapped buffer-head folio when try_to_free_buffers() calls folio_cancel_dirty() (leaving PAGECACHE_TAG_DIRTY set) and zap_present_folio_ptes() races in block_dirty_folio() before __folio_mark_dirty(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796367526.gi= t.snitzer@kernel.org?part=3D5