From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795899866; b=AlnpQJkXkmZP395fck4oPyABky41Jzkm2RGAN6hZLYGqya2TaOMFEno4yqc/QNOoTmW+ Nf+u0pVVmTqjNyl12m3KBBwPRRIzxhwbTYgqzXFAm7seh5CKvn85scV8AmbrXvoPcSzZd d1j0ITjP6sx1dL9y2vYhbTAFpS+cZj1SbYiNfgvcS7e3yzFfyKUBSujsrSZkoWQLz9Aj5 08jXxB5DiJnNLKV1DTNUqCynWvoJ0JGf/GgPFHfZ+OlRmBDcsJKTWxpRhox+4V+kdRELR 4dYkPZMBbZbDg4HBOc6CA+0I6PJbW4YjRVs2c7rcQ6RS29GAnaCuTNoitrrUiYmJZtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795899866; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=S9Ms0l79imZKcuTRfogFcIU7gyWOR7wMiiuL4Jqqf5I=; b=fB7VvuNSRlUsZXfzYHHb48JiSiF4QT46vL2KNR+TvOEZMDSr5jmhqjNwv3wd9mGYXriE HVt/5q6a/jzyPlbKd95I1sTIayUD1XR/IEi+naYDu+O2/jN/2IclOJ6remtqln7YYd22/ SYtWzt2V9hoIPoZZST2goVafBfdS7YmMUFvzVlJ0O/NH0sb3vh/FaEuWh1kZyoVjS7dZa ZM07rGoQqkg14qDdsKqXd+QgdLeqdg9DmovCGOcm96UhIDN61g79kmA6bNd0mh+HVP/Tr iQbprJFdQV87xXX6wLiFK7gDu/DTlB2vIO4MZhjCP23DescUvbLxPKymNSQJu+FxRQQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PA4f3+fy; arc=none smtp.remote-ip=209.85.221.48 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D7A5606A31C for ; Sat, 28 Nov 2026 21:04:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D7A5606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PA4f3+fy Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-48dfc0421d9so8339686f8f.1 for ; Sat, 28 Nov 2026 13:04:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795899864; x=1796504664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=S9Ms0l79imZKcuTRfogFcIU7gyWOR7wMiiuL4Jqqf5I=; b=PA4f3+fyBIlx0+Mw0zptEbXOJpuLZ/V42rfLIdXWkgiVZUrWnZvH3fkDEAR60+BSJ5 mWizRyaBGmS9vWjk1crSGBOgMe8sOVmkWUOz9ICQLTZZ5hcysqhMl1b3siTcpLxcbBXL zN9vVhvGsiEPEVr1rhZVvCB25zZA6DrdnPB/1nsvIzPnegFA8elXgTvAPJJTTA4eq1tk s0nLlvrh2XLAMBbEB1RkkgFZzu48sSj6VbqgFhNEEC5vJRwMMpbZZjZWQLnTwyBxCRqf BdmE3xkC4ZigSvtrbWaPMg52z5fI6zb39zh2kcXaomvj43Wozz9QyowpCkMFl9JwHyHs BEmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795899864; x=1796504664; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=S9Ms0l79imZKcuTRfogFcIU7gyWOR7wMiiuL4Jqqf5I=; b=SDk+IpQeTWGGwIYaIkTm4HFw7cWUXtJWU/4yK7r3rvBz0u0tEkYoPbocOvtwPfDIDX hzIjxp7MBtbZQFXjWO1e+Z2maZPrgqdfnc30DoI0MrlhZF22XAGkA5+S8Klyf3KQzB5N 4MaBil1aHuOznwSI2yVJ5coJGQI3ghkJZ57H5jXdWkvFi+bYwuyDsmNu7uLgggByNysz EvqcsinH3mcP8grUWeCKlj1KqQlpALLgS7wn6YrLxLqKhr1CW0zV/16JdQm9AaDVzivl Hrhhfllg6VtSMJgV1TR9iKOzpNisN6iFXtoTPwQsf6rWK4KVZfo5Xztk9UnJNxCNuPYl KpZw== X-Gm-Message-State: APuU4Z8cPOqhb3FNvP76KRVWqy+KTOLxcBM4R3iOpfBXg2LM7LDvv6l5 8LtZH8qDorFC04igcaU1MG6BRMYC8CxNY5cqJuMk5ZkYt5G8K2nezvrQK85jwbLPcA== X-Gm-Gg: AZFdTZdNIrnf0/I34zigsmJAXnikSGxILjK9P3n5MMVZ1a3mExmFFV1Us752OydQTAv E+qc6avWlQLqG6DDcLlfUuse9UHGtgFYLS60TSUxLLrN72dFhGw4c5ZPGjXx2AnFZnmGJUhQG6k fVuuJPtvccW8tIgCf6LNbyOSP2HRd2gXZsZ+P2Mcpy7Vyd1j/Rab4Ktb/7X//h6wget5E8w8X05 wvYJRehjebapUVb3/JYbWpcs6wLyJYu4wj0Oo2G+9w2J4Po/clvJ205Li+0t2ehHtDNLzJKwoK0 /Qck8cFQyV4Kvua2po5MEOtwvhDb7o+poY+uF0gpM06CDZWZ8Hjj1GZoXLSAEk2ExBrZhxzwcHy HyOV2+CFN76TD+R25bz9uRhSEAd82lWnYt8oiVh1fLRKG327DslE/O5VTQTjHVir5Eh1CBgNCNG fSbHPoFw6b1yzm4ldcMnB8poYFBvxz/sfMDZnFa5cn27KY7g8Jtfh/uqeCmNVaTheB4rZyqkAEV IyeMCN28LwZ0ZwaYc97x6P09rBP4stWU9EQmEfB8rdeLzkGa7Bzjeszi0r6QoGcckBFQ1LpWa2a 43MYukUrVPKubw== X-Received: by 2002:a05:6000:4541:b0:48e:6264:c373 with SMTP id ffacd0b85a97d-4abb400bd81mr35926765f8f.14.1795899864241; Sat, 28 Nov 2026 13:04:24 -0800 (PST) Received: from kali ([39.45.45.41]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b1ed8b6a05sm33375322f8f.43.2026.11.28.13.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 13:04:23 -0800 (PST) From: Muhammad Umer To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.com, mason@kernel.org, fdmanana@suse.com, wqu@suse.com, Muhammad Umer Subject: [PATCH] btrfs: don't count skipped extent maps towards the fast fsync limit Date: Sat, 28 Nov 2026 16:04:07 -0500 Message-ID: <20261128210407.26387-1-mumer.mobi@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 4ef2c403d24c ("btrfs: increment extent count once when logging extents during fast fsync") dropped the second increment of num and halved the limit to 16K. That keeps the limit for extent maps that get logged, but the remaining increment happens before the generation check, so extent maps from past transactions, which are skipped, now count against a limit half the size. Those extent maps stay on modified_extents until the next fsync, so a file with more than 16K extent maps written since its last fsync, in previous transactions, now gets -EFBIG and a full transaction commit on fsync. Before that commit the same happened only above 32K. Move the check after the skips, so only extent maps we are going to log count. Reproducer: write a file densely and fsync it, overwrite N 4K blocks at an 8K stride, sync, then overwrite one block and fsync. Transaction commits during the last fsync: N v6.18 v7.4-rc3 v7.4-rc3 + this patch 15000 0 0 0 18000 0 1 0 31000 0 1 0 34000 1 1 0 Fixes: 4ef2c403d24c ("btrfs: increment extent count once when logging extents during fast fsync") Signed-off-by: Muhammad Umer --- Also tested on 7.2.15 with 4ef2c403d24c backported: commits during the final fsync were 0/0/1/1/1/1 for N = 8000, 15000, 18000, 25000, 31000, 34000 without this patch, and 0 at every size with it. With this patch extent maps from past transactions don't count at all, so N = 34000 no longer commits either (v6.18 did). Happy to keep them counted against the old 32K limit instead if that is preferred. Reproducer: https://github.com/mumer2834/btrfs-fsync-efbig-repro fs/btrfs/tree-log.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 62d94d1a0..f69d25692 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5344,11 +5344,21 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, list_for_each_entry_safe(em, n, &tree->modified_extents, list) { list_del_init(&em->list); + + if (em->generation < trans->transid) + continue; + + /* We log prealloc extents beyond eof later. */ + if ((em->flags & EXTENT_FLAG_PREALLOC) && + em->start >= i_size_read(&inode->vfs_inode)) + continue; + /* * Just an arbitrary number, this can be really CPU intensive * once we start getting a lot of extents, and really once we * have a bunch of extents we just want to commit since it will - * be faster. + * be faster. Only count extents we are going to log, extent + * maps from past transactions are skipped above at no cost. */ if (++num > SZ_16K) { list_del_init(&tree->modified_extents); @@ -5356,14 +5366,6 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, goto process; } - if (em->generation < trans->transid) - continue; - - /* We log prealloc extents beyond eof later. */ - if ((em->flags & EXTENT_FLAG_PREALLOC) && - em->start >= i_size_read(&inode->vfs_inode)) - continue; - /* Need a ref to keep it from getting evicted from cache */ refcount_inc(&em->refs); em->flags |= EXTENT_FLAG_LOGGING; -- 2.53.0